From 5a319457dd29bcbd210f51f7b93f23cebe83aa4c Mon Sep 17 00:00:00 2001 From: Ignacio Duart Date: Mon, 16 Oct 2023 09:51:57 +0200 Subject: [PATCH] Properly concantenate compiler features --- crates/fdev/src/build.rs | 43 ++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/crates/fdev/src/build.rs b/crates/fdev/src/build.rs index a02b90949..a8c491d43 100644 --- a/crates/fdev/src/build.rs +++ b/crates/fdev/src/build.rs @@ -28,38 +28,61 @@ pub fn build_package(cli_config: BuildToolCliConfig, cwd: &Path) -> Result<(), D } } -fn compile_options(cli_config: &BuildToolCliConfig) -> impl Iterator { +fn compile_options(cli_config: &BuildToolCliConfig) -> impl Iterator { let release: &[&str] = if cli_config.debug { &[] } else { &["--release"] }; - let feature_list = cli_config.features.iter().flat_map(|s| { - s.split(',') - .filter(|p| *p != cli_config.package_type.feature()) - }); - let features = ["--features", cli_config.package_type.feature()] + let feature_list = cli_config + .features + .iter() + .flat_map(|s| { + s.split(',') + .filter(|p| *p != cli_config.package_type.feature()) + }) + .chain([cli_config.package_type.feature()]); + let features = [ + "--features".to_string(), + feature_list.collect::>().join(","), + ]; + features .into_iter() - .chain(feature_list); - features.chain(release.iter().copied()) + .chain(release.iter().map(|s| s.to_string())) +} + +#[test] +fn test_get_compile_options() { + let config = BuildToolCliConfig { + features: Some("contract".into()), + version: semver::Version::new(0, 0, 1), + package_type: PackageType::Contract, + debug: false, + }; + let opts: Vec<_> = compile_options(&config).collect(); + assert_eq!( + opts, + vec!["--features", "contract,freenet-main-contract", "--release"] + ); } fn compile_rust_wasm_lib(cli_config: &BuildToolCliConfig, work_dir: &Path) -> Result<(), DynError> { const RUST_TARGET_ARGS: &[&str] = &["build", "--lib", "--target"]; use std::io::IsTerminal; + let comp_opts = compile_options(cli_config).collect::>(); let cmd_args = if std::io::stdout().is_terminal() && std::io::stderr().is_terminal() { RUST_TARGET_ARGS .iter() .copied() .chain([WASM_TARGET, "--color", "always"]) - .chain(compile_options(cli_config)) + .chain(comp_opts.iter().map(|s| s.as_str())) .collect::>() } else { RUST_TARGET_ARGS .iter() .copied() .chain([WASM_TARGET]) - .chain(compile_options(cli_config)) + .chain(comp_opts.iter().map(|s| s.as_str())) .collect::>() };