252 Commits

Author SHA1 Message Date
David Spickett
3308fc4acd
[gn build] Use shutil.which to find git in write_vcsrevision.py (#142570)
Relates to https://github.com/llvm/llvm-project/issues/54337

This is just a comment referencing distutils but even so, we can ditch
the custom which and use the one Python 3.3 added. Which has the .bat
bug fixed:
https://docs.python.org/3.3/library/shutil.html#shutil.which

I tested this on Windows:
```
C:\Users\tcwg>touch foo.bat

C:\Users\tcwg>python
Python 3.11.9 (tags/v3.11.9:de54cf5, Apr  2 2024, 12:24:25) [MSC v.1938 64 bit (ARM64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.which("foo")
'.\\foo.BAT'
```

I just ran the script manually and got reasonable results, I haven't
done a GN build.
2025-07-28 10:55:19 +01:00
Arthur Eubanks
999b35629f
[gn build] Manually partially port #108276 (#149595)
Fixes windows gn clang build.

Don't worry about exporting clang symbols on windows in gn build for
now.
2025-07-22 10:19:02 -07:00
Dirk Pranke
333f2c3341
[gn] Use exec_script_allowlist in //llvm/utils/gn/.gn (#134172)
This requires gn_version >= 2207. Run llvm/utils/gn/get.py to
update your GN binary if you hit the assert added in this commit.
2025-04-08 22:33:07 -04:00
Peter Collingbourne
9222607227
gn build: Add check-builtins target.
Tested on aarch64 Linux and x86_64 Linux.

Reviewers: aeubanks, nico

Reviewed By: aeubanks

Pull Request: https://github.com/llvm/llvm-project/pull/134482
2025-04-07 13:22:52 -07:00
Nico Weber
e5c5e621e6 [gn] Make sync script sync .mm files too
Motivated by #129332, which added a new .mm file that didn't get
autosynced.
2025-03-06 21:09:10 -05:00
Arthur Eubanks
18952bdcd6
[gn build] Fix up win/x86 flags and add stage2_unix_x86 (#111595) 2024-10-09 09:18:59 -07:00
Nico Weber
4a2d24e814 [gn] Reformat build files
Ran:

    git ls-files '*.gn' '*.gni' | xargs llvm/utils/gn/gn.py format

No behavior change.
2024-09-24 20:22:36 -04:00
Arthur Eubanks
bea2f2511b
[gn build] Port win asan runtime rules (#108293)
Windows doesn't have a static runtime after #107899.
2024-09-12 10:11:40 -07:00
GkvJwa
128bb29e6d
[gn] Add "/Zc:preprocessor" build flag on windows when using cl.exe (#108252)
Add ```/Zc:preprocessor``` to fix the ```__VA_ARGS__``` expansion error 
encountered when building with gn and cl.exe(msvc)
2024-09-12 17:14:07 +08:00
Daniel Bertalan
5602bd5a42
[gn build] Bump macOS target to 12 and make it configurable (#107492)
Bumping the deployment target from macOS 10.10 to 12 enables chained
fixups and DWARF 4 debug information for the LLVM binaries and
libraries.
    
Like in Chromium, a GN arg (`mac_deployment_target`) is added to allow
overriding the default.
2024-09-06 10:10:25 +02:00
Nico Weber
f4d5b14dcc [gn] Give two scripts argparse.RawDescriptionHelpFormatter
Without this, the doc string is put in a single line. These
scripts have multi-line docstrings, so this makes their --help
output look much nicer.

Otherwise, no behavior change.
2024-08-09 11:10:12 -04:00
Nico Weber
7d9260948f [gn/mac] Fix isysroot flag when building compiler-rt
If the GN arg `sysroot` was set to a root-relative path like e.g.
`"//sysroot"`, we weren't rebasing it correctly, leading to
warnings from clang about it ignoring a non-existent sysroot.

Similar to 6073f87d7f160.
2024-06-19 12:54:07 -04:00
pcc
c852475f7a
gn build: Pass -fno-sanitize=vptr,function with use_ubsan
Matches CMake LLVM_UBSAN_FLAGS.

Reviewers: aeubanks

Reviewed By: aeubanks

Pull Request: https://github.com/llvm/llvm-project/pull/93911
2024-06-04 11:29:03 -07:00
pcc
303f140594
gn build: Support llvm_enable_zstd.
Reviewers: aeubanks

Reviewed By: aeubanks

Pull Request: https://github.com/llvm/llvm-project/pull/88457
2024-06-04 11:28:24 -07:00
Takuto Ikuta
31850fa974
[gn] remove goma configs (#93941)
goma is deprecated and not maintained anymore.
2024-06-04 07:36:52 -07:00
Aaron Siddhartha Mondal
852aaf5407
Reapply "[Support] Remove terminfo dependency (#92865)" (#93889)
This reverts commit fe82a3da36196157c0caa1ef2505186782f750d1.

This broke LLDB on MacOS due to a missing symbol during linking.

The fix has been applied in c6c08eee37bada190bd1aa4593c88a5e2c8cdaac.

Original commit message:

The terminfo dependency introduces a significant nonhermeticity into the
build. It doesn't respect `--no-undefined-version` meaning that it's not
a dependency that can be built with Clang 17+. This forces maintainers
of source-based distributions to implement patches or ignore linker
errors.

Remove it to reduce the closure size and improve portability of
LLVM-based tools. Users can still use command line arguments to toggle
color support expliticly.

Fixes #75490
Closes #53294 #23355
2024-05-31 01:29:00 +02:00
Michael Buch
fe82a3da36 Revert "[Support] Remove terminfo dependency (#92865)"
This reverts commit 6bf450c7a60fa62c642e39836566da94bb9bbc91.

It breaks LLDB CI: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/4762/execution/node/97/log/

```
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -Wdocumentation -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -mmacosx-version-min=14.1 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-dead_strip -Wl,-no_warn_duplicate_libraries tools/lldb/unittests/Editline/CMakeFiles/EditlineTests.dir/EditlineTest.cpp.o -o tools/lldb/unittests/Editline/EditlineTests  lib/libLLVMSupport.a  lib/libllvm_gtest_main.a  lib/libllvm_gtest.a  lib/liblldbHost.a  lib/liblldbUtility.a  lib/libLLVMTestingSupport.a  /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/libxml2.tbd  /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/libedit.tbd  lib/liblldbHostMacOSXObjCXX.a  lib/liblldbUtility.a  -framework Foundation  -framework CoreFoundation  -framework CoreServices  -framework Security  lib/libLLVMObject.a  lib/libLLVMIRReader.a  lib/libLLVMBitReader.a  lib/libLLVMAsmParser.a  lib/libLLVMCore.a  lib/libLLVMRemarks.a  lib/libLLVMBitstreamReader.a  lib/libLLVMMCParser.a  lib/libLLVMMC.a  lib/libLLVMDebugInfoCodeView.a  lib/libLLVMTextAPI.a  lib/libLLVMBinaryFormat.a  lib/libLLVMTargetParser.a  lib/libllvm_gtest.a  lib/libLLVMSupport.a  -lm  /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/libz.tbd  /opt/homebrew/lib/libzstd.dylib  lib/libLLVMDemangle.a  -lpthread && cd /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/unittests/Editline && /opt/homebrew/Cellar/cmake/3.28.3/bin/cmake -E make_directory /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/unittests/Editline/./Inputs
ld: Undefined symbols:
  _setupterm, referenced from:
      lldb_private::Editline::Editline(char const*, __sFILE*, __sFILE*, __sFILE*, std::__1::recursive_mutex&) in liblldbHost.a[35](Editline.cpp.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
2024-05-29 16:20:42 +01:00
Aaron Siddhartha Mondal
6bf450c7a6
[Support] Remove terminfo dependency (#92865)
The terminfo dependency introduces a significant nonhermeticity into the
build. It doesn't respect `--no-undefined-version` meaning that it's not
a dependency that can be built with Clang 17+. This forces maintainers
of source-based distributions to implement patches or ignore linker
errors.

Remove it to reduce the closure size and improve portability of
LLVM-based tools. Users can still use command line arguments to toggle
color support expliticly.

Fixes #75490
Closes #53294 #23355
2024-05-24 20:20:15 +02:00
Nico Weber
82811a8f50 [gn] fix minor mistake from f7cb1afa0633
The script printed two `/` when one suffices.
2024-01-17 06:43:22 -08:00
Nico Weber
f7cb1afa06 [gn] Make sync script print github URLs
Phab no longer knows about new revisions.
2024-01-09 10:58:23 -05:00
Arthur Eubanks
e02b85bef7
[gn build] Add a generic compiler_wrapper gn arg (#72757)
Since goma is going away soon, we need to experiment with other
wrappers.

We can clean up the goma stuff once it's fully non-functional.
2023-11-21 09:25:07 -08:00
Arthur Eubanks
2041611931 [gn build] Force clang_enable_per_target_runtime_dir for Android builds
Since it doesn't work yet.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D157901
2023-08-17 11:09:03 -07:00
Peter Collingbourne
1978482537 gn build: Fix Android build.
Remove --unwindlib=none flag that was added by D143598. It is required
to not pass this flag when linking binaries. With this flag, linking
e.g. llvm-symbolizer will fail.

There was a missing dependency from most targets to the implicitly linked
libraries (libunwind and builtins), which was causing the build for those
targets to fail when they were built on their own. I never noticed this
because I always build the implicitly linked libraries together with
their dependencies. Make the dependency explicit by introducing a new
target //llvm/utils/gn/build/libs/implicit representing the platform's
implicitly linked libraries, and depend on that from the LLVM libraries,
so that "normal" binaries like llvm-symbolizer will have all of their
dependencies available.

D143598 set the arch subdirectory to i686 for Android. However, the arch
subdirectory on Android is i386, and has been for a long time.

$ find android-ndk-r* -name i386
android-ndk-r18b/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/7.0.2/lib/linux/i386
android-ndk-r19/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.2/lib/linux/i386
android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/lib/linux/i386
android-ndk-r21-beta1/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/lib/linux/i386
android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/lib/linux/i386
android-ndk-r22/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/11.0.5/lib/linux/i386
android-ndk-r23-beta5/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/12.0.5/lib/linux/i386
android-ndk-r24/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/i386
android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7/lib/linux/i386

Using the wrong name prevents Clang from being able to find libunwind.a on
x86. Fix the code to use i386 as the arch subdirectory, consistent with
the NDK.

Bring back -Wl,-z,defs which was removed for Android by D143598, presumably
because of the missing unwind library.

Differential Revision: https://reviews.llvm.org/D146266
2023-08-01 17:41:21 -07:00
Leonard Grey
5e763d35e4 [gn] Add check-lsan target for Mac
Only supports ASAN mode right now. Standalone requires a some more plumbing so it will be a follow-up.

Mac-only but I suspect this will be fine on Linux also since it's based on the check-asan file, will follow up after testing.

Differential Revision: https://reviews.llvm.org/D153651
2023-07-06 13:03:16 -04:00
Tobias Hieta
b71edfaa4e
[NFC][Py Reformat] Reformat python files in llvm
This is the first commit in a series that will reformat
all the python files in the LLVM repository.

Reformatting is done with `black`.

See more information here:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, JDevlieghere, MatzeB

Differential Revision: https://reviews.llvm.org/D150545
2023-05-17 10:48:52 +02:00
Nico Weber
3cce68c2b3 [gn] Unbreak sync_source_lists_from_cmake on mac after Xcode update
Apparently `\b` stopped working with --pickaxe-regex for some reason.
2023-05-02 20:05:38 -04:00
Peter Collingbourne
659da71a40 gn build: Pass -fno-emulated-tls when targeting Android.
Matches the CMake build:
93c1a5f3dd/compiler-rt/CMakeLists.txt (L343)
(we always use API level 29).

Differential Revision: https://reviews.llvm.org/D146341
2023-03-17 17:28:40 -07:00
Arthur Eubanks
998ad085e8 Reland [gn build] Support linux/win compiler-rt cross compilation
Differential Revision: https://reviews.llvm.org/D143545
2023-02-17 09:58:28 -08:00
Arthur Eubanks
7a035de2d6 Revert "[gn build] Support linux/win compiler-rt cross compilation"
This reverts commit d73eb92cc673acf532b396537d78fe041dc9a9c2.

Breaks win/mac, e.g. http://45.33.8.238/win/75236/step_4.txt
2023-02-17 09:56:51 -08:00
Arthur Eubanks
d73eb92cc6 [gn build] Support linux/win compiler-rt cross compilation
Differential Revision: https://reviews.llvm.org/D143545
2023-02-17 09:33:28 -08:00
Arthur Eubanks
c8399811e7 [gn build] Support building x86/64 Android libraries
Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D143598
2023-02-17 09:18:38 -08:00
Arthur Eubanks
4089c28370 [gn build] Remove --rtlib=libgcc for Android builds
Recent Android NDKs don't ship with libgcc
2023-01-10 15:12:49 -08:00
Nico Weber
6bb781fa9a [gn build] Add build files for //bolt
Adds build files for libraries, tools, and tests -- everything except
the runtime.

Doesn't hook up bolt in the main BUILD.gn file yet -- I want to verify
that it builds on Linux, macOS, Windows before doing that. (I've only
checked on macOS so far.)

`ninja check-bolt` passes on macOS with this.
(I locally bumped the deployment target to macOS 10.12 for that. bolt/ uses
std::mutex quite a bit, which requires 10.12.)

Differential Revision: https://reviews.llvm.org/D138355
2022-11-21 19:45:54 -05:00
Nico Weber
20b0e0a71a [gn build] Stop defining GTEST_LANG_CXX11, pass /Zc:__cplusplus with msvc
Ports:
* https://reviews.llvm.org/D84023
* https://reviews.llvm.org/rG4f5ccc72f6a6e
  (but see https://reviews.llvm.org/rG4901199f5b84b223)

No intended behavior change.
2022-11-15 10:56:53 -05:00
Nico Weber
532c206141 [gn build] Reformat all build files
Ran:

    git ls-files '*.gn' '*.gni' | xargs llvm/utils/gn/gn.py format
2022-10-11 11:04:43 -04:00
Zequan Wu
08d4d7cb8d [gn build] port a3172df59c32 (check-lldb)
https://reviews.llvm.org/rGa3172df59c32aac48c113eb7d6a1324aaa95c474 breaks
check-lldb gn build.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D133604
2022-09-13 10:52:56 -07:00
Nico Weber
d299c033e6 [gn build] Make it possible to do PGO-optimized builds
This is fairly manual for now.

Differential Revision: https://reviews.llvm.org/D131710
2022-08-11 18:39:46 -04:00
Nico Weber
c59c8a515f [gn build] port b1356504e63ae better (c++17) 2022-08-06 07:54:43 -04:00
Nico Weber
51a91d6c5d [gn build] port b1356504e63ae (c++17) 2022-08-06 07:51:06 -04:00
Nico Weber
a9b21ec484 [gn build] tweak how symbol_exports map files look on linux, for 94c00c10e
After bc39d7bdd497 (ported to GN in 94c00c10e), libclang uses symbol_exports,
and clang/test/LibClang/symbols.test wants the versioned name to be `LLVM_[0-9]$`
instead of `FOO`.
2022-07-26 01:52:00 -04:00
Nico Weber
b2998143a7 [gn build/mac] Use -mmacos-version-min instead of -mmacosx-version-min
The two flags do the same thing, but the OS is called macOS these days.

(The new flag is 5 years old: https://reviews.llvm.org/D32796)

No behavior change.
2022-07-07 23:56:37 +02:00
Nico Weber
52554f7315 [gn build] Allow use_ubsan=true on mac and unbreak use_asan, use_tsan, use_ubsan
`use_ubsan=true` seems to Just Work on macOS, so allow it.

https://reviews.llvm.org/D122862 broke use_asan=true, use_tsan=true, and
use_ubsan=true builds on Linux too. This makes this go again by explicitly
disabling asan, tsan, and ubsan for the baremetal part of the build. See
discussion on https://reviews.llvm.org/D122862 for other possible approaches.

Differential Revision: https://reviews.llvm.org/D127906
2022-06-15 19:34:35 -04:00
Nico Weber
0083a02839 [gn build] Slighly nicer gn args --list output for is_debug and symbol_level 2022-06-15 19:24:32 -04:00
Nico Weber
ceef00d33d [gn build] (manually) port 6bc8163c79fd 2022-06-10 06:26:31 -04:00
Nico Weber
7ed089153c [gn build] port f06abbb39380 a bit (create main() functions for GENERATE_DRIVER targets) 2022-06-06 06:28:52 -04:00
Nico Weber
10f7255d32 [gn build] Extract compiled_action.gni from tablegen.gni
After years of tablegen being the only host binary we run as part
of the build, we're now in the process of growing at least two more:
- make_confusable_table (https://reviews.llvm.org/rG180bae08a04d)
- pseudo-gen (not yet fully hooked up in the GN build, but I have
  a local branch that hooks it up)

Factor out the few lines we need for running a host binary as part of the
build.

No behavior change.

Differential Revision: https://reviews.llvm.org/D126963
2022-06-03 10:22:15 -04:00
Reid Kleckner
17296607a7 Revert "[Bazel][GN] Reuse the GN LLVM config file generation code"
This reverts commit e2ee8bf9818189b900e65d6ea8f1ae6fc75455ce.

This change is beyond my ability to integrate into Google's internal
build configuration tonight.
2022-05-31 21:15:46 -07:00
Reid Kleckner
e2ee8bf981 [Bazel][GN] Reuse the GN LLVM config file generation code
Currently, the Bazel build uses static, checked in [llvm-]config.h files
in combination with global macro definitions to mimic CMake's generated
headers. This change reuses the write_cmake_config.py script from the GN
build to generate the headers from source in the same way. The purpose
is to ensure that the Bazel build stays up to date with any changes to
the CMake config files. The write_cmake_config.py script has good error
checking to ensure that unneeded, stale variables are not passed, and
that any missing variables are reported as errors.

I tried to closely follow the logic in the GN build here:
  llvm/utils/gn/secondary/llvm/include/Config/BUILD.gn
The duplication between this file and config.bzl is significant, and we
could consider going further, but I'd like to hold off on it for now.

The GN build changes are to move the write_cmake_config.py script up to
//llvm/utils/write_cmake_config.py, and update the paths accordingly.

The next logical change is to generate Clang's config.h header.

Differential Revision: https://reviews.llvm.org/D126581
2022-05-31 19:40:05 -07:00
Arthur Eubanks
f37e6faf52 [gn build] Use llvm-ar when clang_base_path is specified
Only applies linux for now.

This prevents warnings with use_thinlto like
  bfd plugin: LLVM gold plugin has failed to create LTO module: Not an int attribute (Producer: 'LLVM15.0.0git' Reader: 'LLVM 13.0.1')

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D125399
2022-05-11 10:40:54 -07:00
Nico Weber
2ac876c52c [gn build] Fix a URL in a comment 2022-04-12 11:38:12 -04:00