Closed
Description
Problem
I'm trying to create a custom target, but I can't seem to compile std
even when the custom target is basically identical to the built-in.
error[E0432]: unresolved import `crate::sys_common::net::LookupHost`
--> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/net/socket_addr.rs:14:5
|
14 | use crate::sys_common::net::LookupHost;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `LookupHost` in `sys::unix::net`
error[E0432]: unresolved imports `crate::sys_common::net::getsockopt`, `crate::sys_common::net::setsockopt`, `crate::sys_common::net::sockaddr_to_addr`
--> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/net.rs:9:30
|
9 | 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[E0433]: failed to resolve: could not find `TcpStream` in `net_imp`
--> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/net/[tcp.rs:157](http://tcp.rs:157/):41
|
157 | super::each_addr(addr, net_imp::TcpStream::connect).map(TcpStream)
| ^^^^^^^^^ could not find `TcpStream` in `net_imp`
Steps
docker run -it --rm debian
apt update && apt install -y gcc curl
curl https://sh.rustup.rs/ -sSf | sh -s -- -y --default-toolchain none
source $HOME/.cargo/env
rustup toolchain install nightly --component rustc cargo rust-src
cargo new reproducer
cd reproducer
rustc --print=target-spec-json -Z unstable-options | grep -v is-builtin >custom.json
cargo +nightly rustc --target=custom.json -Z build-std
Possible Solution(s)
No response
Notes
No response
Version
cargo 1.67.0-nightly (eb5d35917 2022-11-17)
release: 1.67.0-nightly
commit-hash: eb5d35917b2395194593c9ca70c3778f60c1573b
commit-date: 2022-11-17
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:OpenSSL/1.1.1q)
os: Linux [64-bit]
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ehuss commentedon Nov 23, 2022
Transferred to rust-lang/rust as this is an issue with the standard library.
The issue is that the build scripts all do target-name sniffing, and that doesn't work with a target named "custom.json".
The fix is that all the places that look at the target name should be removed (for example here). These should be looking at the specific
CARGO_CFG_*
values instead. I think there may be some cases where the required information isn't available in the cfg, so those will need some more extensive work to support.I thought there was an existing issue for this, but I couldn't find it.
cilki commentedon Nov 23, 2022
Thanks! Indeed renaming the target to
x86_64-custom-linux-gnu.json
fixes the compile errors. That'll get me by for now, but I'll take a stab at fixing the underlying issue like you said at some point.build-std
compilation fails depending on custom target's file name when compiling wasm32 with target-feature atomics rust-lang/cargo#13035Enselic commentedon Dec 3, 2024
Triage: This should have been fixed by #120232. Tentatively closing as fixed. If there is still a problem, please provide updated step-by-step instructions on how to reproduce. Thanks!