rust-osdev / cargo-xbuild

Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc.
Apache License 2.0
258 stars 25 forks source link

TARGET in build.rs is invalid #19

Closed berkus closed 5 years ago

berkus commented 5 years ago

When using a full path to json file as cargo-xbuild --target argument, the resulting TARGET is not a triple but instead a full file path. I believe it should be a triple.

According to cargo book:

TARGET - the target triple that is being compiled for. Native code should be compiled for this triple.

What I'm getting:

λ cargo xbuild --target=targets/aarch64-vesper-metta.json
   Compiling vesper v1.0.0 (/path/to/vesper)
error: failed to run custom build command for `vesper v1.0.0 (/path/to/vesper)`
process didn't exit successfully: `/path/to/vesper/target/debug/build/vesper-6432e1d623b2c988/build-script-build` (exit code: 101)
--- stderr
Target /path/to/vesper/targets/aarch64-vesper-metta.json
thread 'main' panicked at 'TARGET env variable is not set to one of supported values', build.rs:43:9

The line Target /path/to/vesper/targets/aarch64-vesper-metta.json is output by build.rs from the TARGET env var.

phil-opp commented 5 years ago

Seems like the cargo documentation is not specific enough or out of date. A target triple in rust can be either a triple string or a path to a JSON file: https://github.com/rust-lang/rust/blob/653da4fd006c97625247acd7e076d0782cdc149b/src/librustc_target/spec/mod.rs#L1275-L1278

berkus commented 5 years ago

Hmm, ok, still very inconvenient because my build.rs only need to look at the TRIPLE regardless of actual json file path.

Can this be added? Maybe even to cargo? (As TARGET_TRIPLE for example)

Basically this means I just need result of calling triple() on the triple, so I can probably construct it from the envvar and then call the triple() function, let me try that.

berkus commented 5 years ago

Probably it makes more sense to match on (CARGO_CFG_TARGET_ARCH, CARGO_CFG_TARGET_OS, CARGO_CFG_TARGET_FAMILY) triple instead.

phil-opp commented 5 years ago

You could use https://doc.rust-lang.org/std/path/struct.Path.html#method.file_stem to get the triple from a path.

berkus commented 5 years ago

I used direct match on the env vars and it worked excellently!

phil-opp commented 5 years ago

Cool!