diff --git a/src/build_options.rs b/src/build_options.rs index 1f2bf2c94..bb9e854b8 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -292,7 +292,7 @@ impl BuildOptions { .or( // With zig we can compile to any glibc version that we want, so we pick the lowest // one supported by the rust compiler - if self.zig { + if self.zig && !target.is_musl_target() { Some(PlatformTag::manylinux2010()) } else { None diff --git a/src/compile.rs b/src/compile.rs index 1986afe21..501661796 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -112,18 +112,26 @@ fn compile_universal2( /// We create different files for different args because otherwise cargo might skip recompiling even /// if the linker target changed fn prepare_zig_linker(context: &BuildContext) -> Result { - let (zig_linker, target) = match context.platform_tag { + let (zig_linker, cc_args) = match context.platform_tag { + // Not sure branch even has any use case, but it doesn't hurt to support it None | Some(PlatformTag::Linux) => ( "./zigcc-gnu.sh".to_string(), "native-native-gnu".to_string(), ), - Some(PlatformTag::Musllinux { x, y }) => ( - format!("./zigcc-musl-{}-{}.sh", x, y), - format!("native-native-musl.{}.{}", x, y), - ), + Some(PlatformTag::Musllinux { x, y }) => { + println!("⚠️ Warning: zig with musl is unstable"); + ( + format!("./zigcc-musl-{}-{}.sh", x, y), + format!("-target native-native-musl.{}.{}", x, y), + ) + } Some(PlatformTag::Manylinux { x, y }) => ( format!("./zigcc-gnu-{}-{}.sh", x, y), - format!("native-native-gnu.{}.{}", x, y), + // https://github.com/ziglang/zig/issues/10050#issuecomment-956204098 + format!( + "${{@/-lgcc_s/-lunwind}} -target native-native-gnu.{}.{}", + x, y + ), ), }; @@ -144,16 +152,8 @@ fn prepare_zig_linker(context: &BuildContext) -> Result { .open(&zig_linker)?; #[cfg(not(target_family = "unix"))] let mut custom_linker_file = File::create(&zig_linker)?; - // https://github.com/ziglang/zig/issues/10050#issuecomment-956204098 - custom_linker_file.write_all( - format!( - r##"#!/bin/bash -python -m ziglang cc ${{@/-lgcc_s/-lunwind}} -target {} -"##, - target - ) - .as_bytes(), - )?; + writeln!(&mut custom_linker_file, "#!/bin/bash")?; + writeln!(&mut custom_linker_file, "python -m ziglang cc {}", cc_args)?; drop(custom_linker_file); Ok(zig_linker) } diff --git a/tests/common/integration.rs b/tests/common/integration.rs index 58f6a86f6..18a5aebe1 100644 --- a/tests/common/integration.rs +++ b/tests/common/integration.rs @@ -8,7 +8,11 @@ use structopt::StructOpt; /// For each installed python version, this builds a wheel, creates a virtualenv if it /// doesn't exist, installs the package and runs check_installed.py -pub fn test_integration(package: impl AsRef, bindings: Option) -> Result<()> { +pub fn test_integration( + package: impl AsRef, + bindings: Option, + zig: bool, +) -> Result<()> { maybe_mock_cargo(); let target = Target::from_target_triple(None)?; @@ -21,8 +25,6 @@ pub fn test_integration(package: impl AsRef, bindings: Option) -> "--manifest-path", &package_string, "--cargo-extra-args='--quiet'", - "--compatibility", - "linux", ]; if let Some(ref bindings) = bindings { @@ -30,8 +32,14 @@ pub fn test_integration(package: impl AsRef, bindings: Option) -> cli.push(bindings); } - let options: BuildOptions = BuildOptions::from_iter_safe(cli)?; + if zig { + cli.push("--zig") + } else { + cli.push("--compatibility"); + cli.push("linux"); + } + let options: BuildOptions = BuildOptions::from_iter_safe(cli)?; let build_context = options.into_build_context(false, cfg!(feature = "faster-tests"), false)?; let wheels = build_context.build_wheels()?; @@ -59,6 +67,11 @@ pub fn test_integration(package: impl AsRef, bindings: Option) -> // We can do this since we know that wheels are built and returned in the // order they are in the build context for ((filename, supported_version), python_interpreter) in wheels.iter().zip(interpreter) { + if zig && build_context.target.is_linux() && !build_context.target.is_musl_target() { + assert!(filename + .to_string_lossy() + .ends_with("manylinux_2_12_x86_64.manylinux2010_x86_64.whl")) + } let venv_name = if supported_version == "py3" { format!("{}-cffi", test_name) } else { diff --git a/tests/run.rs b/tests/run.rs index 9718500af..91f15578a 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -65,7 +65,11 @@ fn editable_pyo3_mixed_py_subdir() { #[test] fn integration_pyo3_pure() { - handle_result(integration::test_integration("test-crates/pyo3-pure", None)); + handle_result(integration::test_integration( + "test-crates/pyo3-pure", + None, + false, + )); } #[test] @@ -73,6 +77,7 @@ fn integration_pyo3_mixed() { handle_result(integration::test_integration( "test-crates/pyo3-mixed", None, + false, )); } @@ -81,6 +86,7 @@ fn integration_pyo3_mixed_submodule() { handle_result(integration::test_integration( "test-crates/pyo3-mixed-submodule", None, + false, )); } @@ -89,6 +95,7 @@ fn integration_pyo3_mixed_py_subdir() { handle_result(integration::test_integration( "test-crates/pyo3-mixed-py-subdir", None, + true, )); } @@ -104,7 +111,11 @@ fn integration_pyo3_pure_conda() { #[test] fn integration_cffi_pure() { - handle_result(integration::test_integration("test-crates/cffi-pure", None)); + handle_result(integration::test_integration( + "test-crates/cffi-pure", + None, + false, + )); } #[test] @@ -112,6 +123,7 @@ fn integration_cffi_mixed() { handle_result(integration::test_integration( "test-crates/cffi-mixed", None, + false, )); } @@ -120,6 +132,7 @@ fn integration_hello_world() { handle_result(integration::test_integration( "test-crates/hello-world", None, + false, )); }