Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: cargo fetch --locked

- name: Fetch Python crate dependencies
run: cargo fetch --locked --manifest-path bindings/python/Cargo.toml --target ${{ matrix.host.target }}
run: cargo fetch --locked --manifest-path bindings/python/Cargo.toml

- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
Expand Down
5 changes: 4 additions & 1 deletion xtask/src/tasks/bindings/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl BuildAllBindingsCommand {
let release = self.release;

let targets = ffi::resolve_targets(Vec::new())?;
ffi::build_targets(&workspace, &targets, release)?;
ffi::build_targets(&workspace, &targets, release, false)?;

let ffi_dir = workspace.join("bindings/ffi/target");
let nuget_result = build_nuget_package(&BuildNugetConfig {
Expand All @@ -53,7 +53,9 @@ impl BuildAllBindingsCommand {
release,
target: None,
target_dir: None,
out: None,
frozen: false,
strip: false,
}
.run()?;
BuildWasmCommand {
Expand Down Expand Up @@ -114,6 +116,7 @@ impl TestAllBindingsCommand {
release: self.release,
target: None,
python: self.python.clone(),
frozen: false,
}
.run()?;

Expand Down
2 changes: 1 addition & 1 deletion xtask/src/tasks/bindings/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn build_nuget_package(config: &BuildNugetConfig) -> Result<BuildNugetResult
dir.clone()
} else {
let targets = ffi::resolve_targets(config.targets.clone())?;
ffi::build_targets(&workspace_root, &targets, config.release)?;
ffi::build_targets(&workspace_root, &targets, config.release, false)?;

workspace_root.join("bindings/ffi/target")
};
Expand Down
15 changes: 11 additions & 4 deletions xtask/src/tasks/bindings/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub struct BuildFfiCommand {
/// Build in release mode instead of debug.
#[arg(long)]
release: bool,

/// Pass --frozen to all cargo invocations.
#[arg(long)]
frozen: bool,
}

impl BuildFfiCommand {
Expand All @@ -28,7 +32,7 @@ impl BuildFfiCommand {
let targets = resolve_targets(self.targets.clone())?;
let profile = profile_dir(self.release);

build_targets(&workspace_root, &targets, self.release)?;
build_targets(&workspace_root, &targets, self.release, self.frozen)?;

let base = workspace_root.join("bindings/ffi/target");
if targets.len() == 1 {
Expand Down Expand Up @@ -62,9 +66,9 @@ pub fn resolve_targets(mut targets: Vec<String>) -> Result<Vec<String>> {
}

/// Compiles the FFI crate for the supplied target triples.
pub fn build_targets(root: &Path, targets: &[String], release: bool) -> Result<()> {
pub fn build_targets(root: &Path, targets: &[String], release: bool, frozen: bool) -> Result<()> {
for target in targets {
cargo_build(root, target, release)?;
cargo_build(root, target, release, frozen)?;
}
Ok(())
}
Expand Down Expand Up @@ -101,7 +105,7 @@ pub fn detect_host_triple() -> Result<String> {
Err(anyhow!("failed to detect host target triple"))
}

fn cargo_build(root: &Path, target: &str, release: bool) -> Result<()> {
fn cargo_build(root: &Path, target: &str, release: bool, frozen: bool) -> Result<()> {
let dir = root.join("bindings/ffi");
let mut args = vec![
OsString::from("build"),
Expand All @@ -112,6 +116,9 @@ fn cargo_build(root: &Path, target: &str, release: bool) -> Result<()> {
if release {
args.push(OsString::from("--release"));
}
if frozen {
args.push(OsString::from("--frozen"));
}

let title = format!("cargo build (ffi:{target})");
run_cargo_step(&dir, &title, args)
Expand Down
43 changes: 38 additions & 5 deletions xtask/src/tasks/bindings/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ pub struct BuildPythonCommand {
pub target: Option<String>,

/// Override the directory that receives built wheel files.
#[arg(long, value_name = "PATH")]
#[arg(long, value_name = "PATH", conflicts_with = "out")]
pub target_dir: Option<PathBuf>,

/// Propagate --frozen to cargo invocations prior to packaging.
/// Place built wheel files directly into this directory.
#[arg(long, value_name = "PATH", conflicts_with = "target_dir")]
pub out: Option<PathBuf>,
Comment on lines 26 to +32
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target_dir help text says it controls where built wheel files are written, but in run() it is passed to maturin --target-dir (Cargo target directory), while wheel output is now controlled by --out. This is user-facing CLI/API confusion. Either update the docstring (and maybe the field name) to reflect Cargo target-dir semantics, or switch target_dir to use maturin --out and reserve --target-dir for the Cargo build directory.

Copilot uses AI. Check for mistakes.

/// Propagate --frozen to cargo and maturin invocations.
#[arg(long)]
pub frozen: bool,

/// Strip debug symbols from the built wheel.
#[arg(long)]
pub strip: bool,
}

impl BuildPythonCommand {
Expand Down Expand Up @@ -65,8 +73,19 @@ impl BuildPythonCommand {
maturin.arg("--target");
maturin.arg(target);
}
maturin.arg("--target-dir");
maturin.arg(&wheel_dir);
if self.frozen {
maturin.arg("--frozen");
}
if self.strip {
maturin.arg("--strip");
}
if let Some(out) = &self.out {
maturin.arg("--out");
maturin.arg(out);
} else {
maturin.arg("--target-dir");
maturin.arg(&wheel_dir);
}
Comment on lines +82 to +88
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When --out is provided, this branch correctly switches to maturin --out, but earlier in run() we still compute wheel_dir (defaulting to bindings/python/wheels) and create_dir_all it unconditionally. Consider only creating wheel_dir when self.out is None (or alternatively creating/validating the --out directory when it is set) to avoid unexpected side-effects in CI.

Copilot uses AI. Check for mistakes.
run_command(maturin, "maturin build (bindings/python)")
}
}
Expand All @@ -84,6 +103,10 @@ pub struct TestPythonCommand {
/// Python interpreter used to run the sample and tests.
#[arg(long, value_name = "EXE", default_value = "python3")]
pub python: String,

/// Pass --frozen to all cargo and maturin invocations.
#[arg(long)]
pub frozen: bool,
}

impl TestPythonCommand {
Expand All @@ -95,7 +118,13 @@ impl TestPythonCommand {

install_testing_dependencies(&venv_python)?;

install_local_package(&python_dir, self.release, self.target.as_deref(), &venv_dir)?;
install_local_package(
&python_dir,
self.release,
self.target.as_deref(),
self.frozen,
&venv_dir,
)?;

let mut sample = Command::new(&venv_python);
sample.current_dir(&python_dir);
Expand Down Expand Up @@ -133,6 +162,7 @@ fn install_local_package(
python_dir: &Path,
release: bool,
target: Option<&str>,
frozen: bool,
venv_dir: &Path,
) -> Result<()> {
let mut maturin = Command::new("maturin");
Expand All @@ -145,6 +175,9 @@ fn install_local_package(
maturin.arg("--target");
maturin.arg(target);
}
if frozen {
maturin.arg("--frozen");
}
maturin.env("VIRTUAL_ENV", venv_dir);
let bin_dir = venv_bin_dir(venv_dir);
let mut path_value = bin_dir.clone().into_os_string();
Expand Down
Loading