Skip to content

Conversation

mati865
Copy link
Member

@mati865 mati865 commented Mar 4, 2024

Alternative to #121794

$ cargo b -r
    Finished `release` profile [optimized] target(s) in 0.38s

$ ntldd target/release/hello.exe | rg unwind
        libunwind.dll => H:\msys64\clang64\bin\libunwind.dll (0x0000020c35df0000)

$ RUSTFLAGS="-C target-feature=+crt-static" cargo b -r
    Finished `release` profile [optimized] target(s) in 0.23s

$ ntldd target/release/hello.exe | rg unwind

@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2024

r? @albertlarsan68

rustbot has assigned @albertlarsan68.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Mar 4, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2024

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

@mati865
Copy link
Member Author

mati865 commented Mar 4, 2024

Appears to work with both native toolchain and using -Zbuild-std but I'd like to test official dist archive. Could somebody run @bors try please? Thanks in advance.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 4, 2024
@albertlarsan68
Copy link
Member

Hello,
Thanks for your PR.
A try run will only test for x64 GNU linux.
You can edit the CI files to run the test suite you want, then ask again, unless you want to test only x64 GNU linux.

@mati865
Copy link
Member Author

mati865 commented Mar 4, 2024

Yes, this is intended. I want to try building from Linux host using Cargo's -Zbuild-std using official archive.

@albertlarsan68
Copy link
Member

@bors try

@bors
Copy link
Collaborator

bors commented Mar 5, 2024

⌛ Trying commit fd2b23b with merge e6c1f68...

@bors
Copy link
Collaborator

bors commented Mar 5, 2024

☀️ Try build successful - checks-actions
Build commit: e6c1f68 (e6c1f68d0f35b570d9eaa09d8b50a2b63c450e7f)

@mati865
Copy link
Member Author

mati865 commented Mar 6, 2024

As expected libunwind is not built by -Z build-std, additionally turns out -Z build-std doesn't apply -C target-feature (it's applied only to user's code):

Details

dbg! macros were not pushed to this branch.

$ cargo +stage1_gnullvm rustc -Zbuild-std --target x86_64-pc-windows-gnullvm -- -C target-feature=-crt-static
   Compiling compiler_builtins v0.1.108
   Compiling core v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\core)
   Compiling libc v0.2.153
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\std)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
   Compiling rustc-std-workspace-core v1.99.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\rustc-std-workspace-core)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
   Compiling alloc v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\alloc)
   Compiling cfg-if v1.0.0
   Compiling adler v1.0.2
   Compiling rustc-demangle v0.1.23
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
   Compiling unwind v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\unwind)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
   Compiling rustc-std-workspace-alloc v1.99.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\rustc-std-workspace-alloc)
   Compiling panic_unwind v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\panic_unwind)
   Compiling panic_abort v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\panic_abort)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
   Compiling gimli v0.28.1
   Compiling miniz_oxide v0.7.2
   Compiling object v0.32.2
   Compiling std_detect v0.1.5 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\stdarch\crates\std_detect)
   Compiling hashbrown v0.14.3
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
   Compiling addr2line v0.21.0
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
   Compiling proc_macro v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnullvm\stage1\lib\rustlib\src\rust\library\proc_macro)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = false
   Compiling panic v0.1.0 (D:\tmp\panic)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = true
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:412:13] found_positive = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = true
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:412:13] found_positive = false
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = true
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:412:13] found_positive = false
    Finished dev [unoptimized + debuginfo] target(s) in 19.13s

@kleisauke with this PR and #121712 Rust will ship prebuilt libunwind.a alongside other libs for these targets. That means you can use prebuilt std (installed with rustup) without libunwind.a present in your toolchain but -Z build-std will still require libunwind.a to be present.
Does this solve all your needs or do you need -Z build-std to work without libunwind.a as well?

@kleisauke
Copy link
Contributor

As expected libunwind is not built by -Z build-std, additionally turns out -Z build-std doesn't apply -C target-feature (it's applied only to user's code):

Just wondering, would -Zbuild-std-features=llvm-libunwind or -Zbuild-std-features=system-llvm-libunwind make any difference here?

with this PR and #121712 Rust will ship prebuilt libunwind.a alongside other libs for these targets.

Great! I think that would be very useful.

Does this solve all your needs or do you need -Z build-std to work without libunwind.a as well?

Unfortunately, I'm still using -Zbuild-std due to the Windows ARM32 target requirement (but I'm going to revisit this in the near future). Furthermore, within our toolchain, libunwind.a is not compiled when there's a preference for shared linkage.

@mati865
Copy link
Member Author

mati865 commented Mar 8, 2024

Just wondering, would -Zbuild-std-features=llvm-libunwind or -Zbuild-std-features=system-llvm-libunwind make any difference here?

