Skip to content

cargo-miri does not support .json target files #2053

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

Closed
budde25 opened this issue Apr 6, 2022 · 6 comments · Fixed by #2744
Closed

cargo-miri does not support .json target files #2053

budde25 opened this issue Apr 6, 2022 · 6 comments · Fixed by #2744
Labels
A-target Area: concerns targets outside of what we currently support C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out

Comments

@budde25
Copy link

budde25 commented Apr 6, 2022

rustc 1.61.0-nightly (76d770ac2 2022-04-02)
When I run cargo miri test with a custom target I get an error

If I run cargo miri test --target ./x86_64-os.json I get

error: target path "./x86_64-os.json" is not a valid file

Caused by:
  No such file or directory (os error 2)
fatal error: failed to run xargo

same error if I try thiscargo miri test --target x86_64-os.json

then I tried a fully qualified path cargo miri test --target /home/budd/Code/os/x86_64-os.json
and it said

error: Xargo doesn't support files as an argument to --target. Use `--target foo` instead of `--target foo.json`.
note: run with `RUST_BACKTRACE=1` for a backtrace
fatal error: failed to run xargo

finally I tried without the .json as cargo miri test --target /home/budd/Code/os/x86_64-os and got a panic

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: StripPrefixError(())', src/tools/cargo/src/cargo/core/compiler/fingerprint.rs:1290:60
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: `"/home/budd/.rustup/toolchains/nightly-2022-04-03-x86_64-unknown-linux-gnu/bin/cargo" "check" "--release" "--manifest-path" "/tmp/xargo.buKrTnrXV4hZ/Cargo.toml" "--target" "/home/budd/Code/os/x86_64-os" "-p" "std"` failed with exit code: Some(101)
note: run with `RUST_BACKTRACE=1` for a backtrace
fatal error: failed to run xargo

If custom target files are not supported by miri I think the error should be more clear, especially the first one that just said file not valid.
Also this target works perfectly fine without miri.

the x86_64-os.json is bellow.

{
  "llvm-target": "x86_64-unknown-none-gnu",
  "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
  "arch": "x86_64",
  "target-endian": "little",
  "target-pointer-width": "64",
  "target-c-int-width": "32",
  "os": "none",
  "executables": true,
  "linker-flavor": "ld.lld",
  "linker": "rust-lld",
  "panic-strategy": "abort",
  "disable-redzone": true,
  "features": "-mmx,-sse,+soft-float",
  "pre-link-args": {
    "ld.lld": [
      "--script=src/arch/x86_64/linker.ld"
    ]
  }
}
@RalfJung
Copy link
Member

RalfJung commented Apr 6, 2022

I know basically nothing about custom target JSON files so I guess they are not supported, probably?

But it looks like they are unsupported by xargo and hence by extension also unsupported by Miri. A better error would indeed be nice; I am not sure what the best way would be to detect that situation though since the cargo-miri wrapper that invokes xargo doesn't know anything about targets.

@bjorn3

This comment was marked as resolved.

@RalfJung
Copy link
Member

RalfJung commented Apr 6, 2022

We could probably look for a .json suffix here:

let target = get_arg_flag_value("--target");

Try passing the absolute path to the json file.

They did that, /home/budd/Code/os/x86_64-os.json did not work either.

@RalfJung RalfJung added A-target Area: concerns targets outside of what we currently support C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out labels Jun 5, 2022
@berkus
Copy link

berkus commented Jun 21, 2022

Why does miri use xargo, instead of say, -Z build-std?

@RalfJung
Copy link
Member

RalfJung commented Jun 21, 2022

  1. Miri's use of xargo predates -Z build-std.
  2. Miri needs to build a sysroot that is usable for a range of crates, not just a stdlib for a particular crate. This has some subtle differences, in particular around panics: a sysroot contains both panic_abort and panic_unwind, but -Z build-std will only build one of them.

If someone can figure out how to build reusable sysroots with -Z build-std, I'd be happy for Miri to drop its dependency on xargo.

@RalfJung RalfJung changed the title Fails to find target json file cargo-miri does not support .json target files Nov 30, 2022
@RalfJung
Copy link
Member

Status update: we are not using xargo any more, we are using https://github.com/RalfJung/rustc-build-sysroot. However that does not support target json files either. so this is probably blocked on RalfJung/rustc-build-sysroot#4.

bors added a commit that referenced this issue Dec 28, 2022
support using a JSON target file

Fixes #2053
bors added a commit that referenced this issue Dec 28, 2022
support using a JSON target file

Fixes #2053
@bors bors closed this as completed in 61a933f Dec 28, 2022
RalfJung pushed a commit to RalfJung/rust that referenced this issue Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target Area: concerns targets outside of what we currently support C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants