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

Add support for self-contained object files (musl). #829

Merged
merged 4 commits into from
Jul 30, 2021

Conversation

UebelAndre
Copy link
Collaborator

In newer rust-std artifacts there is a self-contained directory which contains some .o files. These are currently ignored but without them the rules cannot target musl and users will see a similar linker error:

error: linking with `...`
  |
  = note: `...`
  = note: `...`: error: rct1.o: No such file or directory
          `...`: error: crti.o: No such file or directory
          `...`: error: crtbeginS.o: No such file or directory
          `...`: error: crtendS.o: No such file or directory
          `...`: error: crtn.o: No such file or directory

These files appear to have been introduced in Rust 1.46.0. They seem related to rust-lang/rust#70740 but I'm still not clear what mechanism actually generates and installs these directories in the artifacts.

Regardless, this change addresses these linker issues without impacting other target triples as far as I can tell.

@google-cla google-cla bot added the cla: yes label Jul 10, 2021
@UebelAndre UebelAndre changed the title Add support for self-contained files. Add support for self-contained object files. Jul 10, 2021
@UebelAndre
Copy link
Collaborator Author

UebelAndre commented Jul 10, 2021

I also wrote this script to find what artifacts contained the self-contained directory and what was inside it. Only musl populates this directory.

#!/bin/bash

set -euo pipefail

MUSL=(
rust-std-1.26.0-aarch64-unknown-linux-musl
rust-std-1.26.0-x86_64-unknown-linux-musl
rust-std-1.36.0-aarch64-unknown-linux-musl
rust-std-1.36.0-aarch64-unknown-linux-musl
rust-std-1.45.0-aarch64-unknown-linux-musl
rust-std-1.45.0-x86_64-unknown-linux-musl
rust-std-1.46.0-aarch64-unknown-linux-musl
rust-std-1.46.0-x86_64-unknown-linux-musl
rust-std-1.53.0-aarch64-unknown-linux-musl
)

OTHER=(
rust-std-1.45.0-x86_64-apple-darwin
rust-std-1.45.0-wasm32-unknown-unknown
rust-std-1.45.0-x86_64-pc-windows-msvc
rust-std-1.46.0-x86_64-apple-darwin
rust-std-1.46.0-wasm32-unknown-unknown
rust-std-1.46.0-x86_64-pc-windows-msvc
)

function find_self_contained() {
    temp_dir="$(mktemp -d -t rust-self-contained)"
    pushd "${temp_dir}"
    for art in ${@}; do
        echo "${art}"
        wget --quiet https://static.rust-lang.org/dist/${art}.tar.gz
        tar -xf "${art}.tar.gz"
        find "${art}" -name "self-contained" -exec tree {} \;
    done
    popd && rm -rf "${temp_dir}"
}

echo "Test MUSL"
find_self_contained ${MUSL[@]}

echo "Test OTHER"
find_self_contained ${OTHER[@]}
Test MUSL
/var/folders/hf/phjl9q7501gb5wt_qr4ltn3m0000gn/T/rust-self-contained.KEpXUBeb ~/Code/rules_rust
rust-std-1.26.0-aarch64-unknown-linux-musl
rust-std-1.26.0-x86_64-unknown-linux-musl
rust-std-1.36.0-aarch64-unknown-linux-musl
rust-std-1.36.0-aarch64-unknown-linux-musl
rust-std-1.45.0-aarch64-unknown-linux-musl
rust-std-1.45.0-x86_64-unknown-linux-musl
rust-std-1.46.0-aarch64-unknown-linux-musl
rust-std-1.46.0-aarch64-unknown-linux-musl/rust-std-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained
├── Scrt1.o
├── crt1.o
├── crti.o
├── crtn.o
└── rcrt1.o

0 directories, 5 files
rust-std-1.46.0-x86_64-unknown-linux-musl
rust-std-1.46.0-x86_64-unknown-linux-musl/rust-std-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained
├── Scrt1.o
├── crt1.o
├── crti.o
├── crtn.o
└── rcrt1.o

0 directories, 5 files
rust-std-1.53.0-aarch64-unknown-linux-musl
rust-std-1.53.0-aarch64-unknown-linux-musl/rust-std-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained
├── Scrt1.o
├── crt1.o
├── crtbegin.o
├── crtbeginS.o
├── crtend.o
├── crtendS.o
├── crti.o
├── crtn.o
└── rcrt1.o

0 directories, 9 files
~/Code/rules_rust
Test OTHER
/var/folders/hf/phjl9q7501gb5wt_qr4ltn3m0000gn/T/rust-self-contained.0crH80lq ~/Code/rules_rust
rust-std-1.45.0-x86_64-apple-darwin
rust-std-1.45.0-wasm32-unknown-unknown
rust-std-1.45.0-x86_64-pc-windows-msvc
rust-std-1.46.0-x86_64-apple-darwin
rust-std-1.46.0-x86_64-apple-darwin/rust-std-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/self-contained

0 directories, 0 files
rust-std-1.46.0-wasm32-unknown-unknown
rust-std-1.46.0-wasm32-unknown-unknown/rust-std-wasm32-unknown-unknown/lib/rustlib/wasm32-unknown-unknown/lib/self-contained

0 directories, 0 files
rust-std-1.46.0-x86_64-pc-windows-msvc
rust-std-1.46.0-x86_64-pc-windows-msvc/rust-std-x86_64-pc-windows-msvc/lib/rustlib/x86_64-pc-windows-msvc/lib/self-contained

0 directories, 0 files

@UebelAndre
Copy link
Collaborator Author

Also, I'm not sure how to add a test for musl... The changes here work though 😅

@UebelAndre UebelAndre changed the title Add support for self-contained object files. Add support for self-contained object files (musl). Jul 13, 2021
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel like I have enough context to really review this (or indeed to suggest how to test it on CI), but in general the change looks reasonable? If anyone has more context, it'd be great for them to review, otherwise I can somewhat unknowingly approve...

rust/toolchain.bzl Show resolved Hide resolved
rust/toolchain.bzl Show resolved Hide resolved
@hlopko
Copy link
Member

hlopko commented Jul 15, 2021

Is there a way we could have a test?

@UebelAndre UebelAndre requested a review from hlopko July 15, 2021 11:53
@UebelAndre
Copy link
Collaborator Author

Is there a way we could have a test?

I had the same question (#829 (comment)) and opened bazelbuild/continuous-integration#1190 to try and answer it. Any suggestions?

rust/toolchain.bzl Show resolved Hide resolved
rust/toolchain.bzl Show resolved Hide resolved
@UebelAndre UebelAndre merged commit c2f5701 into bazelbuild:main Jul 30, 2021
@UebelAndre UebelAndre deleted the musl branch July 30, 2021 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants