Commit Graph

243 Commits

Author SHA1 Message Date
Sergei Trofimovich
4bdbae5ad1 cc-wrapper: wrap cpp for cross lust like to native
Without this change $target-cpp is used unwrapped and is missing
standard header search paths among other things).

Example failure:

    $ nix build -f. -L pkgsStatic.netbsd.compat
    ...
       > checking how to run the C preprocessor... x86_64-unknown-linux-musl-cpp
       > configure: error: in `/build/cvs-export/tools/compat':
       > configure: error: C preprocessor "x86_64-unknown-linux-musl-cpp" fails sanity check
       > See `config.log' for more details
2023-03-17 16:42:52 +00:00
Adam Joseph
6b6c06e5d7 cc-wrapper: allow non-clang compilers to use gccForLibs codepath
cc-wrapper has essentially two separate codepaths: the `gccForLibs`
codepath, used only by non-gcc (i.e. clang) compilers, and the
"other" codepath.

This PR allows non-clang compilers to opt-in to the `gccForLibs`
codepath (off by default).  To allow this, a new parameter
`ccForLibs` is exposed, since it would be extremely confusing for
gcc to be able to use `gccForLibs` but not do so by default.
2023-02-20 23:03:44 -08:00
Felix Buehler
cdb39a86e0 treewide: use optionalString 2023-02-13 21:52:34 +01:00
Sergei Trofimovich
6b832b5332 build-support/cc-wrapper: revert "pass in non-existent --sysroot= to untangle from libc"
This reverts commit 8c80bd08b7
("build-support/cc-wrapper: pass in non-existent --sysroot= to untangle
from libc").

This change was good in spirit: we caught a few genuine problems with
`scons` based packages (`godot`, `fluxus`) and unexpected `-idirafter`
includes in various boot loadres (`ipxe`, wimboot`):

    https://github.com/NixOS/nixpkgs/pull/210004#issuecomment-1407162693

Unfortunately `--sysroot=` also has a negative impact on libary search
order for DT_NEEDED libraries and RUNPATHs of linked libraries. This
unexpectedly broke `dmd`, `d-seams`, `llvmPackages_rocm.compiler-rt`).

An interesting case of unexpected breakage is `usbmuxd2` where the bug
exposed incomplete library move on `libstdc++fs` in `gcc`.

The library breakage is very non-intuitive (on top of already unusual
layout of `cc-wrapper` driver). Let's revert this change for now.

Once it lands we can undo `--sysroot=/` workarounds merged for
`staging-next`.
2023-01-29 07:49:37 +00:00
Sergei Trofimovich
4763533cca build-support/cc-wrapper: add libstdc++fs into default library path for clang
After https://github.com/NixOS/nixpkgs/pull/210004 `usbmuxd2` started
failing to build as:

    usbmuxd2-unstable> .../ld: cannot find -lstdc++fs: No such file or directory
    usbmuxd2-unstable> clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

This started happening because #210004 exposed a long-standing bug in
`gcc` derivation: `cc.lib` is missing `libstdc++fs` library:

    $ find $(nix-build --no-link -A stdenv.cc.cc.lib) | fgrep libstdc | unnix

    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++fs.la

    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++.la
    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++.so.6.0.29
    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++.so
    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++.so.6

It was not moved from `cc.out` output:

    $ find $(nix-build --no-link -A stdenv.cc.cc) | fgrep libstdc | unnix
    /<<NIX>>/gcc-11.3.0/lib/libstdc++.a
    /<<NIX>>/gcc-11.3.0/lib/libstdc++fs.a

This change adds `cc` library lookup path back to `staging-next` until
`gcc` is fixed.`
2023-01-28 07:30:33 +00:00
github-actions[bot]
c47e4b69a3
Merge master into staging-next 2023-01-25 00:02:20 +00:00
Alyssa Ross
2ae30c9f45 llvmPackages: use libcxxrt on FreeBSD
FreeBSD doesn't use LLVM's cxxabi implementation, for backwards
compatibility reasons.  Software expects the libcxxrt API when
building on FreeBSD.  This fixes the build of
pkgsCross.x86_64-freebsd.boost.
2023-01-24 21:18:39 +00:00
Sergei Trofimovich
b9b1d958d0 Merge remote-tracking branch 'origin/staging-next' into staging
Conflicts:
	pkgs/development/libraries/qt-6/modules/qtbase.nix
	pkgs/stdenv/linux/make-bootstrap-tools.nix
2023-01-20 21:56:57 +00:00
Yureka
7a05f9de7d
gccgo: wrap go binary (#207670) 2023-01-20 14:31:54 +01:00
Sergei Trofimovich
ca4da963f8 Merge remote-tracking branch 'origin/staging-next' into staging
Conflicts:
    pkgs/development/libraries/audio/roc-toolkit/default.nix
2023-01-14 11:07:42 +00:00
Sergei Trofimovich
67a3a14f24
Merge pull request #210004 from trofi/cc-fake-sysroot
build-support/cc-wrapper: pass in non-existent --sysroot= to untangle…
2023-01-14 08:18:56 +00:00
github-actions[bot]
49722fd14a
Merge master into staging-next 2023-01-13 18:01:34 +00:00
Vladimír Čunát
befc83905c
Merge #209423: gnat12: add for x86_64-darwin 2023-01-13 18:32:21 +01:00
Martin Weinelt
c1e6c6af69 Merge remote-tracking branch 'origin/master' into staging-next 2023-01-11 03:51:33 +01:00
Adam Joseph
dfa3f14493 cc-wrapper: -march= is not allowed on powerpc
Gcc does not allow `-march=` on PowerPC:

  https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/RS_002f6000-and-PowerPC-Options.html#RS_002f6000-and-PowerPC-Options

Instead, `-mcpu=` should be used to set the minimum instruction set
and `-mtune=` is used to optimize instruction scheduling for a
specific processor.  Both flags take the same set of valid values,
which includes `native`.

This commit causes `isGccArchSupported` to return `false` for PowerPC
targets so we never pass an `-march=` flag, since that will always be
rejected by gcc.
2023-01-10 14:05:03 +01:00
Sergei Trofimovich
8c80bd08b7 build-support/cc-wrapper: pass in non-existent --sysroot= to untangle from libc
I would like to add an extra `gcc` build step during linux bootstrap
(https://github.com/NixOS/nixpkgs/issues/208412). This makes it early
bootstrap compiler linked and targeted against `bootstrapTools` `glibc`
including it's headers.

Without this change `gcc`'s spec files always prefer `bootstrapTools` `glibc`
for header search path (passed in as --with-native-system-header-dir=). We'can't
override it with:

- `-I` option as it gets stacked before gcc-specific headers, we need to keep
  glibc headers after gcc as gcc cleans namespace up for C standard by using
  #include_next and by undefining system macros.
- `-idirafter` option as it gets appended after existing `glibc`-includes

This `--sysroot=/nix/store/does/not/exist` hack allows us to remove existing
`glibc` headers and add new ones with `-idirafter`.

We use `cc-cflags-before` instead of `libc-cflags` to allow user to define
their own `--sysroot=` (like `firefox` does).

To keep it working prerequisite cross-symlink in gcc.libs is required:
https://github.com/NixOS/nixpkgs/pull/209153
2023-01-10 07:54:13 +00:00
Boey Maun Suang
a584587bea cc-wrapper: Wrap/link all other GNAT commands 2023-01-07 18:32:12 +11:00
Boey Maun Suang
c1308ac58c cc-wrapper: Fix gnatmake wrapper
Switches that gnatmake needs to pass to gcc must be given as
"-cargs <gcc_switches>" after at least the files to compile (see the
gnatmake docs for all the subtleties).  This commit makes that happen,
in a way that triggers rebuilds only for things that actually depend on
GNAT, and not the other compilers contained in GCC.
2023-01-07 18:32:12 +11:00
Artturin
adc8900df1 treewide: fix some core package structuredAttrs 2022-12-08 21:05:28 +02:00
Artturin
734d7df235 allow derivation attributes in env
derivations can be coerced to their output paths
2022-12-08 06:13:19 +02:00
Nick Cao
994deb2bf1 cc-wrapper: fix path to libcxx includes for cross compilers 2022-11-30 18:46:16 +01:00
Vladimír Čunát
6890557c17
Revert "Merge #191724: cc-wrapper: remove duplicate include flags"
Let's redo this later, with more testing and less bugs.
This reverts commits 4f6e99870b and d700d8e8a2.
2022-10-28 10:28:12 +02:00
Vladimír Čunát
d700d8e8a2
stdenv cc-wrapper: revert a problematic change for non-Linux
The change from 0bea4a194f (PR #191724) broke stdenv bootstap
on *-darwin, and I didn't want to drop the *-linux binaries
that we have already.
2022-10-14 09:40:48 +02:00
github-actions[bot]
efe19ddf3b
Merge staging-next into staging 2022-08-25 18:01:48 +00:00
Minijackson
bec06f5bba
cc-wrapper: disable stackprotector for MicroBlaze
This option doesn't seem to be supported in the cross-compiler
2022-08-25 16:00:49 +02:00
Theodore Ni
1f6366d38c
cc-wrapper: fortran: enable stackprotector on M1
Was failing due to https://github.com/iains/gcc-darwin-arm64/issues/54,
fix picked up in https://github.com/NixOS/nixpkgs/pull/186477.
2022-08-19 16:41:36 -07:00
github-actions[bot]
67f5b5a85d
Merge staging-next into staging 2022-08-08 18:02:11 +00:00
adisbladis
5cc12aa8cb
Merge pull request #182187 from adisbladis/newlib-nano-cc
newlib-nano: Set same flags as regular newlib in cc-wrapper/gcc config
2022-08-08 22:07:57 +08:00
Sergei Trofimovich
549e08c8e8 bintools-wrapper, cc-wrapper: avoid invalid export of 'expand-response-params'
POSIX sh (and `bash`) impose a restriction on environment variable name
format and disallow hypheps in the names. Normally it's not a problem
as nothing usually tries to refer nyphenated names.

One exception is `nix develop` (https://github.com/NixOS/nix/issues/6848):

    $ nix develop -f. gcc -L
    gcc-wrapper> ...-get-env.sh: line 70: expand-response-params: bad substitution

Note that bash usually uses explicitly created `expandResponseParams`
variant of the same variable.

To work the problem around let's avoid environment variable export and move
it to `passthru` for `cc` (used ina  few places) and remove it completely for
`binutils` (does not seem to be used at all).
2022-07-31 16:31:13 +01:00
Vladimír Čunát
5b5843e2b2
Merge #151983: wrapper: Fortran: disable stackprotector
...hardening on darwin aarch64 (merge into staging)
2022-07-29 19:27:34 +02:00
adisbladis
d5fb429c7d cc-wrapper: Set correct hardening_unsupported_flags for newlib-nano 2022-07-20 16:41:48 +08:00
Semion Nadezhdin
b060076e21 cc-wrapper: broaden explicit libc++abi linking for LLVM stdenv 2022-07-13 21:19:12 +03:00
John Ericson
e23e71f9e4
Merge pull request #176152 from mmlb/cc-wrapper-allow-target-override
cc-wrapper: Allow user to override -target for clang
2022-06-15 15:09:27 -04:00
Manuel Mendez
0fdc72b7e9 cc-wrapper: Add clang specific options to clang specific file
This way gcc doesn't need to be rebuilt because of clang. This also avoids
rebuilding clang when only the wrapper needs to be tweaked.
2022-06-15 11:34:53 -04:00
Manuel Mendez
19b6ccd9ac cc-wrapper: Allow for override of -target for clang/clang++
This enables users to make use of clang's multi-platform/target support
without having to go through full cross system setup. This is especially useful
for generating bpf object files, I'm not even usre what would a no-userland
cross compile system tuple even look like to even try going that route.

Fixes #176128
2022-06-09 16:57:15 -04:00
FliegendeWurst
7b185e04a9 cc-wrapper: Fortran: disable format hardening
Otherwise, these warnings are emitted:
command-line option '-Wformat=1' is valid for C/C++/ObjC/ObjC++ but not for Fortran
command-line option '-Wformat-security' is valid for C/C++/ObjC/ObjC++ but not for Fortran
'-Werror=' argument '-Werror=format-security' is not valid for Fortran

Fixes part of #27218
2022-05-26 12:29:35 +02:00
Artturin
1d44ac176c treewide: add enableParallelBuilding's to bootstrap packages so hashes stay the same
when enableParallelBuildingByDefault is enabled

verified with
`nix-diff $(nix eval ".#gcc-unwrapped.drvPath") $(nix eval --expr 'with import ./. { config = { enableParallelBuildingByDefault = true; }; }; gcc-unwrapped.drvPath' --impure)`
2022-05-25 16:03:14 +03:00
Janne Heß
c911240e9c
Revert "Add mingwW64-llvm cross-system." 2022-05-18 13:50:23 +02:00
Shea Levy
0f68ed163c
Merge branch 'mingwW64-clang' into staging 2022-05-18 06:30:21 -04:00
Shea Levy
078a07708a
libunwind: Fix build against compiler-rt-using clang 2022-05-09 10:05:47 -04:00
Shea Levy
4b503b2a58
cc-wrapper: clang doesn't support -fPIC on Windows 2022-05-06 10:54:52 -04:00
Emery Hemingway
89a0dd2414 wrapCCWith: structured argument for wrapper flags
Take a "nixSupport" argument that is an attrset of lists to append
to "$out/nix-support/${name}" where name is the name of the
attribute. This attrset is available from the passthru of the
wrapped compiler.

This is an alternative to imperatively issuing flags with
extraBuildCommands and makes it possible to append or filter
flags with an override.
2022-04-30 21:21:41 -05:00
Doron Behar
2cc754a7ba cc-wrapper: Fortran: disable stackprotector hardening on darwin aarch64 2022-04-16 11:11:26 +03:00
John Ericson
d3407f1a3b cc-wrapper: Add support for -mthumb / -marm 2021-09-17 17:12:54 +00:00
Shea Levy
9ecfbe0c5b
mingw: Disalbe FORTIFY_SOURCE by default.
In newer versions of mingw, programs compiled with FORTIFY_SOURCE need
to link to libssp or they will have link-time errors.

gmp has been broken since @pstn updated mingw-64 in c60a0b0447
2021-08-11 05:07:42 -04:00
sternenseemann
c3c4ef859a gprbuild, xmlada: init at 21.0.0
GPRbuild is a multi language build system developed by AdaCore which
is mostly used for build Ada-related projects using GNAT.

Since GPRbuild is used to build itself and its dependency library
XML/Ada we first build a bootstrap version of it using the provided
bash build script bootstrap.sh as the gprbuild-boot derivation.
gprbuild-boot is then used to build xmlada and the proper gprbuild
derivation.

GPRbuild has its own search path mechanism via GPR_PROJECT_PATH which
we address via a setupHook. It currently works quite similar to the
pkg-config one: It accumulates all inputs into GPR_PROJECT_PATH,
GPR_PROJECT_PATH_FOR_BUILD etc. However this is quite limited at the
moment as we don't have a gprbuild wrapper yet which understands the
_FOR_BUILD suffix. However, we'll need to address this in the future
as it is currently basically impossible to test since the distinction
only affects cross-compilation, but it is not possible to build a GNAT
cross-compiler in nixpkgs at the moment (I'm working on changing that,
however).

Another issue we had to solve was GPRbuild not finding the right GNAT
via its gprconfig tool: GPRbuild has a knowledge base with compiler
definitions which run some checks and collect info about binaries
which are in PATH. In the end the first compiler in PATH that supports
the desired language is selected.

We want GPRbuild to discover our wrapped GNAT since the unwrapped one
is incapable of producing working binaries since it won't find the
crt*.o objects distributed with libc. GPRbuild however needs to find
the Ada runtime distributed with GNAT which is not part of the wrapper
derivation, so it will skip the wrapper and select the unwrapped GNAT.
Symlinking the unwrapped's lib directory into the wrapper fixes this
problem, but breaks linking in some cases (e. g. when linking against
OMP from gcc, the runtime variant will shadow the problem dynamic lib
from buildInputs). Additionally it uses gnatls as an indicator it has
found GNAT which is not part of the wrapper.

The solution we opted to adopt here is to install a custom compiler
description into gprbuild's knowledge base which properly detects the
nixpkgs GNAT wrapper: It uses gnatmake to detect GNAT instead of
gnatls and discovers the runtime via a symlink we add to
`$out/nix-support`. This additional definition is enough to properly
detect GNAT, since the plain wrapped gcc detection works out of the
box. It may, however, be necessary to add special definitions for
other languages in the future where gprbuild also needs to discover
the runtime.

One future improvement would be to install libgpr into a separate
output or split it into a separate derivation (which would require to
link gprbuild statically always since otherwise we end up with a
cyclical dependency).
2021-08-03 14:58:49 +02:00
John Ericson
18c38f8aee treewide: All the linker to be chosen independently
This will begin the process of breaking up the `useLLVM` monolith. That
is good in general, but I hope will be good for NetBSD and Darwin in
particular.

Co-authored-by: sterni <sternenseemann@systemli.org>
2021-05-14 21:29:51 +00:00
John Ericson
912c8262b4
Merge pull request #117591 from s1341/android_non_prebuilt
treewide: Support aarch64-android using minimal prebuilt components
2021-05-11 12:49:53 -04:00
s1341
1e1d29c2af treewide: Support aarch64-android using minimal prebuilt components
This PR adds a new aarch64 android toolchain, which leverages the
existing crossSystem infrastructure and LLVM builders to generate a
working toolchain with minimal prebuilt components.

The only thing that is prebuilt is the bionic libc. This is because it
is practically impossible to compile bionic outside of an AOSP tree. I
tried and failed, braver souls may prevail. For now I just grab the
relevant binaries from https://android.googlesource.com/.

I also grab the msm kernel sources from there to generate headers. I've
included a minor patch to the existing kernel-headers derivation in
order to expose an internal function.

Everything else, from binutils up, is using stock code. Many thanks to
@Ericson2314 for his help on this, and for building such a powerful
system in the first place!

One motivation for this is to be able to build a toolchain which will
work on an aarch64 linux machine. To my knowledge, there is no existing
toolchain for an aarch64-linux builder and an aarch64-android target.
2021-05-11 15:39:08 +00:00
Vladimír Čunát
8eabe2ecc5
Merge #115235: gcc: native aarch64-darwin support 2021-05-11 12:12:04 +02:00