-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage.sh
78 lines (63 loc) · 3.3 KB
/
usage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
# 1. Build Zig from src (manually)
# Start the dev shell
nix develop
# You can now follow the build instructions from the Wiki
# https://github.com/ziglang/zig/wiki/Building-Zig-From-Source
#―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
# 2. Build Zig from src (with ./run)
# ./run is an opinionated script that helps with building and testing Zig.
./run --help
# It accepts these env vars:
# - src (default: /tmp/zig-src)
# - build_dir (default: /tmp/zig-build)
#
# You might want to use a wrapper script that sets these variables, like so:
install -m755 <(echo '#!/usr/bin/env bash
export src=<Your Zig src>
export build_dir=<Your build dir>
. /path/to/nix-zig-build/run.sh "$@"') ~/bin/zb
## 2.1 Clone Zig repo
git clone https://github.com/ziglang/zig /tmp/zig-src
## 2.2
# Note: All ./run functions used here are idempotent.
# Build Zig from source (with optimize=ReleaseFast), using only a C compiler.
# This cmd automatically runs within the dev shell.
./run buildBootstrap
# Run Zig created by `buildBootstrap`
./run 'eval $build_dir/stage3/bin/zig help'
# Alternatively, use a pre-built, signature-checked Zig release binary from ziglang.org.
# This is much faster than running a bootstrap build.
./run usePrebuilt
# Run Zig created by `usePrebuilt`
./run 'eval $build_dir/stage3/bin/zig help'
## 2.3
# Build Zig from source (with optimize=Debug), using the Zig binary created in step 2.2.
# After changing the src, rebuilding with `buildDebug` is much faster than `buildBootstrap`.
./run buildDebug
# Run Zig created by `zig-debug`
./run 'eval $build_dir/zig-debug/bin/zig help'
## 2.4 Run tests using the Zig binary created by `buildDebug`
./run testStdlibFast
./run testBehavior
./run testBehavior --verbose # Print Zig build cmds
./run testBehaviorFast
./run zigSrc build --help # Show Zig build options for the Zig repo
# For more cmds, see the src of ./run
#―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
# 3. Build the Zig pkgs
# Built from source
nix build --no-link --print-out-paths -L
# Prebuilt static binary from ziglang.org
nix build --no-link --print-out-paths -L .#zigPrebuilt
#―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
# 4. Build Zig as a statically linked executable
# This requires musl and is best achieved using zig-bootstrap.
git clone --depth 1 https://github.com/ziglang/zig-bootstrap /tmp/zig-bootstrap
# Enter bootstrap shell
nix shell .#bootstrapEnv
cd /tmp/zig-bootstrap
export CMAKE_GENERATOR=Ninja
./build x86_64-linux-musl baseline
# Run Zig
/tmp/zig-bootstrap/out/zig-x86_64-linux-musl-baseline/zig help