I had thought of it previously but it feels hacky. System can provide both static and shared libunwind but this feature would have to be limited to shared only. Or maybe it's just my point of view?

Unfortunately, I'm still using -Zbuild-std due to the Windows ARM32 target requirement (but I'm going to revisit this in the near future). Furthermore, within our toolchain, libunwind.a is not compiled when there's a preference for shared linkage.

I'll ask on Zulip to see if anybody has any idea but I want to test something first.

@bjorn3
Copy link
Member

bjorn3 commented Mar 10, 2024

additionally turns out -Z build-std doesn't apply -C target-feature (it's applied only to user's code):

If you use cargo rustc -- -Csome-arg, -Csome-arg is only passed to the final crate that is built. If you use RUSTFLAGS="-Csome-arg", -Zbuild-std will respect it.

@mati865 mati865 marked this pull request as draft March 20, 2024 20:15
@mati865
Copy link
Member Author

mati865 commented Mar 20, 2024

Sorry, I was a bit busy with other things.

Thanks, indeed this was the case but apparently the problem was more complex.

When I test with native gnullvm toolchain (built and installed with ./x.py install --build x86_64-pc-windows-gnullvm --host x86_64-pc-windows-gnullvm --target x86_64-pc-windows-gnullvm using prebuilt gnullvm toolchain for bootstrap) and libunwind.a missing build fails because the flag is ignored:

Details

Note: this Cargo binary was built with x.py alongside Rustc.

$ RUSTFLAGS="-C target-feature=-crt-static" cargo b -Z build-std --target x86_64-pc-windows-gnullvm -j1
   Compiling compiler_builtins v0.1.108
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = true
error: linking with `x86_64-w64-mingw32-clang` failed: exit code: 1
  |
  = note: "x86_64-w64-mingw32-clang" "-nolibc" "--unwindlib=none" "-m64" "H:\\msys64\\tmp\\rustcVoAInG\\symbols.o" "D:\\tmp\\panic\\target\\debug\\build\\compiler_builtins-b79a7eedf8c0d029\\build_script_build-b79a7eedf8c0d029.build_script_build.9a53934735b65b99-cgu.0.rcgu.o" "D:\\tmp\\panic\\target\\debug\\build\\compiler_builtins-b79a7eedf8c0d029\\build_script_build-b79a7eedf8c0d029.build_script_build.9a53934735b65b99-cgu.1.rcgu.o" "D:\\tmp\\panic\\target\\debug\\build\\compiler_builtins-b79a7eedf8c0d029\\build_script_build-b79a7eedf8c0d029.build_script_build.9a53934735b65b99-cgu.2.rcgu.o" "D:\\tmp\\panic\\target\\debug\\build\\compiler_builtins-b79a7eedf8c0d029\\build_script_build-b79a7eedf8c0d029.build_script_build.9a53934735b65b99-cgu.3.rcgu.o" "D:\\tmp\\panic\\target\\debug\\build\\compiler_builtins-b79a7eedf8c0d029\\build_script_build-b79a7eedf8c0d029.build_script_build.9a53934735b65b99-cgu.4.rcgu.o" "D:\\tmp\\panic\\target\\debug\\build\\compiler_builtins-b79a7eedf8c0d029\\build_script_build-b79a7eedf8c0d029.18ovrelxx6weay1z.rcgu.o" "-L" "D:\\tmp\\panic\\target\\debug\\deps" "-L" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib" "-Wl,-Bstatic" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libstd-72b85cbf268c7c14.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libpanic_unwind-0c1c39b20562b60a.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libobject-d6fe485a6655d599.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libmemchr-a1f658cf6e351042.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libaddr2line-4c19c65ddedbb697.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libgimli-ebd8f1ccf4c71a85.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\librustc_demangle-1d2b2000310c3af9.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libstd_detect-323c4571649ead5d.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libhashbrown-26043183fc023068.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\librustc_std_workspace_alloc-f6d4df7f51a275cc.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libminiz_oxide-bb4ecb3dcc783829.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libadler-1de00ec187d51c9c.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libunwind-98e7503b1e534674.rlib" "-lunwind" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libcfg_if-79fd7b00cc20ded9.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\liblibc-596f2201c61e175b.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\liballoc-e849dd0e1627dbdf.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\librustc_std_workspace_core-f9f3757fdcfa2a73.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libcore-993c8506e8bea543.rlib" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib\\libcompiler_builtins-7ebfbfda1eb1b859.rlib" "-Wl,-Bdynamic" "-lkernel32" "-ladvapi32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-lsynchronization" "-lkernel32" "-lws2_32" "-lkernel32" "-lntdll" "-lkernel32" "-lmingw32" "-lmingwex" "-lmsvcrt" "-lkernel32" "-luser32" "-Wl,--nxcompat" "-L" "H:\\tmp\\rust\\lib\\rustlib\\x86_64-pc-windows-gnullvm\\lib" "-o" "D:\\tmp\\panic\\target\\debug\\build\\compiler_builtins-b79a7eedf8c0d029\\build_script_build-b79a7eedf8c0d029.exe" "-Wl,--gc-sections" "-static" "-no-pie"
  = note: x86_64-w64-mingw32-clang: warning: argument unused during compilation: '-nolibc' [-Wunused-command-line-argument]
          x86_64-w64-mingw32-clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
          lld: error: unable to find library -lunwind
          x86_64-w64-mingw32-clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `compiler_builtins` (build script) due to 1 previous error

