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

Can't build std if I specify target json file: std does not see networking #60

Closed
vi opened this issue Sep 17, 2020 · 5 comments · Fixed by rust-lang/rust#120232
Closed
Labels
implementation Implementation exploration and tracking issues plan before stabilization This needs a plan for how to address before stabilization, but does not need to be implemented. upstream An issue with the standard library itself or its dependencies.

Comments

@vi
Copy link

vi commented Sep 17, 2020

Building hello world for x86_64-unknown-linux-gnu works.

But if I save x86_64-unknown-linux-gnu's target specification to json and build using that json, std fails to find socket-related things.

$ cargo --version
cargo 1.48.0-nightly (8777a6b1e 2020-09-15)
$ rustc --version
rustc 1.48.0-nightly (285fc7d70 2020-09-16)

$ rustc +nightly -Z unstable-options --print target-spec-json > mytarget.json
$ gvim mytarget.json # change `is-builin` to `false`. It doesn't matter actually.
$ cargo build --release -Zbuild-std=panic_abort,std -Zbuild-std-features=panic_immediate_abort --target=./mytarget.json
...
   Compiling std v0.0.0 (/nix/rust/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
error[E0432]: unresolved imports `crate::sys_common::net::getsockopt`, `crate::sys_common::net::setsockopt`, `crate::sys_common::net::sockaddr_to_addr`
 --> /nix/rust/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/net.rs:8:30
  |
8 | use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr};
  |                              ^^^^^^^^^^  ^^^^^^^^^^  ^^^^^^^^^^^^^^^^ no `sockaddr_to_addr` in `sys::unix::net`
  |                              |           |
  |                              |           no `setsockopt` in `sys::unix::net`
  |                              no `getsockopt` in `sys::unix::net`

error[E0432]: unresolved import `crate::sys_common::net::LookupHost`
... (a lot of other missing things related to networking) ...

I except building using custom target json that happens to be the same as built-in json to be exactly the same as building specifying built-in target directly.

@alexcrichton
Copy link
Member

This looks like it's an issue with libstd and various cfg options. I don't think it's a bug with Cargo's support here?

@ehuss
Copy link
Contributor

ehuss commented Sep 18, 2020

This isn't directly related to Cargo, but it is related to rust-lang/rust#74033, with the intent of helping with build-std support. JSON spec support isn't in a great place right now, unfortunately.

This particular issue is due to the target-name sniffing done here. If you rename the JSON file to something like x86_64-unknown-linux-gnu.json, this should work.

The intent is to fix the build scripts that inspect target, just haven't gotten around to it, yet. There should probably be an issue somewhere to track that, I don't think there is, yet. This is as good a place as any, I think, even though this is an issue with the standard library.

@maspe36
Copy link

maspe36 commented Dec 3, 2021

Currently messing around trying to cross-compile a rust binary for QNX and I also hit this issue. I moved forward by just changing the name of my custom target to something its not, which did find these symbols.

Should we inspect the value of the llvm-target instead of the target name itself? Not sure if there are any cases where the target name and llvm-target name don't lineup intentionally

@roblabla
Copy link

roblabla commented Dec 3, 2021

This should probably not use llvm-target. I suspect it should instead use the CARGO_CFG_TARGET_* variables, see https://doc.rust-lang.org/cargo/reference/environment-variables.html. Those values can be controlled from within the target spec json. In particular, using CARGO_CFG_TARGET_OS should do the trick for the vast majority of those.

@ehuss ehuss added implementation Implementation exploration and tracking issues plan before stabilization This needs a plan for how to address before stabilization, but does not need to be implemented. upstream An issue with the standard library itself or its dependencies. labels May 3, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 27, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 27, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 29, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 11, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Feb 11, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
@ehuss
Copy link
Contributor

ehuss commented Feb 12, 2024

Closing as resolved by rust-lang/rust#120232.

@ehuss ehuss closed this as completed Feb 12, 2024
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes rust-lang/wg-cargo-std-aware#60.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
implementation Implementation exploration and tracking issues plan before stabilization This needs a plan for how to address before stabilization, but does not need to be implemented. upstream An issue with the standard library itself or its dependencies.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants