diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 082791dc9..e34ce2296 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,9 +87,9 @@ jobs: run: | dora-cli up dora-cli list - dora-cli new test_project + dora-cli new test_project --internal-create-with-path-dependencies cd test_project - cargo build --all --config "patch.'https://github.com/dora-rs/dora.git'.dora-node-api.path=\"../apis/rust/node\"" --config "patch.'https://github.com/dora-rs/dora.git'.dora-operator-api.path=\"../apis/rust/operator\"" + cargo build --all UUID=$(dora-cli start dataflow.yml) sleep 10 dora-cli stop $UUID diff --git a/binaries/cli/src/main.rs b/binaries/cli/src/main.rs index b202ea070..0d3bcb437 100644 --- a/binaries/cli/src/main.rs +++ b/binaries/cli/src/main.rs @@ -39,6 +39,8 @@ enum Command { New { #[clap(flatten)] args: CommandNew, + #[clap(hide = true, long)] + internal_create_with_path_dependencies: bool, }, Up { #[clap(long)] @@ -120,7 +122,10 @@ fn main() -> eyre::Result<()> { Command::Build { dataflow } => { build::build(&dataflow)?; } - Command::New { args } => template::create(args)?, + Command::New { + args, + internal_create_with_path_dependencies, + } => template::create(args, internal_create_with_path_dependencies)?, Command::Up { config, coordinator_path, diff --git a/binaries/cli/src/template/mod.rs b/binaries/cli/src/template/mod.rs index 086616071..4e68cb548 100644 --- a/binaries/cli/src/template/mod.rs +++ b/binaries/cli/src/template/mod.rs @@ -3,9 +3,9 @@ mod cxx; mod python; mod rust; -pub fn create(args: crate::CommandNew) -> eyre::Result<()> { +pub fn create(args: crate::CommandNew, use_path_deps: bool) -> eyre::Result<()> { match args.lang { - crate::Lang::Rust => rust::create(args), + crate::Lang::Rust => rust::create(args, use_path_deps), crate::Lang::Python => python::create(args), crate::Lang::C => c::create(args), crate::Lang::Cxx => cxx::create(args), diff --git a/binaries/cli/src/template/rust/mod.rs b/binaries/cli/src/template/rust/mod.rs index ac1493193..4b5f5e624 100644 --- a/binaries/cli/src/template/rust/mod.rs +++ b/binaries/cli/src/template/rust/mod.rs @@ -5,7 +5,7 @@ use std::{ }; const VERSION: &str = env!("CARGO_PKG_VERSION"); -pub fn create(args: crate::CommandNew) -> eyre::Result<()> { +pub fn create(args: crate::CommandNew, use_path_deps: bool) -> eyre::Result<()> { let crate::CommandNew { kind, lang: _, @@ -14,13 +14,17 @@ pub fn create(args: crate::CommandNew) -> eyre::Result<()> { } = args; match kind { - crate::Kind::Operator => create_operator(name, path), - crate::Kind::CustomNode => create_custom_node(name, path), - crate::Kind::Dataflow => create_dataflow(name, path), + crate::Kind::Operator => create_operator(name, path, use_path_deps), + crate::Kind::CustomNode => create_custom_node(name, path, use_path_deps), + crate::Kind::Dataflow => create_dataflow(name, path, use_path_deps), } } -fn create_dataflow(name: String, path: Option) -> Result<(), eyre::ErrReport> { +fn create_dataflow( + name: String, + path: Option, + use_path_deps: bool, +) -> Result<(), eyre::ErrReport> { const DATAFLOW_YML: &str = include_str!("dataflow-template.yml"); const WORKSPACE_CARGO_TOML: &str = include_str!("Cargo-template.toml"); @@ -45,9 +49,9 @@ fn create_dataflow(name: String, path: Option) -> Result<(), eyre::ErrR fs::write(&cargo_toml_path, &cargo_toml) .with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?; - create_operator("op_1".into(), Some(root.join("op_1")))?; - create_operator("op_2".into(), Some(root.join("op_2")))?; - create_custom_node("node_1".into(), Some(root.join("node_1")))?; + create_operator("op_1".into(), Some(root.join("op_1")), use_path_deps)?; + create_operator("op_2".into(), Some(root.join("op_2")), use_path_deps)?; + create_custom_node("node_1".into(), Some(root.join("node_1")), use_path_deps)?; println!( "Created new Rust dataflow at `{name}` at {}", @@ -57,7 +61,11 @@ fn create_dataflow(name: String, path: Option) -> Result<(), eyre::ErrR Ok(()) } -fn create_operator(name: String, path: Option) -> Result<(), eyre::ErrReport> { +fn create_operator( + name: String, + path: Option, + use_path_deps: bool, +) -> Result<(), eyre::ErrReport> { const CARGO_TOML: &str = include_str!("operator/Cargo-template.toml"); const LIB_RS: &str = include_str!("operator/lib-template.rs"); @@ -82,9 +90,17 @@ fn create_operator(name: String, path: Option) -> Result<(), eyre::ErrR fs::create_dir(&src) .with_context(|| format!("failed to create directory `{}`", src.display()))?; + let dep = if use_path_deps { + r#"dora-operator-api = { path = "../../apis/rust/operator" }"#.to_string() + } else { + format!( + r#"dora-operator-api = {{ git = "https://github.com/dora-rs/dora.git", tag = "v{VERSION}" }}"# + ) + }; let cargo_toml = CARGO_TOML .replace("___name___", &name) - .replace("___version___", VERSION); + .replace("dora-operator-api = {}", &dep); + let cargo_toml_path = root.join("Cargo.toml"); fs::write(&cargo_toml_path, &cargo_toml) .with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?; @@ -101,7 +117,11 @@ fn create_operator(name: String, path: Option) -> Result<(), eyre::ErrR Ok(()) } -fn create_custom_node(name: String, path: Option) -> Result<(), eyre::ErrReport> { +fn create_custom_node( + name: String, + path: Option, + use_path_deps: bool, +) -> Result<(), eyre::ErrReport> { const CARGO_TOML: &str = include_str!("node/Cargo-template.toml"); const MAIN_RS: &str = include_str!("node/main-template.rs"); @@ -120,9 +140,16 @@ fn create_custom_node(name: String, path: Option) -> Result<(), eyre::E fs::create_dir(&src) .with_context(|| format!("failed to create directory `{}`", src.display()))?; + let dep = if use_path_deps { + r#"dora-node-api = { path = "../../apis/rust/node" }"#.to_string() + } else { + format!( + r#"dora-node-api = {{ git = "https://github.com/dora-rs/dora.git", tag = "v{VERSION}" }}"# + ) + }; let cargo_toml = CARGO_TOML .replace("___name___", &name) - .replace("___version___", VERSION); + .replace("dora-node-api = {}", &dep); let cargo_toml_path = root.join("Cargo.toml"); fs::write(&cargo_toml_path, &cargo_toml) .with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?; diff --git a/binaries/cli/src/template/rust/node/Cargo-template.toml b/binaries/cli/src/template/rust/node/Cargo-template.toml index 2d609a7eb..fa46f49a0 100644 --- a/binaries/cli/src/template/rust/node/Cargo-template.toml +++ b/binaries/cli/src/template/rust/node/Cargo-template.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dora-node-api = { git = "https://github.com/dora-rs/dora.git", tag = "v___version___" } +dora-node-api = {} diff --git a/binaries/cli/src/template/rust/operator/Cargo-template.toml b/binaries/cli/src/template/rust/operator/Cargo-template.toml index 0ee039cae..19ecbb9cd 100644 --- a/binaries/cli/src/template/rust/operator/Cargo-template.toml +++ b/binaries/cli/src/template/rust/operator/Cargo-template.toml @@ -9,4 +9,4 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -dora-operator-api = { git = "https://github.com/dora-rs/dora.git", tag = "v___version___" } +dora-operator-api = {}