Restoring libunwind.a makes the final binary link to static libunwind.

Then I tried to cross compile (with -Z build-std and gnullvm target ) from a windows-gnu toolchain that is missing libgcc and it failed because of missing libgcc:

Details

Note: this Cargo binary is a bit older nightly: cargo 1.77.0-nightly (ac6bbb332 2023-12-26).
Note2: [compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false is present again.

$ cargo +stage1_gnu b --target x86_64-pc-windows-gnullvm -Zbuild-std
   Compiling compiler_builtins v0.1.108
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = true
   Compiling libc v0.2.153
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnu\stage1\lib\rustlib\src\rust\library\std)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = false
[compiler\rustc_session\src\session.rs:421:13] self.target.crt_static_default = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "x86_64-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "C:\\Users\\mateusz\\AppData\\Local\\Temp\\rustcckqXIy\\symbols.o" "D:\\tmp\\panic\\target\\debug\\build\\std-9b8ad8037c1b2838\\build_script_build-9b8ad8037c1b2838.build_script_build.a03aaf86fb42fd71-cgu.0.rcgu.o" "D:\\tmp\\panic\\target\\debug\\build\\std-9b8ad8037c1b2838\\build_script_build-9b8ad8037c1b2838.2nxsv0hnm3j393pz.rcgu.o" "-L" "D:\\tmp\\panic\\target\\debug\\deps" "-L" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bstatic" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd-88ba3b3cba0c64ed.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libpanic_unwind-59ea7c64824ef776.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libobject-d33177e0e971fa19.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libmemchr-36de91dd776f2a08.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libaddr2line-760e0493e55d7a90.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libgimli-09126d4a95f3f591.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_demangle-de9ab12c2f2efeac.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd_detect-ce42ee94dc6529ea.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libhashbrown-1e781abfa547db98.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_std_workspace_alloc-5278135146ff5c94.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libminiz_oxide-07a041a5f2f36188.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libadler-cf980c3963b5283c.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libunwind-30ee30d5e9c1fc56.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcfg_if-848b06957b619713.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liblibc-06d5cd11aca2ee11.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liballoc-be8961b6024b8c36.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_std_workspace_core-ea451eb24792bb79.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcore-2447ae15269b5c81.rlib" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcompiler_builtins-4d92a5d2ada47422.rlib" "-Wl,-Bdynamic" "-lkernel32" "-ladvapi32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-lsynchronization" "-lkernel32" "-lws2_32" "-lkernel32" "-lntdll" "-lkernel32" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-L" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-o" "D:\\tmp\\panic\\target\\debug\\build\\std-9b8ad8037c1b2838\\build_script_build-9b8ad8037c1b2838.exe" "-Wl,--gc-sections" "-no-pie" "-nodefaultlibs" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnu\\stage1\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
  = note: x86_64-w64-mingw32-gcc: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
          lld: error: unable to find library -lgcc_eh
          lld: error: unable to find library -lgcc
          x86_64-w64-mingw32-gcc: error: linker command failed with exit code 1 (use -v to see invocation)
This is what made me think `-Z build-std` builds something for the host (proc-macros?) and full std for the target.

That wouldn't be big deal if the final binary was linked to target's std but somehow if host == target it gets linked to host's std (probably the prebuilt one in sysroot).

Finally cross compiling from working windows-gnu toolchain gave the expected result:

Details

Note: Cargo is the same but Rustc prints all [compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = true as expected this time 🤷🏻‍♂️

RUSTFLAGS="-C target-feature=+crt-static" cargo +stage1_gnu b --target x86_64-pc-windows-gnullvm -Zbuild-std
   Compiling compiler_builtins v0.1.108
   Compiling core v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnu\stage1\lib\rustlib\src\rust\library\core)
   Compiling libc v0.2.153
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnu\stage1\lib\rustlib\src\rust\library\std)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = true
[compiler\rustc_session\src\session.rs:412:13] found_positive = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = true
[compiler\rustc_session\src\session.rs:412:13] found_positive = true    Finished dev [unoptimized + debuginfo] target(s) in 19.43s

