Commit Graph

146 Commits

Author SHA1 Message Date
Andrew Kelley
a3a8a266ef add missing clang and llvm library listings 2024-09-19 18:20:21 -07:00
Alex Rønne Petersen
dd095e506a cmake: Update to LLVM 19.
Co-authored-by: David Rubin <daviru007@icloud.com>
2024-09-19 18:20:20 -07:00
Forest
cf939b096a cmake: CLANG_LIBRARIES: find libclang-cpp.so.18.1
This fixes the failure to find CLANG_LIBRARIES on debian, which packages
the relevant .so file at these paths:

libclang-cpp18: /usr/lib/llvm-18/lib/libclang-cpp.so.18.1
libclang-cpp18: /usr/lib/x86_64-linux-gnu/libclang-cpp.so.18.1
libclang-cpp18: /usr/lib/x86_64-linux-gnu/libclang-cpp.so.18

(The latter two paths are symlinks to the first.)
2024-08-17 13:15:32 -07:00
Erik Arvstedt
c40708a2ce cmake/findllvm: fix incorrect lib dir setup for zig2
Line `link_directories("${CMAKE_PREFIX_PATH}/lib")` was evaluated as
`link_directories("/lib")` in the default case of `CMAKE_PREFIX_PATH`
being empty.
This caused cmake to add `-L/lib -Wl,-rpath,/lib` to the zig2
build flags.

This could result in errors on systems where libraries set via
`CMAKE_LIBRARY_PATH` had conflicting versions in `/lib`:
- `-L/lib` could cause linking zig2 to fail
- `-Wl,-rpath,/lib` adds `/lib` as the first entry of the zig2 `RPATH`.
  This could cause running zig2 (to build zig3) to fail.

In case of conflicting lib dirs, cmake emitted this warning, which is
now fixed:
```
Cannot generate a safe runtime search path for target zig2 because files in
  some directories may conflict with libraries in implicit directories:

    runtime library [libclang-cpp.so.18.1] in /nix/store/...-clang-18.1.5-lib/lib may be hidden by files in:
      /lib
```
2024-07-06 14:29:03 -04:00
Andrew Kelley
793f820b39 Revert "cmake/llvm: Don't unset LLVM_CONFIG_EXE"
This reverts commit 28476a5ee9.

It also adds a comment to explain the purpose of this line, to prevent
this mistake from being repeated.
2024-05-25 09:04:52 -07:00
Ridai Govinda Pombo
28476a5ee9 cmake/llvm: Don't unset LLVM_CONFIG_EXE 2024-05-20 17:36:07 -04:00
Eric Joldasov
1e785984b0
CMake: try to fix CI failures
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-05-15 15:37:12 +05:00
Eric Joldasov
b59c722a3f
CMake: clean CMAKE_{SOURCE,BUILD}_DIR
Replace `CMAKE_SOURCE_DIR` and `CMAKE_BUILD_DIR` with different variables,
or in some cases just remove them.

For some function arguments, prepended `CMAKE_SOURCE_DIR` was removed without
replacement. This includes:
 * Sources for `add_library` and `add_executable` (`ZIG_CPP_SOURCES` and `ZIG_WASM2C_SOURCES`)
 * Inputs for `configure_file` and `target_include_directory`
 * For arguments above, CMake already prepends
   `CMAKE_CURRENT_SOURCE_DIR` to them by default, if they are relative paths.
   Additionaly, it was removed from arguments of commands that have `WORKING_DIRECTORY` set to
   `PROJECT_SOURCE_DIR`, they will be similarly converted by CMake for us.

Also:
 * Move project declaration to the top so that these variables are
