From d05559ba99f09dca97c7c7112ab45fdee62b2756 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Wed, 20 Nov 2024 16:41:23 -0500 Subject: [PATCH] Handle spaces in source/build paths --- aws-lc-fips-sys/builder/cmake_builder.rs | 4 ++-- aws-lc-sys/builder/cc_builder.rs | 2 +- aws-lc-sys/builder/cmake_builder.rs | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/aws-lc-fips-sys/builder/cmake_builder.rs b/aws-lc-fips-sys/builder/cmake_builder.rs index e168298c8f4..89662a97003 100644 --- a/aws-lc-fips-sys/builder/cmake_builder.rs +++ b/aws-lc-fips-sys/builder/cmake_builder.rs @@ -121,13 +121,13 @@ impl CmakeBuilder { if parent_dir.is_some() && (target_family() == "unix" || target_env() == "gnu") { let parent_dir = parent_dir.unwrap(); let cc_build = cc::Build::new(); - let flag = format!("-ffile-prefix-map={}=", parent_dir.display()); + let flag = format!("\"-ffile-prefix-map={}=\"", parent_dir.display()); if let Ok(true) = cc_build.is_flag_supported(&flag) { emit_warning(&format!("Using flag: {}", &flag)); cmake_cfg.asmflag(&flag); cmake_cfg.cflag(&flag); } else { - let flag = format!("-fdebug-prefix-map={}=", parent_dir.display()); + let flag = format!("\"-fdebug-prefix-map={}=\"", parent_dir.display()); if let Ok(true) = cc_build.is_flag_supported(&flag) { emit_warning(&format!("Using flag: {}", &flag)); cmake_cfg.asmflag(&flag); diff --git a/aws-lc-sys/builder/cc_builder.rs b/aws-lc-sys/builder/cc_builder.rs index dd016003e36..4364dfac0e1 100644 --- a/aws-lc-sys/builder/cc_builder.rs +++ b/aws-lc-sys/builder/cc_builder.rs @@ -188,7 +188,7 @@ impl CcBuilder { env::set_var("CFLAGS", cflags); } - if target_os() == "macos" && target_arch() == "x86_64" { + if target_os() == "macos" { // This compiler error has only been seen on MacOS x86_64: // ``` // clang: error: overriding '-mmacosx-version-min=13.7' option with '--target=x86_64-apple-macosx14.2' [-Werror,-Woverriding-t-option] diff --git a/aws-lc-sys/builder/cmake_builder.rs b/aws-lc-sys/builder/cmake_builder.rs index a5a789acdc2..16a7ed35bf7 100644 --- a/aws-lc-sys/builder/cmake_builder.rs +++ b/aws-lc-sys/builder/cmake_builder.rs @@ -103,7 +103,25 @@ impl CmakeBuilder { self.output_lib_type, ); let mut cflags = OsString::new(); - cflags.push(cc_builder.prepare_builder().get_compiler().cflags_env()); + let compiler = cc_builder.prepare_builder().get_compiler(); + let args = compiler.args(); + for (i, arg) in args.iter().enumerate() { + if i > 0 { + cflags.push(" "); + } + if let Some(arg) = arg.to_str() { + if arg.contains(' ') { + cflags.push("\""); + cflags.push(arg); + cflags.push("\""); + } else { + cflags.push(arg); + } + } else { + cflags.push(arg); + } + } + if !get_cflags().is_empty() { cflags.push(" "); cflags.push(get_cflags());