Skip to content

Commit

Permalink
add dev task runner (#10)
Browse files Browse the repository at this point in the history
* add dev task runner

* use task runner for tests

this is kinda a hard thing to test, not totally satisfied with its organization but whatever i think its fundamental
  • Loading branch information
0xcaff authored Jul 23, 2024
1 parent 752544e commit 13f1c8c
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 65 deletions.
1 change: 1 addition & 0 deletions .idea/duckdb_protobuf.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/runConfigurations/build_debug.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/runConfigurations/build_release.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# A Makefile for building stuff during development. This is not used for the CI
# builds. These two are separate concepts with different constraints (which
# target is specified, cross compilation, etc.). Using this as a task runner (a
# la just).

DUCKDB_PLATFORM := osx_arm64
DUCDKB_EXTENSION_VERSION := v0.0.1
DUCKDB_VERSION := v1.0.0

ifeq ($(DUCKDB_PLATFORM),windows_amd64)
LIBRARY_OUTPUT := duckdb_protobuf.dll
endif
ifeq ($(DUCKDB_PLATFORM),osx_arm64)
LIBRARY_OUTPUT := libduckdb_protobuf.dylib
endif
ifeq ($(DUCKDB_PLATFORM),linux_amd64)
LIBRARY_OUTPUT := libduckdb_protobuf.so
endif

debug:
cargo build --package duckdb_protobuf
cargo run \
--package duckdb_metadata_bin \
--bin duckdb_metadata \
-- \
--input target/debug/$(LIBRARY_OUTPUT) \
--output target/debug/protobuf.duckdb_extension \
--extension-version $(DUCKDB_EXTENSION_VERSION) \
--duckdb-version $(DUCKDB_VERSION) \
--platform $(DUCKDB_PLATFORM)

release:
cargo build --package duckdb_protobuf --release
cargo run \
--package duckdb_metadata_bin \
--bin duckdb_metadata \
-- \
--input target/debug/$(LIBRARY_OUTPUT) \
--output target/release/protobuf.duckdb_extension \
--extension-version $(DUCDKB_EXTENSION_VERSION) \
--duckdb-version $(DUCKDB_VERSION) \
--platform $(DUCKDB_PLATFORM)

test: release
cargo test

.PHONY: debug release
4 changes: 4 additions & 0 deletions packages/duckdb_protobuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ anyhow = "1.0"
prost = "0.13.1"
prost-build = "0.13.1"

[[test]]
name = "it"
path = "tests/it/main.rs"

77 changes: 12 additions & 65 deletions packages/duckdb_protobuf/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use anyhow::Result;
use duckdb::{Config, Connection};
use prost::Message;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::process::Command;
use std::sync::Once;

use anyhow::Result;
use duckdb::{Config, Connection};
use prost::Message;

static INIT: Once = Once::new();

fn setup() {
INIT.call_once(|| {
compile_protos().expect("Failed to compile protobufs");
generate_test_data().expect("Failed to generate test data");
compile_duckdb_extension().expect("Failed to compile DuckDB extension");
attach_metadata().expect("Failed to attach metadata");
});
}

Expand Down Expand Up @@ -73,56 +71,6 @@ fn generate_test_data() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

fn compile_duckdb_extension() -> Result<()> {
Command::new("cargo")
.args(["build", "--release"])
.status()?;

Ok(())
}

fn attach_metadata() -> Result<()> {
let target_dir = "../../target/release";
let library_output = if cfg!(target_os = "macos") {
"libduckdb_protobuf.dylib"
} else if cfg!(target_os = "linux") {
"libduckdb_protobuf.so"
} else {
unimplemented!("Unsupported platform");
};

Command::new("cargo")
.args([
"run",
"--package",
"duckdb_metadata_bin",
"--bin",
"duckdb_metadata",
"--",
"--input",
&format!("{}/{}", target_dir, library_output),
"--output",
&format!("{}/protobuf.duckdb_extension", target_dir),
"--extension-version",
"v0.0.1",
"--duckdb-version",
"v1.0.0",
"--platform",
if cfg!(target_os = "macos") {
"osx_arm64"
} else if cfg!(target_os = "linux") {
"linux_amd64"
} else {
unimplemented!("Unsupported platform")
},
])
.status()?;

println!("Metadata attached successfully.");

Ok(())
}

#[test]
fn test_setup_creates_files() {
setup();
Expand All @@ -149,15 +97,14 @@ fn test_query_protobuf_data() -> Result<()> {

let mut stmt = conn.prepare(
"
SELECT *
FROM protobuf(
descriptors = './tests/generated/descriptor.pb',
files = './tests/generated/data/**/*.bin',
message_type = 'user.User',
delimiter = 'SingleMessagePerFile'
)
LIMIT 10;
",
SELECT * FROM protobuf(
descriptors = './tests/generated/descriptor.pb',
files = './tests/generated/data/**/*.bin',
message_type = 'user.User',
delimiter = 'SingleMessagePerFile'
)
LIMIT 10;
",
)?;

let mut rows = stmt.query([])?;
Expand Down

0 comments on commit 13f1c8c

Please sign in to comment.