available earlier.
 * Avoid calling "git" executable if ".git" directory does not exist.
 * Swap "--prefix" and `ZIG_BUILD_ARGS` arguments in cmake/install.cmake
   to match same "zig2 build" command in CMakeLists.txt and allow
   overriding "--prefix" argument

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-05-14 23:40:41 +05:00
Eric Joldasov
c2ad0220e0
CMake: remove C/C++ flags override for static executable
They were introduced in https://github.com/ziglang/zig/pull/3467 and
5b51f41cee , and become obsolete since
C++-based compiler was removed: all C or C++ sources built by CMake
are just intermediate steps in bootstrapping.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-05-14 23:40:41 +05:00
Andrew Kelley
376387c390 add missing clang static library to the build 2024-05-08 19:37:28 -07:00
Andrew Kelley
3ac8d37182 update CMake files to LLVM 18 2024-05-08 19:37:28 -07:00
Andrew Kelley
78e95e1062 update LLVM static library list to 17
release/17.x branch, commit 8f4dd44097c9ae25dd203d5ac87f3b48f854bba8
2023-09-19 09:37:32 -07:00
Andrew Kelley
3882ce4f4b update cmake files to LLVM 17 2023-09-19 09:37:26 -07:00
Andrew Kelley
d20d69b59e update Findllvm.cmake static lib list to LLVM 16 2023-01-29 20:11:14 -07:00
Andrew Kelley
9c3bd437e6 update cmake files to LLVM 16 2023-01-25 20:26:14 -07:00
Andrew Kelley
c28c38d1e5
Merge pull request #13514 from kcbanner/windows_build_fixes
Windows: Support building stage3, and bootstrapping via MSVC
2023-01-05 17:26:32 -07:00
Eric Joldasov
fe2bd9dda8 cmake: move 'continue' statement to avoid cmake bug 2023-01-05 02:23:17 -07:00
kcbanner
3cacbea95b build: simplify llvm-config provided system library parsing
- Revert the addition of CLANG_SYSTEM_LIBARIES and LLVM_SYSTEM_LIBRARIES
- Change addCMakeLibraryList to parse non-absolute path .lib dependencies as system libraries
2023-01-04 21:45:06 -05:00
kcbanner
0471eea0e2 build: first pass on geting stage3 building under x64_64-windows-msvc 2023-01-04 21:45:05 -05:00
kcbanner
4ffc2bbb5e cmake: handle llvm system libraries separately from the llvm libraries themselves, to fix path issues on windows 2023-01-04 21:45:05 -05:00
Andrew Kelley
b1207b3293 Revert "cmake: check llvm-config in separate function"
This reverts commit 55c3efcb58.

This caused a regression when building Zig with Homebrew.
Also I don't like that it prints a message on success. Only when there
is a problem should an error message be printed.

closes #14093
2022-12-27 19:21:33 -07:00
Eric Joldasov
55c3efcb58 cmake: check llvm-config in separate function 2022-12-27 13:53:46 -05:00
Andrew Kelley
caddbbc315 build: avoid compiling self-hosted twice
build.zig: add a 'compile' step to compile the self-hosted compiler
without installing it.
Compilation: set cache mode to whole when using the LLVM backend and
--enable-cache is passed.

This makes `zig build` act the same as it does with stage1. Upside is
that a second invocation of `zig build` on an unmodified source tree
will avoid redoing the compilation again. Downside is that it will
proliferate more garbage in the project-local cache (same as stage1).

This can eventually be fixed when Zig's incremental compilation is more
robust; we can go back to having LLVM use CacheMode.incremental and rely
on it detecting no changes and avoiding doing the flush() step.
2022-10-18 16:52:43 -07:00
Eric Joldasov
1013212697 cmake: separate installing and building (again) 2022-10-18 16:52:43 -07:00
Andrew Kelley
de7270028d Merge remote-tracking branch 'origin/master' into llvm15 2022-08-29 14:10:59 -07:00
Andrew Kelley
56129d26eb cmake: build stage3 by default
This is a simplification of the cmake build script which introduces a
new "stage3" target that is built by default, which builds and installs
a stage3 zig.

It greatly simplifies the build instructions for Zig, making it conform
to the regular cmake routine, while still producing a stage3 artifact.
2022-08-28 17:07:21 -07:00
Andrew Kelley
dfecd819ce build: add new clang libraries for LLVM 15 upgrade 2022-08-02 17:22:16 -07:00
Andrew Kelley
129bd4e9c3 update LLVM library list to LLVM 15 2022-08-02 16:57:32 -07:00
Andrew Kelley
d46446e4df Merge remote-tracking branch 'origin/master' into llvm15 2022-07-31 15:55:44 -07:00
sin-ack
b35490c217 cmake: Print all LLVM config errors instead of just the last one
If you have multiple llvm-config executables in your path, and all of
them cause failures, then only the last failure will be printed. This
can cause confusion when the multiple llvm-config executables are from
different major LLVM versions, i.e. LLVM 13 and 14, which might mask an
error that happened on the LLVM 14 llvm-config with an unrelated error.

This commit makes it so that all errors are collected into a list and
printed all at once; this way, you can see how each llvm-config
executable failed to configure properly. Note that the failures still
won't be printed if a successful configuration is found.
2022-07-31 12:56:00 -07:00
Andrew Kelley
adb4a95302 update to LLVM 15
release/15.x 37007475ca1b345b4c5d340e228bcd7a62732d81
2022-07-28 11:53:25 -07:00
Cody Tapscott
abc1ae538f CMake: Search for Clang in CMAKE_LIBRARY_PATH, CMAKE_PREFIX_PATH, and CMAKE_FRAMEWORK_PATH
On some systems (esp. systems that use unique hashed file-paths for
library-versions like Nix), we can't expect LLVM and Clang to share
lib/bin directories.

The best we can do is find the matching clang libraries in the
CMAKE_LIBRARY_PATH provided by the environment
2022-07-25 10:38:52 -07:00
Cody Tapscott
4113a790b0 CMake: Search more permissively for LLD
This change relaxes the restriction added in the prior commit that LLD
should be alongside LLVM.

This also leaves unresolved the issue of making sure the link mode
(static or shared) of LLD matches that of LLVM/Clang. That would be an
unfortunate restriction, since LLD seems to be provided only as a static
lib on some distros.
2022-07-23 08:55:56 -07:00
Cody Tapscott
3f640ef3d2 CMake: Improve usage of llvm-config, esp. for consistent linking
This commit reworks the LLVM/Clang/LLD discovery process for CMake. The
biggest changes are that:
  1. We search for LLVM from most preferred directory to least, skipping
     any `llvm-config` that is the wrong version, or that doesn't
     support the requested link mode ("static" or "shared").
  2. `ZIG_PREFER_CLANG_CPP_DYLIB` has been renamed to `ZIG_SHARED_LLVM`,
     to better align with `ZIG_STATIC_LLVM`.
  3. We only search for LLVM in the same directory alongside LLVM.
  4. LLVM's link mode is forwarded to Clang, so that we can look for the
     appropriate shared/static libraries.
  5. We use `--link-static` when querying `--system-libs` from llvm-config,
     so that this will include libz and other dependencies for
     statically linking LLD
2022-07-23 08:52:30 -07:00
Cody Tapscott
dd70336f3a CMake: Use NAMES_PER_DIR in all lookups
CMake has a surprising default behavior where looking up a library by
multiple names gives the name order higher priority than the directory
search order.

For example, if your system provides "llvm-config-14" and
CMAKE_PREFIX_PATH includes "llvm-config", CMake will always end up
choosing the system-provided llvm-config-14.

