aws / aws-lc-rs

aws-lc-rs is a cryptographic library using AWS-LC for its cryptographic operations. The library strives to be API-compatible with the popular Rust library named ring.
Other
236 stars 40 forks source link

Linux -> Mac cannot cross compile aws-lc-sys #409

Closed brongan closed 2 months ago

brongan commented 2 months ago

Problem:

On an x86_64 Linux box

cargo new repro
cd repro
cargo add aws-lc-rs
cargo b --target x86_64-apple-darwin

Fails with unknown flag errors.

  --- stderr
  thread 'main' panicked at /home/brong/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.15.0/builder/cc_builder.rs:225:9:
  COMPILER: "cc"ARGS: ["-O0", "-ffunction-sections", "-fdata-sections", "-fPIC", "-gdwarf-2", "-fno-omit-frame-pointer", "-m64", "-arch", "x86_64", "-mmacosx-version-min=10.7", "-Wall", "-Wextra", "/home/brong/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.15.0/aws-lc/tests/compiler_features_tests/memcmp_invalid_stripped_check.c", "-Wno-unused-parameter", "-o", "/home/brong/ws/repro/target/x86_64-apple-darwin/debug/build/aws-lc-sys-963977ec30e96b4e/out/memcmp_invalid_stripped_check"]EXECUTED: trueERROR: cc: error: unrecognized command-line option ‘-arch’
  cc: error: unrecognized command-line option ‘-mmacosx-version-min=10.7’
  OUTPUT: Failed to compile memcmp_invalid_stripped_check

Relevant details

aws-lc-rs 17

Linux 6.8.6-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Sat, 13 Apr 2024 14:44:53 +0000 x86_64 unknown

nightly-x86_64-unknown-linux-gnu (default) rustc 1.78.0-nightly (a4472498d 2024-02-15)

thedjpetersen commented 2 months ago

+1

justsmth commented 2 months ago

I can reproduce this on my Linux host. I'm investigating now.

justsmth commented 2 months ago

The parameter appears to be added here: https://github.com/rust-lang/cc-rs/blob/994dc909dc54caa9eaa473b9807c171e1763d27e/src/lib.rs#L2659

...
        match arch {
            AppleArchSpec::Device(_) if is_mac => {
                cmd.args
                    .push(format!("-mmacosx-version-min={}", min_version).into());
            }
...

It seems related to this issue: https://github.com/rust-lang/cc-rs/issues/1030

justsmth commented 2 months ago

Another related issue: https://github.com/rust-lang/cc-rs/issues/710

I'm not certain cross-compiling C/C++ code to MacOS from Linux via cc-rs is expect to work like this. I tried this same method and reproduced the failure with ring and openssl; they both generate errors about these same flags:

  cargo:warning=cc: error: unrecognized debug output level ‘full’
  cargo:warning=cc: error: unrecognized command-line option ‘-arch’
  cargo:warning=cc: error: unrecognized command-line option ‘-mmacosx-version-min=10.7’
brongan commented 2 months ago

From https://rust-lang.github.io/rustup/cross-compilation.html

Note that rustup target add only installs the Rust standard library for a given target. There are typically other tools necessary to cross-compile, particularly a linker. For example, to cross compile to Android the Android NDK must be installed. In the future, rustup will provide assistance installing the NDK components as well. See the target section of the cargo configuration for how to setup a linker to use for a certain target.

justsmth commented 2 months ago

Since cross-compiling from Linux to Mac is not something we currently plan to support. I'm closing this issue. Feel free to open another issue as a feature request if you'd like us to further investigate this as a cross-compilation option.