Commit Graph

68 Commits

Author SHA1 Message Date
Wolfgang Walther
91a8fee3aa treewide: remove redundant parentheses
Auto-fixed by nixf-diagnose.
2025-10-05 10:52:03 +02:00
Luna
1f46266191 llvmPackages.libclang: add enableClangToolsExtra flag
rocmPackages needs a clang at runtime but has no need to include
clang-tidy.

The approach in this change avoids rebuilds and is messy, I will
make a followup in staging that changes this to more idiomatic
optionalString usage if this is merged
2025-09-25 18:45:39 -07:00
Emily
2dac87bbde llvmPackages_17: drop 2025-09-14 19:03:24 +01:00
Emily
a892ce396d llvmPackages_16: drop 2025-09-14 19:03:24 +01:00
Emily
77acbe1f9c llvmPackages_15: drop 2025-09-14 19:03:24 +01:00
Emily
f470ea24b6 llvmPackages_14: drop 2025-09-14 19:03:24 +01:00
Emily
791fe23b63 llvmPackages_13: drop 2025-09-14 19:03:24 +01:00
Emily
c3c8a4a05d llvmPackages: remove obsolete version conditionals 2025-09-14 19:03:24 +01:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Peter Collingbourne
8dc663ea18 llvmPackages.clang: embed resource directory in Clang libraries
When Clang is statically linked against other programs they are unable to
find the headers in Clang's resource directory. Typically the resource
directory is found by searching a path relative to argv[0] but this
would only really work for Clang itself due to each binary having a
separate prefix (and not in Nix because of the full resource directory
being split between multiple derivations and assembled in the wrapper).

Because users of Clang as a library typically only need include in order
for parsing to succeed, let's set that as the resource directory. The LLVM
patch to make this work was sent upstream in llvm/llvm-project#145996,
I intend to land it upstream and drop it from this PR.
2025-07-02 10:19:33 +02:00
K900
3b9cc44907 llvmPackages.clang: only build debug info on 64-bit compilers
32-bit compilers cannot handle this and explode.
2025-06-09 20:28:11 +03:00
Alyssa Ross
929e918a51 llvmPackages.clang-unwrapped: enable debug info
This increases the memory required to link by quite a bit, but it
should be fine for Hydra, and people building themselves with
insufficient RAM can either disable it, or just decrease --cores.
2025-05-31 16:18:43 +02:00
Robert Scott
3f1a00c79d cc-wrapper: add support for strictflexarrays1 & strictflexarrays3 hardening flags
adding strictflexarrays1 to pkgsExtraHardening
2025-05-24 11:10:20 +01:00
nixpkgs-ci[bot]
0e76d45697 Merge staging-next into staging 2025-04-30 18:06:31 +00:00
Silvan Mosberger
bc2b4e77d8 llvmPackages: add comments for all patches in LLVM and CLang
Co-Authored-By: Silvan Mosberger <silvan.mosberger@moduscreate.com>
2025-04-30 11:55:26 +04:00
Peter Waller
8eed584a6d llvmPackages.{clang,mlir}: Mark big-parallel
Mark these packages as big-parallel to match llvmPackages.llvm.

They are chosen because they are relatively expensive to build, as
opposed to others where I currently believe they are less of an issue
from a CPU time/memory standpoint.

I suspect most people don't care about big-parallel or it would have
been noticed earlier. I have a use case where I am building many
variants of clang all at once and I want to avoid OOM by constraining
the number of parallel builds of items marked big-parallel.

Signed-off-by: Peter Waller <p@pwaller.net>
2025-04-28 22:48:48 +01:00
Tristan Ross
c599ce6eb7 llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: nixfmt 2025-03-30 19:07:03 +02:00
Tristan Ross
dffb86fd08 llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: no toplevel let 2025-03-30 19:07:03 +02:00
Tristan Ross
e3c3b5611b llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: drop rec 2025-03-30 19:07:03 +02:00
Tristan Ross
8ba1fdd4d0 llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: condense 2025-03-30 19:07:03 +02:00
Tristan Ross
f9de5019a8 llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: move pname 2025-03-30 19:07:03 +02:00
Tristan Ross
0d8556f352 llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: move env 2025-03-30 19:07:03 +02:00
Tristan Ross
bd63121c71 llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: move src 2025-03-30 19:07:03 +02:00
Tristan Ross
a5267c9945 llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: use lib.cmake functions 2025-03-30 19:07:03 +02:00
zvolin
1ab394e053 llvmPackages_17.{clang,tblgen}: fix builds on aarch64 2025-03-09 11:53:33 +01:00
Tristan Ross
e85abae0ae llvmPackages_{12,13,14,15,16,17,18,19,20,git}.clang: move patches out of common 2025-03-07 14:15:33 +01:00
Peter Waller
9676ba5756 llvmPackages.clang: Drop failing substituteInPlace for CompletionModel.cmake
Fix up #356120 for clang 12. The failing replacement target was removed
between llvm 12.0.0 and 12.0.1.

Ref: https://github.com/NixOS/nixpkgs/pull/348568#discussion_r1894533619
Ref: 3be5dbbc32
Signed-off-by: Peter Waller <p@pwaller.net>
2024-12-22 16:51:56 +01:00
Philip Taron
bbbe3d4ddc llvmPackages: remove _IMPORT_PREFIX replacements
These strings do not show up in the files where they are attempting to be replaced.
2024-12-17 16:41:57 -08:00
github-actions[bot]
17dc04d068 Merge staging-next into staging 2024-12-17 12:06:41 +00:00
K900
293d08b05f Merge remote-tracking branch 'origin/master' into staging-next 2024-12-17 09:46:26 +03:00
Tristan Ross
ba1deff5ad llvmPackages.*: Expose git rev through pkg.src.rev (#354792) 2024-12-16 19:38:25 -08:00
Peter Waller
269fdda927 llvmPackages: sed -i 's/--replace /--replace-fail /g'
Rationale: --replace is deprecated and emits warnings. If these
replacements fail it is probably better to know about it early and come
up with better fixes than the alternative of letting them silently fail
and discover some distal brokenness.

Signed-off-by: Peter Waller <p@pwaller.net>
2024-12-15 16:20:01 +00:00
Peter Waller
59331c3a17 llvmPackages: Split tablegen into its own derivation
Background:

LLVM has some tools that run at build time. In native builds, these are
built as a part of the usual build, but in cross builds they need to
come from buildPackages.

In many scenarios this is a small problem because LLVM from
buildPackages is already available as a build; but if cross building a
version of LLVM which is not available (e.g. a new git commit of LLVM)
this results in two builds of LLVM and clang, one native and one for the
cross.

Full builds of LLVM are expensive; and unnecessary in this scenario. We
don't need a native LLVM, only a native copy of the tools which run at
build time. This is only tablegen and related tooling, which are cheap
to build.

Implementation-wise, we introduce a derivation llvmPackages.tblgen,
which specifies the tablegen targets which need to be built and has a
custom installPhase to copy them to the output.

A previous attempt in https://github.com/NixOS/nixpkgs/pull/359967
dropped the use of LLVM_TABLEGEN_EXE and friends on the grounds that
llvm can already cross build these things, but that is false since it's
necessary in that case to wire in a cross compiler. This PR avoids that
problem by allowing access to buildPackages.tblgen.

Signed-off-by: Peter Waller <p@pwaller.net>
2024-12-11 20:55:03 +00:00
Philip Taron
246e737cca various: replace substituteAll with replaceVars (#360770) 2024-12-02 05:52:25 -08:00
Wolfgang Walther
217d3132cf various: remove unused substituteAll imports 2024-12-01 14:25:56 +01:00
sternenseemann
6309f13670 llvmPackages_12.clang: use nostdlibinc patch instead of sed command
Seems like the patch we've written for LLVM 13 and above also works for
LLVM 12 which seems a little more robust.

(cherry picked from commit 37437849de)
(cherry picked from commit f30f8ee969e6a395da091e7a8053e779b39686ff)
2024-11-30 15:11:10 +01:00
sternenseemann
f0f66c41d4 llvmPackages_12: build from monorepo source
As mentioned in #305146, keeping LLVM 12 is a source of pain because it
is the only version to be built from individual release tarball instead
of the LLVM monorepo. This commit makes LLVM 12 start from the monorepo
as well, simplifying all common LLVM expressions in the process.

With #347887, some quirks in the expressions for LLVM <14 were ironed
out, so building LLVM through from the monorepo is quite simple now.

- Most expressions only required minor changes, mostly removing the
  special casing for `sourceRoot`.

- The patch lists from llvm/12/default.nix were ported to
  common/default.nix. This only required a few extra conditionals which
  could be reduced via a rebuild also involving other LLVM versions.
  Outstanding tasks of little urgency have been noted in TODO comments.
  I have verified that the patch lists stay the same for all packages
  except LLVM where merely the order changes. An extra set of eyes
  is appreciated, of course.

- clang: The expression was reworked to use the same symlink location
  for clang-tools-extra for all versions including LLVM 12. This
  required adjusting the ad hoc patching of the clangd cmake files
  slightly.

- libunwind: We no longer need to make the libcxx sources available
  manually. We can rely on the monorepo source instead.

- lld: We no longer need to make the libunwind sources available manually.

- llvm: We no longer need to make the polly sources available manually

- On Darwin, we need to bypass CMake's C++ compiler for libcxx and
  libunwind now. It isn't a 100% clear why, probably because we've
  started to use Darwin's bootstrapStdenv for libcxx in the common
  expression compared to LLVM 12 on master [1].
  The reordering of flags for wasm causes a rebuild for some packages
  like firefox, but this should be tolerable on staging.

[1]: 665ebfb253/pkgs/development/compilers/llvm/12/default.nix (L392-L430)

(cherry picked from commit ee9eacf23e)
(cherry picked from commit c4e9f17ef944bb7ce0d3d1226d7f922f28e46b02)
2024-11-30 15:11:09 +01:00
Reno Dakota
1e3da684a3 llvmPackages.libclang{12,13,14,15,16}: ignore -nostd* flag when linking
apply
5b77e752dc
to clang 14-16 and backport the patch to apply to clang 12-13

backported patch just drops the final change in Hunk 2 of Options.td as
it doesn't exist until clang-14
2024-11-24 22:37:39 +00:00
Reno Dakota
f9a5549db2 llvmPackages{12-git}.clang: don't swallow unsupported option errors when compiling + linking
`https://github.com/llvm/llvm-project/issues/116278`

make clang report unsupported option errors / warning when compiling +
linking in the same command.

this works
```
$ clang --target=aarch64 -mpopcnt hello.c
clang: error: unsupported option '-mpopcnt' for target aarch64
```

before change clang swallows the error
```
$ clang --target=aarch64 -mpopcnt hello.c -lc
$ echo $?
0
```

after change error is reported:
```
$ clang --target=aarch64 -mpopcnt hello.c -lc
clang: error: unsupported option '-mpopcnt' for target aarch64
```
2024-11-20 02:33:34 +00:00
Emily
597a7ad587 llvmPackages.clang: move add-nostdlibinc-flag.patch to cc-wrapper (#356162) 2024-11-17 14:29:00 +00:00
Peter Waller
7047ba9ccb llvmPackages.clang: move add-nostdlibinc-flag.patch to cc-wrapper
Remove a patch to decrease the divergence from upstream.

Motivation is a continuation of trying to reduce the number of clang
builds floating around. Wrapper builds are cheap, compiler builds are
not.

It's expected that this patch can be removed at some point and replaced
with some other cc-wrapper logic. This will be a little bit easier with
the logic already in the cc-wrapper.

Ongoing discussion in #191152. It would be nice to drop this but we
think it's probably needed at least on systems where /usr/include may be
available to prevent the possibility of picking up unwanted includes.

One potential method for eliminating nostdlibinc in the future is by
providing a non-existent -sysroot but that was reverted in #213185, and
remains a can of worms.

Signed-off-by: Peter Waller <p@pwaller.net>
2024-11-15 15:48:50 +00:00
Peter Waller
cdefc40e99 llvmPackages.*: Expose git rev through pkg.src.rev
Also exposes owner, repo, and other attributes available on the original
monorepoSrc. These attributes were previously hidden behind a
runCommand that consumes monorepoSrc and hides this information away.

```
$ nix eval --raw .#llvmPackages_18.llvm.src.rev
llvmorg-18.1.8

$ nix eval --raw .#llvmPackages_git.llvm.src.rev
0e8555d4dbfdfeddc01dc2ecf9a9b6e804f7b645
```

Signed-off-by: Peter Waller <p@pwaller.net>
2024-11-09 15:12:56 +00:00
sternenseemann
37437849de llvmPackages_12.clang: use nostdlibinc patch instead of sed command
Seems like the patch we've written for LLVM 13 and above also works for
LLVM 12 which seems a little more robust.
2024-11-08 23:31:05 +01:00
sternenseemann
ee9eacf23e llvmPackages_12: build from monorepo source
As mentioned in #305146, keeping LLVM 12 is a source of pain because it
is the only version to be built from individual release tarball instead
of the LLVM monorepo. This commit makes LLVM 12 start from the monorepo
as well, simplifying all common LLVM expressions in the process.

With #347887, some quirks in the expressions for LLVM <14 were ironed
out, so building LLVM through from the monorepo is quite simple now.

- Most expressions only required minor changes, mostly removing the
  special casing for `sourceRoot`.

- The patch lists from llvm/12/default.nix were ported to
  common/default.nix. This only required a few extra conditionals which
  could be reduced via a rebuild also involving other LLVM versions.
  Outstanding tasks of little urgency have been noted in TODO comments.
  I have verified that the patch lists stay the same for all packages
  except LLVM where merely the order changes. An extra set of eyes
  is appreciated, of course.

- clang: The expression was reworked to use the same symlink location
  for clang-tools-extra for all versions including LLVM 12. This
  required adjusting the ad hoc patching of the clangd cmake files
  slightly.

- libunwind: We no longer need to make the libcxx sources available
  manually. We can rely on the monorepo source instead.

- lld: We no longer need to make the libunwind sources available manually.

- llvm: We no longer need to make the polly sources available manually

- On Darwin, we need to bypass CMake's C++ compiler for libcxx and
  libunwind now. It isn't a 100% clear why, probably because we've
  started to use Darwin's bootstrapStdenv for libcxx in the common
  expression compared to LLVM 12 on master [1].
  The reordering of flags for wasm causes a rebuild for some packages
  like firefox, but this should be tolerable on staging.

[1]: 665ebfb253/pkgs/development/compilers/llvm/12/default.nix (L392-L430)
2024-11-08 23:30:20 +01:00
github-actions[bot]
f3423cc412 Merge staging-next into staging 2024-10-30 00:14:51 +00:00
Peter Waller
9917c9705f llvmPackages.clang: Drop CLANG_DEFAULT_CXX_STDLIB
This is better handled in the cc-wrapper, and makes it possible to avoid
rebuilding clang in some scenarios.

It also appears to be unnecessary since the cc-wrapper already passes
-stdlib=libc++ where needed.

See: 8885a1e21a/pkgs/build-support/cc-wrapper/default.nix (L603)
Signed-off-by: Peter Waller <p@pwaller.net>
2024-10-27 15:25:04 +00:00
Emily
514b00cf08 clang: skip the -nostdlibinc patch on Darwin 2024-10-24 17:55:27 +01:00
sternenseemann
1d6675e530 llvmPackages_13: build from filtered monorepoSrc
This change implements a leftover task from #307211, namely passing
monorepoSrc to the different llvmPackages_13 package expressions. Before
this change, all packages llvmPackages_13 would be built from a
subdirectory of the full LLVM monorepo tree. After this change only the
relevant directories are made available at build time. This

- reduces the size of the source that needs to be made available to the
  builder.
- prevents LLVM from sidestepping our instructions and including extra
  sources from other directories it shouldn't.

Since LLVM 12 and 13 don't have the `cmake` directory at the top level,
the runCommand expressions filtering the source need to be adjusted, but
this causes no rebuild for any other LLVM version (ofborg should confirm
this).

The only problem encountered was in lld:

- We need to make the patch to the inclusion of libunwind headers
  unconditional now. lld needs this on non-darwin as well. In the
  full monorepo, LLVM_MAIN_SRC_DIR would be set correctly, so the
  patch wasn't necessary.
- The substitute mechanism for LLVM 12 and 13 can't be unified yet since
  LLVM 12 still uses a non monorepo build, so we come up with a
  different LLVM_MAIN_SRC_DIR.

Change was tested by building the following expression on x86_64-linux.

    with import ./. {};
    builtins.removeAttrs llvmPackages_13 [ "lldb" "lldbPlugins" ]'

lld was also tested on aarch64-darwin.
2024-10-14 12:15:32 +02:00
Tristan Ross
d55298086a llvmPackages_git: 20.0.0-git-2024-09-16 -> 20.0.0-git-2024-09-22 2024-09-25 06:59:58 -07:00
Peter Waller
290ec4e775 llvmPackages.*: Add devExtraCmakeFlags parameter
cmake flags have a 'last flag wins' logic, so by appending to the end of
the flags it is possible to override any cmake flag.

It also ignores (and warns) if a flag is unused, so passing flags across
all packages should be safe if you want to target one package.

In combination with #320261, this PR allows consistently overriding all
packages within LLVM with additional cmake arguments. Consistency here
means for example 'if you override LLVM, then all dependencies on it are
also see the overridden LLVM in their input'. Consistency is hard to
achieve with the other obvious way of implementing this as a user: if
you use overrideAttrs then you have to write a big mess of override code
in order to override all dependents, and this can be very difficult in a
cross-compilation scenario using crossSystem and useLLVM, for example.

With this PR it is possible to write an overlay which overlays
`llvmPackages` with `llvmPackage.override { devExtraCmakeFlags = [ ... ]; }`,
and then the toolchain used with useLLVM in effect should respect
these flags.

This is useful in development for experimenting with the effect of
various flags, hence the chosen name `devCmakeFlags`.

This won't work out of the box without #341855 applied, which fixes
override passthrough.

See-Also: #320261, #341855
Signed-off-by: Peter Waller <p@pwaller.net>
2024-09-15 11:50:52 +01:00