Skip to content

Commit

Permalink
Add test for zig and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Dec 27, 2021
1 parent a55de9e commit 1ebf6aa
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
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
),
),
};

Expand All @@ -144,16 +152,8 @@ fn prepare_zig_linker(context: &BuildContext) -> Result<PathBuf> {
.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)
}
Expand Down
21 changes: 17 additions & 4 deletions tests/common/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>, bindings: Option<String>) -> Result<()> {
pub fn test_integration(
package: impl AsRef<Path>,
bindings: Option<String>,
zig: bool,
) -> Result<()> {
maybe_mock_cargo();

let target = Target::from_target_triple(None)?;
Expand All @@ -21,17 +25,21 @@ pub fn test_integration(package: impl AsRef<Path>, bindings: Option<String>) ->
"--manifest-path",
&package_string,
"--cargo-extra-args='--quiet'",
"--compatibility",
"linux",
];

if let Some(ref bindings) = bindings {
cli.push("--bindings");
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()?;

Expand Down Expand Up @@ -59,6 +67,11 @@ pub fn test_integration(package: impl AsRef<Path>, bindings: Option<String>) ->
// 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 {
Expand Down
17 changes: 15 additions & 2 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ 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]
fn integration_pyo3_mixed() {
handle_result(integration::test_integration(
"test-crates/pyo3-mixed",
None,
false,
));
}

Expand All @@ -81,6 +86,7 @@ fn integration_pyo3_mixed_submodule() {
handle_result(integration::test_integration(
"test-crates/pyo3-mixed-submodule",
None,
false,
));
}

Expand All @@ -89,6 +95,7 @@ fn integration_pyo3_mixed_py_subdir() {
handle_result(integration::test_integration(
"test-crates/pyo3-mixed-py-subdir",
None,
true,
));
}

Expand All @@ -104,14 +111,19 @@ 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]
fn integration_cffi_mixed() {
handle_result(integration::test_integration(
"test-crates/cffi-mixed",
None,
false,
));
}

Expand All @@ -120,6 +132,7 @@ fn integration_hello_world() {
handle_result(integration::test_integration(
"test-crates/hello-world",
None,
false,
));
}

Expand Down

0 comments on commit 1ebf6aa

Please sign in to comment.