Skip to content

Use cmake --build instead of makefiles #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,31 @@ For other versions, check the git tags of this repository.
* C++ compiler capable of building LLVM, Clang, and LLD from source (GCC 5.1+
or Clang)
* cmake 3.19 or later
* make
* make, ninja, or any other build system supported by cmake
* POSIX system (bash, mkdir, cd)
* Python 3

## Build Instructions

```
./build -j1 <arch>-<os>-<abi> baseline
./build <arch>-<os>-<abi> baseline
```

All parameters are required:

* `-j1`: Replace with your jobs parameter to make.
* `<arch>-<os>-<abi>`: Replace with one of the Supported Triples below, or use
`native` for the `<arch>` value (e.g. `native-linux-gnu`) to use the native
architecture.
* `baseline`: Replace with a `-mcpu` parameter of Zig. `baseline` means
it will target a generic CPU for the target. `native` means it will target
the native CPU. See the Zig documentation for more details.

To use a non-default cmake generator, export the `CMAKE_GENERATOR` environment
variable before calling `build`.

If you aren't using a build system that builds in parallel by default (ie. make),
export `CMAKE_BUILD_PARALLEL_LEVEL` to parallelize the build.

If it succeeds, the output will be in `out/zig-triple-mcpu/`.

### Supported Triples
Expand Down
19 changes: 9 additions & 10 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

set -eu

JOBS="$1"
TARGET="$2" # Example: riscv64-linux-gnu
MCPU="$3" # Examples: `baseline`, `native`, `generic+v7a`, or `arm1176jzf_s`
TARGET="$1" # Example: riscv64-linux-gnu
MCPU="$2" # Examples: `baseline`, `native`, `generic+v7a`, or `arm1176jzf_s`

ROOTDIR="$(pwd)"
ZIG_VERSION="0.11.0-dev.78+28288dcbb"
Expand Down Expand Up @@ -41,7 +40,7 @@ cmake "$ROOTDIR/llvm" \
-DCLANG_INCLUDE_DOCS=OFF \
-DLLVM_INCLUDE_DOCS=OFF \
-DCMAKE_BUILD_TYPE=Release
make "$JOBS" install
cmake --build . --target install

# Now we build Zig, still with system C/C++ compiler, linking against LLVM,
# Clang, LLD we just built from source.
Expand All @@ -52,7 +51,7 @@ cmake "$ROOTDIR/zig" \
-DCMAKE_PREFIX_PATH="$ROOTDIR/out/host" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_VERSION="$ZIG_VERSION"
make "$JOBS" install
cmake --build . --target install

# Now we have Zig as a cross compiler.
ZIG="$ROOTDIR/out/host/bin/zig"
Expand All @@ -73,7 +72,7 @@ cmake "$ROOTDIR/zlib" \
-DCMAKE_RC_COMPILER="$ROOTDIR/out/host/bin/llvm-rc" \
-DCMAKE_AR="$ROOTDIR/out/host/bin/llvm-ar" \
-DCMAKE_RANLIB="$ROOTDIR/out/host/bin/llvm-ranlib"
make "$JOBS" install
cmake --build . --target install

# Same deal for zstd.
# The build system for zstd is whack so I just put all the files here.
Expand Down Expand Up @@ -161,13 +160,13 @@ cmake "$ROOTDIR/llvm" \
-DLIBCLANG_BUILD_STATIC=ON \
-DLLVM_DEFAULT_TARGET_TRIPLE="$TARGET"
cd "$ROOTDIR/out/build-llvm-$TARGET-$MCPU/tools/lld"
make "$JOBS" install
cmake --build . --target install
cd "$ROOTDIR/out/build-llvm-$TARGET-$MCPU/tools/clang/lib"
make "$JOBS" install
cmake --build . --target install
cd "$ROOTDIR/out/build-llvm-$TARGET-$MCPU/lib"
make "$JOBS" install
cmake --build . --target install
cd "$ROOTDIR/out/build-llvm-$TARGET-$MCPU"
make "$JOBS" install-llvm-headers install-clang-headers install-LLVMSupport install-LLVMDemangle
cmake --build . --target install-llvm-headers install-clang-headers install-LLVMSupport install-LLVMDemangle

# Finally, we can cross compile Zig itself, with Zig.
cd "$ROOTDIR/zig"
Expand Down