Skip to content

Unresolved imports with custom target and build-std #104761

Closed
@cilki

Description

@cilki

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]

Activity

transferred this issue fromrust-lang/cargoon Nov 23, 2022
ehuss

ehuss commented on Nov 23, 2022

@ehuss
Contributor

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

cilki commented on Nov 23, 2022

@cilki
Author

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.

added
-Zbuild-stdUnstable Cargo option: Compile the standard library yourself.
on Mar 13, 2023
added
T-libsRelevant to the library team, which will review and decide on the PR/issue.
on Apr 27, 2023
Enselic

Enselic commented on Dec 3, 2024

@Enselic
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zbuild-stdUnstable Cargo option: Compile the standard library yourself.A-crossArea: Cross compilationA-target-specsArea: Compile-target specificationsC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@Enselic@cilki@jyn514@workingjubilee

        Issue actions

          Unresolved imports with custom target and build-std · Issue #104761 · rust-lang/rust