Skip to content
Merged
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
12 changes: 0 additions & 12 deletions src/fromager/vendor_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ def _detect_rust_build_backend(
return None


def has_rust_build_backend(req: Requirement, project_dir: pathlib.Path) -> bool:
"""Return ``True`` if the project uses a Rust build backend.

Checks whether the project's ``pyproject.toml`` declares ``maturin``
or ``setuptools-rust`` as its build backend.
"""
pyproject_toml = dependencies.get_pyproject_contents(project_dir)
if not pyproject_toml:
return False
return _detect_rust_build_backend(req, pyproject_toml) is not None


def vendor_generic_rust_package(
req: Requirement,
manifests: list[pathlib.Path],
Expand Down
7 changes: 0 additions & 7 deletions src/fromager/wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
requirements_file,
resolver,
sbom,
vendor_rust,
)
from .pkgmetadata.pep376 import verbatim_dist_name

Expand Down Expand Up @@ -335,12 +334,6 @@ def build_wheel(
build_env=build_env,
)

# Isolate Rust build artifacts per package to prevent CARGO_TARGET_DIR
# collisions during parallel builds and EXDEV (cross-device rename)
# failures.
if vendor_rust.has_rust_build_backend(req, sdist_root_dir):
extra_environ.setdefault("CARGO_TARGET_DIR", str(sdist_root_dir / "target"))

if pbi.build_ext_parallel:
logger.warning(
"%s: build_ext_parallel is deprecated and will be removed in a "
Expand Down
43 changes: 0 additions & 43 deletions tests/test_vendor_rust.py

This file was deleted.

120 changes: 0 additions & 120 deletions tests/test_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,123 +337,3 @@ def test_validate_wheel_file(
else:
with pytest.raises(ValueError):
wheels.validate_wheel_filename(req, version, wheel_file)


@patch("fromager.wheels.add_extra_metadata_to_wheels")
@patch("fromager.wheels.overrides.find_and_invoke")
@patch("fromager.wheels.vendor_rust.has_rust_build_backend", return_value=True)
@patch("fromager.wheels.packagesettings.get_extra_environ", return_value={})
def test_build_wheel_sets_cargo_target_dir_for_rust_packages(
mock_get_extra_environ: Mock,
mock_has_rust: Mock,
mock_find_and_invoke: Mock,
mock_add_metadata: Mock,
tmp_path: pathlib.Path,
tmp_context: context.WorkContext,
) -> None:
"""CARGO_TARGET_DIR is set per package for Rust builds."""
req = Requirement("some-rust-pkg==1.0.0")
sdist_root = tmp_path / "some_rust_pkg-1.0.0"
sdist_root.mkdir()
build_env = build_environment.BuildEnvironment(
ctx=tmp_context,
req=req,
sdist_root_dir=sdist_root,
)

wheel_file = tmp_context.wheels_build / "some_rust_pkg-1.0.0-py3-none-any.whl"
wheel_file.parent.mkdir(parents=True, exist_ok=True)
wheel_file.touch()
mock_add_metadata.return_value = wheel_file

wheels.build_wheel(
ctx=tmp_context,
req=req,
sdist_root_dir=sdist_root,
version=Version("1.0.0"),
build_env=build_env,
)

extra_environ = mock_find_and_invoke.call_args.kwargs["extra_environ"]
assert extra_environ["CARGO_TARGET_DIR"] == str(sdist_root / "target")


@patch("fromager.wheels.add_extra_metadata_to_wheels")
@patch("fromager.wheels.overrides.find_and_invoke")
@patch("fromager.wheels.vendor_rust.has_rust_build_backend", return_value=True)
@patch(
"fromager.wheels.packagesettings.get_extra_environ",
return_value={"CARGO_TARGET_DIR": "/custom/target"},
)
def test_build_wheel_does_not_override_explicit_cargo_target_dir(
mock_get_extra_environ: Mock,
mock_has_rust: Mock,
mock_find_and_invoke: Mock,
mock_add_metadata: Mock,
tmp_path: pathlib.Path,
tmp_context: context.WorkContext,
) -> None:
"""Per-package CARGO_TARGET_DIR from settings takes precedence."""
req = Requirement("some-rust-pkg==1.0.0")
sdist_root = tmp_path / "some_rust_pkg-1.0.0"
sdist_root.mkdir()
build_env = build_environment.BuildEnvironment(
ctx=tmp_context,
req=req,
sdist_root_dir=sdist_root,
)

wheel_file = tmp_context.wheels_build / "some_rust_pkg-1.0.0-py3-none-any.whl"
wheel_file.parent.mkdir(parents=True, exist_ok=True)
wheel_file.touch()
mock_add_metadata.return_value = wheel_file

wheels.build_wheel(
ctx=tmp_context,
req=req,
sdist_root_dir=sdist_root,
version=Version("1.0.0"),
build_env=build_env,
)

extra_environ = mock_find_and_invoke.call_args.kwargs["extra_environ"]
assert extra_environ["CARGO_TARGET_DIR"] == "/custom/target"


@patch("fromager.wheels.add_extra_metadata_to_wheels")
@patch("fromager.wheels.overrides.find_and_invoke")
@patch("fromager.wheels.vendor_rust.has_rust_build_backend", return_value=False)
@patch("fromager.wheels.packagesettings.get_extra_environ", return_value={})
def test_build_wheel_skips_cargo_target_dir_for_non_rust_packages(
mock_get_extra_environ: Mock,
mock_has_rust: Mock,
mock_find_and_invoke: Mock,
mock_add_metadata: Mock,
tmp_path: pathlib.Path,
tmp_context: context.WorkContext,
) -> None:
"""Non-Rust packages do not get CARGO_TARGET_DIR."""
req = Requirement("pure-python-pkg==1.0.0")
sdist_root = tmp_path / "pure_python_pkg-1.0.0"
sdist_root.mkdir()
build_env = build_environment.BuildEnvironment(
ctx=tmp_context,
req=req,
sdist_root_dir=sdist_root,
)

wheel_file = tmp_context.wheels_build / "pure_python_pkg-1.0.0-py3-none-any.whl"
wheel_file.parent.mkdir(parents=True, exist_ok=True)
wheel_file.touch()
mock_add_metadata.return_value = wheel_file

wheels.build_wheel(
ctx=tmp_context,
req=req,
sdist_root_dir=sdist_root,
version=Version("1.0.0"),
build_env=build_env,
)

extra_environ = mock_find_and_invoke.call_args.kwargs["extra_environ"]
assert "CARGO_TARGET_DIR" not in extra_environ
Loading