@@ -34,10 +34,9 @@ pub fn create_runtime_bundle_inclusion_file(
3434 env:: set_var ( "SUBSPACE_WASM_TARGET_DIRECTORY" , & target_dir) ;
3535 }
3636
37- // Make correct profile accessible in child processes.
3837 env:: set_var (
39- "SUBSPACE_WASM_BUILD_PROFILE " ,
40- env:: var ( "SUBSPACE_WASM_BUILD_PROFILE " ) . unwrap_or_else ( |_| {
38+ "SUBSPACE_WASM_BUNDLE_PATH " ,
39+ env:: var ( "SUBSPACE_WASM_BUNDLE_PATH " ) . unwrap_or_else ( |_| {
4140 // The tricky situation, Cargo doesn't put custom profiles like `production` in
4241 // `PROFILE` environment variable, so we need to find the actual profile ourselves by
4342 // extracting the first component of `OUT_DIR` that comes after `CARGO_TARGET_DIR`.
@@ -47,40 +46,50 @@ pub fn create_runtime_bundle_inclusion_file(
4746 out_components. next ( ) ;
4847 }
4948
50- if let Component :: Normal ( profile) = out_components
51- . next ( )
52- . expect ( "OUT_DIR has CARGO_TARGET_DIR as prefix" )
53- {
54- profile
55- . to_str ( )
56- . expect ( "Profile is always a utf-8 string" )
57- . to_string ( )
58- } else {
59- unreachable ! ( "OUT_DIR has CARGO_TARGET_DIR as prefix" )
60- }
49+ let mut path = target_dir;
50+
51+ let profile = loop {
52+ if let Component :: Normal ( profile_or_target) = out_components
53+ . next ( )
54+ . expect ( "OUT_DIR has CARGO_TARGET_DIR as prefix" )
55+ {
56+ let profile_or_target = profile_or_target
57+ . to_str ( )
58+ . expect ( "Profile is always a utf-8 string" ) ;
59+
60+ // Custom target was specified with `--target`
61+ if profile_or_target == env:: var ( "TARGET" ) . expect ( "Always set by cargo" ) {
62+ path = path. join ( profile_or_target) ;
63+ } else {
64+ break profile_or_target;
65+ }
66+ } else {
67+ unreachable ! ( "OUT_DIR has CARGO_TARGET_DIR as prefix" )
68+ }
69+ } ;
70+
71+ path. join ( profile)
72+ . join ( "wbuild" )
73+ . join ( runtime_crate_name)
74+ . join ( format ! (
75+ "{}.compact.wasm" ,
76+ runtime_crate_name. replace( '-' , "_" )
77+ ) )
78+ . to_string_lossy ( )
79+ . to_string ( )
6180 } ) ,
6281 ) ;
6382
6483 // Create a file that will include execution runtime into consensus runtime
65- let profile = env:: var ( "SUBSPACE_WASM_BUILD_PROFILE" ) . expect ( "Set above; qed" ) ;
66- let execution_wasm_bundle_path = target_dir
67- . join ( profile)
68- . join ( "wbuild" )
69- . join ( runtime_crate_name)
70- . join ( format ! (
71- "{}.compact.wasm" ,
72- runtime_crate_name. replace( '-' , "_" )
73- ) ) ;
84+ let execution_wasm_bundle_path = env:: var ( "SUBSPACE_WASM_BUNDLE_PATH" ) . expect ( "Set above; qed" ) ;
7485
7586 let execution_wasm_bundle_rs_path =
7687 env:: var ( "OUT_DIR" ) . expect ( "Set by cargo; qed" ) + "/" + target_file_name;
7788 let execution_wasm_bundle_rs_contents = format ! (
7889 r#"
7990 pub const {bundle_const_name}: &[u8] = include_bytes!("{}");
8091 "# ,
81- execution_wasm_bundle_path
82- . to_string_lossy( )
83- . escape_default( )
92+ execution_wasm_bundle_path. escape_default( )
8493 ) ;
8594
8695 fs:: write (
0 commit comments