This change add NAMES_PER_DIR to request the more sensible behavior:
directory search order has higher priority than name order, so
CMAKE_PREFIX_PATH always wins over system-provided tools/libraries.
2022-07-14 22:18:10 -04:00
Andrew Kelley
15bdba410a update build scripts to LLD and LLVM 14 libraries 2022-07-03 18:41:43 -07:00
Andrew Kelley
ae0b0729fc LLD: there are fewer libraries to link against now 2022-07-01 22:13:12 -07:00
Andrew Kelley
c89dd15e1b Merge remote-tracking branch 'origin/master' into llvm14 2022-07-01 15:52:54 -07:00
Isaac Freund
49a7ceb5bc cmake: add /usr/lib/llvm13 to searched paths
Alpine linux installs llvm to this path and currently patches zig's
cmake file in order to build zig from source.

https://git.alpinelinux.org/aports/tree/testing/zig/llvm-include.patch?id=0c3f7850bef38fb4c63fc6af5c14724e5311b0cc
2022-05-05 02:51:48 -04:00
Andrew Kelley
25a7025613 ci: use zig-bootstrap for windows 2022-02-16 18:43:45 -07:00
Kazuki Sakamoto
64f7231f86 stage1: Fix missing LLD library 2022-02-04 01:45:44 -05:00
Andrew Kelley
308f72701a update cmake files to LLVM 14 2022-02-03 13:38:48 -07:00
Andrew Kelley
0f35a1f37a fix the list of llvm libraries
not sure what "HelloNew" was doing in there
2021-09-30 23:33:03 -07:00
Andrew Kelley
f3ebfcae38 Merge remote-tracking branch 'origin/master' into llvm13
Conflicts:

 * cmake/Findclang.cmake
 * cmake/Findlld.cmake
 * cmake/Findllvm.cmake

In master branch, more search paths were added to these files with "12"
in the path. In this commit I updated them to "13".

 * src/stage1/codegen.cpp
 * src/zig_llvm.cpp
 * src/zig_llvm.h

In master branch, ZigLLVMBuildCmpXchg is improved to add
`is_single_threaded`. However, the LLVM 13 C API has this already, and
in the llvm13 branch, ZigLLVMBuildCmpXchg is deleted in favor of the C
API. In this commit I updated stage2 to use the LLVM 13 C API rather
than depending on an improved ZigLLVMBuildCmpXchg.

Additionally, src/target.zig largestAtomicBits needed to be updated to
include the new m68k ISA.
2021-09-15 14:51:08 -07:00
FnControlOption
23c25c5eaf cmake: also check Homebrew install paths when looking for LLVM
- On Intel Macs, the path is /usr/local/opt/llvm@12
- On Silicon Macs, the path is /opt/homebrew/opt/llvm@12

This makes specifying CMAKE_PREFIX_PATH optional for Homebrew LLVM.
2021-09-08 13:48:16 -04:00
Andrew Kelley
78ff2a148a cmake: update to LLVM 13 rc1
More precisely, aac4fe380d16a957627af2d6e5110ee35ad7e7e7 which is the
current tip of release/13.x.

Immediately following commits are tracking the same LLVM version.
2021-08-15 17:48:37 -07:00
Jakub Konka
0e15205521 Remove mention of lldMachO from the project
including:
* finding lldMachO in CMake config
* punting `ld64.lld` to LLD linker
* providing bindings to LLD linker
2021-06-29 23:38:19 +02:00
Andrew Kelley
a4316d5505 Merge remote-tracking branch 'origin/master' into llvm12 2021-03-13 14:35:03 -07:00
Andrew Kelley
4e9894cfc4 cmake build: allow overriding whether to use llvm-config
Previously, there was an option ZIG_PREFER_LLVM_CONFIG which would
override the default of not using llvm-config when cross compiling.

That option is now removed in favor of the more powerful
ZIG_USE_LLVM_CONFIG which defaults to OFF for cross compiling and ON for
native compilation. The option overrides the default.

This will be used in zig-bootstrap to improve support for native builds.
2021-03-13 14:30:56 -07:00
Timon Kruiper
939f334221 cmake: update findllvm.cmake file to include llvm12 libraries 2021-03-01 12:51:25 -08:00