$ ntldd target/x86_64-pc-windows-gnullvm/debug/panic.exe
        KERNEL32.dll => C:\Windows\SYSTEM32\KERNEL32.dll (0x000002250d030000)
        libunwind.dll => D:\msys64\mingw64\bin\libunwind.dll (0x000002250d030000)
        ntdll.dll => C:\Windows\SYSTEM32\ntdll.dll (0x000002250d200000)

$ cargo clean
     Removed 258 files, 214.2MiB total

$ RUSTFLAGS="-C target-feature=+crt-static" PATH=/d/msys64/mingw64/bin:/h/msys64/clang64/bin:$PATH ~/.cargo/bin/cargo +stage1_gnu b --target x86_64-pc-windows-gnullvm -Zbuild-std
...
    Finished dev [unoptimized + debuginfo] target(s) in 19.61s

$ ntldd target/x86_64-pc-windows-gnullvm/debug/panic.exe
        KERNEL32.dll => C:\Windows\SYSTEM32\KERNEL32.dll (0x00000195be160000)
        ntdll.dll => C:\Windows\SYSTEM32\ntdll.dll (0x00000195be330000)

Logs from a working build are very different from the failing ones, so I've decided to run it with -j1 but it confused me even more:

Details
$ RUSTFLAGS="-C target-feature=+crt-static" PATH=/d/msys64/mingw64/bin:/h/msys64/clang64/bin:$PATH ~/.cargo/bin/cargo +stage1_gnu b --target x86_64-pc-windows-gnullvm -Zbuild-std -j1
   Compiling compiler_builtins v0.1.108
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = true
   Compiling core v0.0.0 (H:\projects\rust\build\x86_64-pc-windows-gnu\stage1\lib\rustlib\src\rust\library\core)
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = true
[compiler\rustc_session\src\session.rs:412:13] found_positive = true
[compiler\rustc_session\src\session.rs:400:12] !self.target.crt_static_respected = false
[compiler\rustc_session\src\session.rs:406:30] requested_features.clone().any(|r| r == "-crt-static") = false
[compiler\rustc_session\src\session.rs:407:30] requested_features.clone().any(|r| r == "+crt-static") = true
[compiler\rustc_session\src\session.rs:412:13] found_positive = true

The conclusion is there is some weirdness (hopefully caused by unknown difference between official dist and my setup) to -Z build-std but in the end I've got it working by cross compiling and hope the official dist binaries will work the same way.

What needs to be sorted out is whether we want to use crt-static for libunwind only. Mingw-w64 cannot statically link whole CRT because it's proprietary closed source code, so it wouldn't be the same as crt-static on windows-msvc where whole CRT is linked statically.

@kleisauke
Copy link
Contributor

Perhaps you should set crt_static_respected: true in compiler/rustc_target/src/spec/base/windows_gnullvm.rs, similar to what is done for MSVC?

crt_static_respected: true,

(untested, but noticed that for FreeBSD something similar was done in commit adce3fd)

@Dylan-DPC
Copy link
Member

@mati865 any updates on this? thanks

@mati865 mati865 force-pushed the gnullvm-build-libunwind branch from fd2b23b to 51b1136 Compare September 29, 2024 15:22
@mati865 mati865 changed the title Build libunwind for pc-windows-gnullvm control libunwind linkage mode via crt-static on gnullvm targets Sep 29, 2024
@mati865
Copy link
Member Author

mati865 commented Sep 29, 2024

@kleisauke first off, sorry taking so long. #119229 had drained my battery for a while.

I'm sure I have tested something similar to what you have posted, but it didn't work that time (maybe I have missed something back then).
I have tested this solution, and it works fine (at least for small crates, but I don't expect any issues), so I've went ahead and added you as the coauthor.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 29, 2024
@mati865 mati865 marked this pull request as ready for review September 29, 2024 15:32
@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2024

These commits modify compiler targets.
(See the Target Tier Policy.)

@mati865
Copy link
Member Author

mati865 commented Nov 20, 2024

@rustbot r? compiler

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 20, 2024
@rustbot rustbot assigned BoxyUwU and unassigned albertlarsan68 Nov 20, 2024
@jieyouxu jieyouxu added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Nov 25, 2024
@jieyouxu
Copy link
Member

r? @petrochenkov (this modifies windows-gnullvm base spec, I think u might know a bit about this target)

@rustbot rustbot assigned petrochenkov and unassigned BoxyUwU Nov 25, 2024
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 10, 2024

📌 Commit d442cf5 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 10, 2024
@bors bors merged commit a4cf1f8 into rust-lang:master Dec 12, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 12, 2024
@mati865 mati865 deleted the gnullvm-build-libunwind branch December 12, 2024 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants