Skip to content

cc-wrapper: wrap TOOL and ${targetPrefix}-TOOL if both exist#181724

Closed
trofi wants to merge 1 commit intoNixOS:masterfrom
trofi:cc-wrappers-are-prefix-consistent
Closed

cc-wrapper: wrap TOOL and ${targetPrefix}-TOOL if both exist#181724
trofi wants to merge 1 commit intoNixOS:masterfrom
trofi:cc-wrappers-are-prefix-consistent

Conversation

@trofi
Copy link
Copy Markdown
Contributor

@trofi trofi commented Jul 16, 2022

In #87909 ("stdenv: always
pass --build, --host to configure") we noticed that stdenv.cc
exposes c++ as a wrapped bianry and x86_64-unknown-linux-gnu-c++
as unsrapped binary.

As a result x86_64-unknown-linux-gnu-c++ was not able to create
basic bianries. This makes seepingly no-op --host=x86_64-unknown-linux-gnu
option for ./configure a breaking change.

This change adds wrappers to prefixed binaries for cross and
native cases where such an inconsistency exists. New validation
change will catch new possible inconsistencies. It already caught
existing inconsistencies in: gcc, gfortran, gcj, gccgo, gdc.

At least radare2 build is fixed by consistent wrappers. It used to fail
before as:

radare2> ERROR: x86_64-unknown-linux-gnu-gcc cannot create executables

Issue: #178802

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

In NixOS#87909 ("stdenv: always
pass --build, --host to configure") we noticed that stdenv.cc
exposes `c++` as a wrapped bianry and `x86_64-unknown-linux-gnu-c++`
as unsrapped binary.

As a result `x86_64-unknown-linux-gnu-c++` was not able to create
basic bianries. This makes seepingly no-op `--host=x86_64-unknown-linux-gnu`
option for `./configure` a breaking change.

This change adds wrappers to prefixed binaries for cross and
native cases where such an inconsistency exists. New validation
change will catch new possible inconsistencies. It already caught
existing inconsistencies in: `gcc`, `gfortran`, `gcj`, `gccgo`, `gdc`,
`clang`.

At least `radare2` build is fixed by consistent wrappers. It used to fail
before as:

    radare2> ERROR: x86_64-unknown-linux-gnu-gcc cannot create executables

Issue: NixOS#178802
@trofi trofi force-pushed the cc-wrappers-are-prefix-consistent branch from 7ce0308 to 02521bf Compare July 16, 2022 13:18
@ofborg ofborg bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Jul 16, 2022
@trofi
Copy link
Copy Markdown
Contributor Author

trofi commented Jul 16, 2022

@ofborg build stdenv

@trofi trofi marked this pull request as draft July 16, 2022 17:04
@trofi
Copy link
Copy Markdown
Contributor Author

trofi commented Jul 16, 2022

Switching to draft for now. cross-LLVM case uncovered some meson failure I don't quite understand:

$ nix build -L -f. pkgsLLVM.xorg.xorgproto

xorgproto-x86_64-unknown-linux-gnu> unpacking sources
xorgproto-x86_64-unknown-linux-gnu> unpacking source archive /nix/store/hpkjm7ljp5hxvy01clhw3p4hbjf41hqy-xorgproto-2021.5.tar.bz2
xorgproto-x86_64-unknown-linux-gnu> source root is xorgproto-2021.5
xorgproto-x86_64-unknown-linux-gnu> setting SOURCE_DATE_EPOCH to timestamp 1631721475 of file xorgproto-2021.5/test-driver
xorgproto-x86_64-unknown-linux-gnu> patching sources
xorgproto-x86_64-unknown-linux-gnu> configuring
xorgproto-x86_64-unknown-linux-gnu> meson flags: --buildtype=plain         --libdir=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5/lib --libexecdir=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5/libexec         --bindir=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5/bin --sbindir=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5/sbin         --includedir=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5/include         --mandir=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5/share/man --infodir=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5/share/info         --localedir=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5/share/locale         -Dauto_features=enabled         -Dwrap_mode=nodownload         --prefix=/nix/store/flm7h4nsbng4qqmzkdapllxjzjkp991n-xorgproto-x86_64-unknown-linux-gnu-2021.5 --cross-file=/nix/store/093qxaclmqgya1mfwip3qy3hv8lkqgbl-cross-file.conf -Dlegacy=true
xorgproto-x86_64-unknown-linux-gnu> The Meson build system
xorgproto-x86_64-unknown-linux-gnu> Version: 0.61.2
xorgproto-x86_64-unknown-linux-gnu> Source dir: /build/xorgproto-2021.5
xorgproto-x86_64-unknown-linux-gnu> Build dir: /build/xorgproto-2021.5/build
xorgproto-x86_64-unknown-linux-gnu> Build type: cross build
xorgproto-x86_64-unknown-linux-gnu> Project name: xorgproto
xorgproto-x86_64-unknown-linux-gnu> Project version: 2021.5
xorgproto-x86_64-unknown-linux-gnu> C compiler for the host machine: x86_64-unknown-linux-gnu-clang (clang 13.0.1 "clang version 13.0.1")
xorgproto-x86_64-unknown-linux-gnu> C linker for the host machine: x86_64-unknown-linux-gnu-clang ld.lld 13.0.1
xorgproto-x86_64-unknown-linux-gnu> C compiler for the build machine: clang (clang 13.0.1 "clang version 13.0.1")
xorgproto-x86_64-unknown-linux-gnu> C linker for the build machine: clang ld.lld 13.0.1
xorgproto-x86_64-unknown-linux-gnu> meson.build:22:0: ERROR: Unknown linker(s): [['llvm-ar'], ['ar'], ['gar']]
xorgproto-x86_64-unknown-linux-gnu> The following exception(s) were encountered:
xorgproto-x86_64-unknown-linux-gnu> Running "llvm-ar --version" gave "[Errno 2] No such file or directory: 'llvm-ar'"
xorgproto-x86_64-unknown-linux-gnu> Running "ar --version" gave "[Errno 2] No such file or directory: 'ar'"
xorgproto-x86_64-unknown-linux-gnu> Running "gar --version" gave "[Errno 2] No such file or directory: 'gar'"
xorgproto-x86_64-unknown-linux-gnu> A full log can be found at /build/xorgproto-2021.5/build/meson-logs/meson-log.txt

@trofi
Copy link
Copy Markdown
Contributor Author

trofi commented Jul 16, 2022

I think it uncovers already existing discrepancy:

$ nix develop -i -f. pkgsLLVM.xorg.xorgproto
bash-5.1$ dev>printf "int main(){}" | gcc -x c - -o a

bash-5.1$ dev>printf "int main(){}" | x86_64-unknown-linux-gnu-clang -x c - -o a

bash-5.1$ dev>printf "int main(){}" | clang -x c - -o a
x86_64-unknown-linux-gnu-ld: error: cannot open crt1.o: No such file or directory
x86_64-unknown-linux-gnu-ld: error: cannot open crti.o: No such file or directory
x86_64-unknown-linux-gnu-ld: error: cannot open crtbegin.o: No such file or directory
x86_64-unknown-linux-gnu-ld: error: unable to find library -lgcc
x86_64-unknown-linux-gnu-ld: error: unable to find library -lgcc_s
x86_64-unknown-linux-gnu-ld: error: unable to find library -lgcc
x86_64-unknown-linux-gnu-ld: error: unable to find library -lgcc_s
x86_64-unknown-linux-gnu-ld: error: cannot open crtend.o: No such file or directory
x86_64-unknown-linux-gnu-ld: error: cannot open crtn.o: No such file or directory
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

@trofi
Copy link
Copy Markdown
Contributor Author

trofi commented Jul 16, 2022

meson fails now because clang used to be non-working executable and meson assumed CC_FOR_BUILD is not present. But now clang works, but meson wants llvm-ar (and what not) for it. Basically, we export too much from a wrapped for cross-compiler.

I'll try another attempt: reexport everything needed from wrapper without re-exporting unwrapped compiler PATHs.

@trofi
Copy link
Copy Markdown
Contributor Author

trofi commented Jul 30, 2022

binutils did the similar thing in #182385

@trofi
Copy link
Copy Markdown
Contributor Author

trofi commented Sep 15, 2022

We'll probably follow binutils path.

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

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant