33
44use std:: {
55 collections:: HashMap ,
6- fs, io,
6+ env , fs, io,
77 path:: { Path , PathBuf } ,
88 process:: Command ,
99 str:: FromStr ,
@@ -30,6 +30,10 @@ struct Args {
3030 /// Path to which the wasm file is output
3131 #[ arg( long, short) ]
3232 output : PathBuf ,
33+
34+ /// Compile the local crate instead of the published one
35+ #[ arg( long) ]
36+ local : bool ,
3337}
3438
3539fn main ( ) -> io:: Result < ( ) > {
@@ -47,8 +51,13 @@ fn main() -> io::Result<()> {
4751 eprintln ! ( "creating {}" , target_dir. display( ) ) ;
4852 fs:: create_dir_all ( & target_dir) ?;
4953
50- let crate_dir =
51- create_codec_wasm_component_crate ( & scratch_dir, & args. crate_ , & args. version , & args. codec ) ?;
54+ let crate_dir = create_codec_wasm_component_crate (
55+ & scratch_dir,
56+ & args. crate_ ,
57+ & args. version ,
58+ & args. codec ,
59+ args. local ,
60+ ) ?;
5261 copy_buildenv_to_crate ( & crate_dir) ?;
5362
5463 let nix_env = NixEnv :: new ( & crate_dir) ?;
@@ -72,6 +81,7 @@ fn create_codec_wasm_component_crate(
7281 crate_ : & str ,
7382 version : & Version ,
7483 codec : & str ,
84+ local : bool ,
7585) -> io:: Result < PathBuf > {
7686 let crate_dir = scratch_dir. join ( format ! ( "{crate_}-wasm-{version}" ) ) ;
7787 eprintln ! ( "crate_dir={}" , crate_dir. display( ) ) ;
@@ -81,6 +91,25 @@ fn create_codec_wasm_component_crate(
8191 }
8292 fs:: create_dir_all ( & crate_dir) ?;
8393
94+ let ( numcodecs_wasm_logging_path, numcodecs_wasm_guest_path, numcodecs_my_codec_path) = if local
95+ {
96+ let numcodecs = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( ".." ) . join ( ".." ) ;
97+ eprintln ! ( "looking for local workspace in {}" , numcodecs. display( ) ) ;
98+ let numcodecs = numcodecs. canonicalize ( ) ?;
99+ let numcodecs_wasm_logging = numcodecs. join ( "crates" ) . join ( "numcodecs-wasm-logging" ) ;
100+ let numcodecs_wasm_guest = numcodecs. join ( "crates" ) . join ( "numcodecs-wasm-guest" ) ;
101+ let numcodecs_my_codec = numcodecs
102+ . join ( "codecs" )
103+ . join ( crate_. strip_prefix ( "numcodecs-" ) . unwrap_or ( crate_) ) ;
104+ (
105+ format ! ( r#" path = "{}","# , numcodecs_wasm_logging. display( ) ) ,
106+ format ! ( r#" path = "{}","# , numcodecs_wasm_guest. display( ) ) ,
107+ format ! ( r#" path = "{}","# , numcodecs_my_codec. display( ) ) ,
108+ )
109+ } else {
110+ ( String :: new ( ) , String :: new ( ) , String :: new ( ) )
111+ } ;
112+
84113 fs:: write (
85114 crate_dir. join ( "Cargo.toml" ) ,
86115 format ! (
@@ -95,9 +124,9 @@ edition = "2024"
95124# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
96125
97126[dependencies]
98- numcodecs-wasm-logging = {{ version = "0.2", default-features = false }}
99- numcodecs-wasm-guest = {{ version = "0.3", default-features = false }}
100- numcodecs-my-codec = {{ package = "{crate_}", version = "{version}", default-features = false }}
127+ numcodecs-wasm-logging = {{ version = "0.2",{numcodecs_wasm_logging_path} default-features = false }}
128+ numcodecs-wasm-guest = {{ version = "0.3",{numcodecs_wasm_guest_path} default-features = false }}
129+ numcodecs-my-codec = {{ package = "{crate_}", version = "{version}",{numcodecs_my_codec_path} default-features = false }}
101130 "#
102131 ) ,
103132 ) ?;
0 commit comments