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

Unresolved imports with custom target and build-std #104761

Closed
cilki opened this issue Nov 23, 2022 · 3 comments
Closed

Unresolved imports with custom target and build-std #104761

cilki opened this issue Nov 23, 2022 · 3 comments
Labels
-Zbuild-std Unstable Cargo option: Compile the standard library yourself. A-cross Area: Cross compilation A-target-specs Area: Compile-target specifications C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@cilki
Copy link

cilki commented Nov 23, 2022

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]
@cilki cilki added the C-bug Category: This is a bug. label Nov 23, 2022
@ehuss ehuss transferred this issue from rust-lang/cargo Nov 23, 2022
@ehuss
Copy link
Contributor

ehuss commented 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
Copy link
Author

cilki commented 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.

@workingjubilee workingjubilee added the -Zbuild-std Unstable Cargo option: Compile the standard library yourself. label Mar 13, 2023
@jyn514 jyn514 added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Apr 27, 2023
@Enselic Enselic added A-cross Area: Cross compilation A-target-specs Area: Compile-target specifications labels Nov 22, 2024
@Enselic
Copy link
Member

Enselic commented 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!

@Enselic Enselic closed this as completed Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zbuild-std Unstable Cargo option: Compile the standard library yourself. A-cross Area: Cross compilation A-target-specs Area: Compile-target specifications C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants