Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cross compiling with cross #1865

Merged
merged 1 commit into from
Nov 26, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ test-crates/wheels/
test-crates/targets/
test-crates/venvs/
node_modules
.idea
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ base64 = "0.21.0"
glob = "0.3.0"
cargo-config2 = "0.1.9"
cargo_metadata = "0.18.0"
cargo-options = "0.7.1"
cargo-options = "0.7.2"
cbindgen = { version = "0.26.0", default-features = false }
flate2 = "1.0.18"
goblin = "0.7.1"
Expand Down
16 changes: 15 additions & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ fn compile_target(

debug!("Running {:?}", build_command);

let using_cross = build_command
.get_program()
.to_string_lossy()
.starts_with("cross");
let mut cargo_build = build_command
.spawn()
.context("Failed to run `cargo rustc`")?;
Expand Down Expand Up @@ -494,8 +498,18 @@ fn compile_target(
.into_iter()
.zip(artifact.filenames);
for (crate_type, filename) in tuples {
let path = if using_cross && filename.starts_with("/target") {
// Convert cross target path in docker back to path on host
context
.cargo_metadata
.target_directory
.join(filename.strip_prefix("/target").unwrap())
.into_std_path_buf()
} else {
filename.into()
};
let artifact = BuildArtifact {
path: filename.into(),
path,
linked_paths: Vec::new(),
};
artifacts.insert(crate_type, artifact);
Expand Down
4 changes: 4 additions & 0 deletions src/project_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ impl ProjectResolver {
debug!("Resolving cargo metadata from {:?}", manifest_path);
let cargo_metadata_extra_args = extract_cargo_metadata_args(cargo_options)?;
let result = MetadataCommand::new()
// Force resolving metadata using cargo instead of instead of $CARGO env var
// to avoid getting wrong file path like target directory, for example `cross` would
// output paths in docker while we want paths on host.
.cargo_path("cargo")
.manifest_path(manifest_path)
.verbose(true)
.other_options(cargo_metadata_extra_args)
Expand Down
Loading