Skip to content

cross-built compiler doesn't have the standard library for the target in its sysroot #77352

Open
@glandium

Description

@glandium
Contributor

This is actually a followup to #76733, because somehow I overlooked that when checking the fix for that issue worked.

After building the compiler with the following config.toml:

[build]
build = "x86_64-apple-darwin"
host = ["aarch64-apple-darwin"]
target = ["aarch64-apple-darwin"]

you end up with a compiler without any of the libstd, etc. rlibs, meaning that using the compiler fails with:

error[E0463]: can't find crate for `std`

The same is true when building with the following config.toml on linux:

[build]
build = "x86_64-unknown-linux-gnu"
host = ["i686-unknown-linux-gnu"]
target = ["i686-unknown-linux-gnu"]

Cc @Mark-Simulacrum

Activity

added
A-crossArea: Cross compilation
T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
on Sep 30, 2020
jyn514

jyn514 commented on Sep 30, 2020

@jyn514
Member

How are you building the compiler, what x.py command?

jyn514

jyn514 commented on Sep 30, 2020

@jyn514
Member

It sounds like you're using build --stage 1 compiler/rustc; to get the standard library you need build --stage 2.

Mark-Simulacrum

Mark-Simulacrum commented on Sep 30, 2020

@Mark-Simulacrum
Member

I know what the problem here is, currently thinking/working on a solution.

Mark-Simulacrum

Mark-Simulacrum commented on Sep 30, 2020

@Mark-Simulacrum
Member

I think this is the same underlying problem as I noted in #76799 (comment) -- for now, I think x.py dist library/std src/librustc should build just std + rustc tarballs and put them in the build/dist directory, and if those are unpacked they will contain the expected contents.

The reason this isn't fully working today is because rustbuild has no reason to populate the (internal) stage2/ compiler directory with a standard library and compiler for i686-unknown-linux-gnu; you're not able to run that locally (or so it assumes, since it could be the case).

The proper fix is quite involved -- we'd need to rework rustbuild to support the notion that while we only need to build std for each target once, we need to promote it into multiple places. Which places to copy to is not entirely obvious; I think the right answer is every host compiler in that stage, but it would potentially create awkward artifacts in e.g. i686/stage1/lib/rustlib where they don't really need to be.

I am still thinking -- there might be a targeted fix here that we can apply. For now my recommendation is that if you want to cross-compile, you use x.py dist which is likely always going to be the more stable command (since it gives you closer to "what I asked for" instead of trying to be smart and failing).

glandium

glandium commented on Oct 1, 2020

@glandium
ContributorAuthor

x.py dist doesn't leave you with a working compiler in some directory. You need to x.py install for that, which puts things in /usr/local, which you may or may not want.

Mark-Simulacrum

Mark-Simulacrum commented on Oct 1, 2020

@Mark-Simulacrum
Member

That seems easily solvable, though: [install] prefix = "/my/own/directory" in config.toml.

changed the title [-]cross-built compiler can't compile[/-] [+]cross-built compiler doesn't have the standard library for the target in its sysroot[/+] on Feb 3, 2023
Enselic

Enselic commented on Nov 26, 2024

@Enselic
Member

Triage: This issue is quite old by now. Is this still a problem?

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

    A-crossArea: Cross compilationC-bugCategory: This is a bug.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Enselic@glandium@Mark-Simulacrum@jyn514

        Issue actions

          cross-built compiler doesn't have the standard library for the target in its sysroot · Issue #77352 · rust-lang/rust