-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
235 lines (193 loc) · 9.28 KB
/
justfile
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
set unstable := true
set shell := ["bash", "-euo", "pipefail", "-c"]
set script-interpreter := ["bash", "-euo", "pipefail"]
# Turn on debug_mode if you want to `set -x` all the just [script] recipes
debug := "false"
# The version of the rust compiler to include.
# These versions are pinned by the `./nix/versions.nix`
# file (which is managed by `./scripts/bump.sh`)
rust := "stable"
container_repo := "ghcr.io/githedgehog/dpdk-sys"
# This is the maximum number of builds nix will start at a time.
# You can jump this up to 8 or 16 if you have a really powerful machine.
# Be careful tho, LLVM is a memory hog of a build.
max_nix_builds := "1"
# This is the path to the versions.nix file that contains the nixpkgs version information
# It is a safe bet that the current ./nix/versions.nix file is what you want unless you are
# trying to jump back in time to a previous version of nixpkgs or something.
versions := "./nix/versions.nix"
# semi private (override if you really need to)
# Setting this to "false" will disable pulling derivations from the nix cache.
# If you turn this to "false" with an empty /nix/store, then you will have to rebuild
# _everything_.
# The rebuild will be massive!
# On the other hand, setting this to "false" will allow you to test
# the reproducibility of the entire dependency graph.
#
# NOTE: if you already have packages cached they will still be used.
# You would need to clear out /nix/store to truly force a rebuild of everything.
nix_substitute := "true"
# private fields (do not override)
# The git tree state (clean or dirty)
_clean := ```
set -euo pipefail
(
git diff-index --quiet HEAD -- && \
test -z "$(git ls-files --exclude-standard --others)" && \
echo clean \
) || echo dirty
```
# The git commit hash of the last commit to HEAD
_commit := `git rev-parse HEAD`
# The git branch we are currnetly on
_branch := `git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9]/-/g'`
# The slug is the branch name (sanitized) with a marker if the tree is dirty
_slug := (if _clean == "clean" { "" } else { "dirty-_-" }) + _branch
# The name of the doc-env container
_doc_env_container_name := container_repo + "/doc-env"
# The name of the compile-env container
_compile_env_container_name := container_repo + "/compile-env"
_frr_container_name := container_repo + "/frr"
# This is a unique identifier for the build.
# We temporarily tag our containers with this id so that we can be certain that we are
# not retagging or pushing some other container.
_build-id := uuid()
_just_debug_ := if debug == "true" { "set -x" } else { "" }
_build_time := datetime_utc("%+")
# Compute the default number of jobs to use as a guess to try and keep the build within the memory limits
# of the system
cores := `./scripts/estimate-jobs.sh`
[private]
@default:
just --list --justfile {{ justfile() }}
# Install the nix package manager (in single user mode)
[script]
install-nix:
{{ _just_debug_ }}
sh <(curl -L https://nixos.org/nix/install) --no-daemon
[private]
[script]
_nix_build attribute:
{{ _just_debug_ }}
mkdir -p /tmp/dpdk-sys/builds
nix build \
--option substitute "{{ nix_substitute }}" \
--keep-failed \
--print-build-logs \
--show-trace \
-f default.nix \
"{{ attribute }}" \
--out-link "/tmp/dpdk-sys/builds/{{ attribute }}" \
--argstr onlyRunDeps false \
--argstr container-repo "{{ container_repo }}" \
--argstr image-tag "{{ _build-id }}" \
--argstr rust-channel "{{ rust }}" \
"-j{{ max_nix_builds }}" \
`if [ "{{ cores }}" != "all" ]; then echo --cores "{{ cores }}"; fi`
# Build the sysroot
build-sysroot: \
(_nix_build "sysroots") \
(_nix_build "env.sysroot.gnu64.dev") \
(_nix_build "env.sysroot.gnu64.release") \
(_nix_build "env.sysroot.musl64.dev") \
(_nix_build "env.sysroot.musl64.release") \
(_nix_build "sysroot")
# Build doc env packages
build-docEnvPackageList: (_nix_build "docEnvPackageList")
# Build FRR
build-frr-contents: (_nix_build "frrContainerContents")
# Builds and post processes a container from the nix build
[private]
[script]
_build-container target container-name: (_nix_build ("container." + target))
{{ _just_debug_ }}
declare build_date
build_date="$(date --utc --iso-8601=date --date="{{ _build_time }}")"
declare -r build_date
docker load --input /tmp/dpdk-sys/builds/container.{{ target }}
docker tag \
"{{ container-name }}:{{ _build-id }}" \
"{{ container-name }}:{{ _slug }}.rust-{{ rust }}"
docker tag \
"{{ container-name }}:{{ _build-id }}" \
"{{ container-name }}:{{ _commit }}.rust-{{ rust }}"
docker build \
--label "git.commit={{ _commit }}" \
--label "git.branch={{ _branch }}" \
--label "git.tree-state={{ _clean }}" \
--label "build.date=${build_date}" \
--label "build.timestamp={{ _build_time }}" \
--label "rust={{ rust }}" \
--label "rust.version=$(nix eval --raw -f '{{ versions }}' 'rust.{{ rust }}.version')" \
--label "rust.channel=$(nix eval --raw -f '{{ versions }}' 'rust.{{ rust }}.channel')" \
--label "rust.profile=$(nix eval --raw -f '{{ versions }}' 'rust.{{ rust }}.profile')" \
--label "rust.targets=$(nix eval --json -f '{{ versions }}' 'rust.{{ rust }}.targets')" \
--label "llvm.version=$(nix eval --raw -f '{{ versions }}' 'rust.{{ rust }}.llvm')" \
--label "nixpkgs.git.commit=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.commit')" \
--label "nixpkgs.git.branch=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.branch')" \
--label "nixpkgs.git.commit_date=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.commit_date')" \
--label "nixpkgs.git.source_url=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.source_url')" \
--label "nixpkgs.hash.nix32.packed.sha256=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.nix32.packed.sha256')" \
--label "nixpkgs.hash.nix32.packed.sha512=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.nix32.packed.sha512')" \
--label "nixpkgs.hash.nix32.unpacked.sha256=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.nix32.unpacked.sha256')" \
--label "nixpkgs.hash.tar.sha256=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.tar.sha256')" \
--label "nixpkgs.hash.tar.sha384=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.tar.sha384')" \
--label "nixpkgs.hash.tar.sha512=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.tar.sha512')" \
--label "nixpkgs.hash.tar.sha3_256=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.tar.sha3_256')" \
--label "nixpkgs.hash.tar.sha3_384=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.tar.sha3_384')" \
--label "nixpkgs.hash.tar.sha3_512=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.tar.sha3_512')" \
--label "nixpkgs.hash.tar.blake2b512=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.tar.blake2b512')" \
--label "nixpkgs.hash.tar.blake2s256=$(nix eval --raw -f '{{ versions }}' 'nixpkgs.hash.tar.blake2s256')" \
--label "versions.json=$(nix eval --json -f '{{ versions }}')" \
--build-arg IMAGE="{{ container-name }}:{{ _build-id }}" \
--tag "{{ container-name }}:post-{{ _build-id }}" \
--target {{ target }} \
-f Dockerfile \
.
docker tag \
"{{ container-name }}:post-{{ _build-id }}" \
"{{ container-name }}:{{ _slug }}.rust-{{ rust }}"
docker tag \
"{{ container-name }}:post-{{ _build-id }}" \
"{{ container-name }}:{{ _commit }}.rust-{{ rust }}"
docker rmi "{{ container-name }}:{{ _build-id }}"
docker rmi "{{ container-name }}:post-{{ _build-id }}"
# Build and tag the doc-env container
build-doc-env-container: build-docEnvPackageList (_build-container "doc-env" _doc_env_container_name)
# Build and tag the compile-env container
build-compile-env-container: build-sysroot (_build-container "compile-env" _compile_env_container_name)
# Build and tag the frr container
build-frr-container: build-frr-contents (_build-container "frr" _frr_container_name)
# Build the sysroot, and compile-env containers
build: build-sysroot build-frr-container build-compile-env-container build-doc-env-container
# Push the compile-env and doc-env containers to the container registry
[script]
push: build
{{ _just_debug_ }}
docker push "{{ _compile_env_container_name }}:{{ _slug }}.rust-{{ rust }}"
docker push "{{ _compile_env_container_name }}:{{ _commit }}.rust-{{ rust }}"
docker push "{{ _doc_env_container_name }}:{{ _slug }}.rust-{{ rust }}"
docker push "{{ _doc_env_container_name }}:{{ _commit }}.rust-{{ rust }}"
docker push "{{ _frr_container_name }}:{{ _slug }}.rust-{{ rust }}"
docker push "{{ _frr_container_name }}:{{ _commit }}.rust-{{ rust }}"
# Delete all the old generations of the nix store and run the garbage collector
[script]
nix-garbage-collector:
{{ _just_debug_ }}
nix-env --delete-generations old
nix-store --gc
# Generate the test matrix
[script]
generate-todo-list param=".":
{{ _just_debug_ }}
yq -r -c '[
{{ param }} as $matrix |
$matrix | keys as $factors |
[range(0; $factors | length)] as $itr |
$factors | map($matrix[.]) | combinations as $combinations |
$itr | map({($factors[.]): $combinations[.]}) | add
]' ./builds.yml
[script]
bump dpdk_sys_branch="main":
{{ _just_debug_ }}
./scripts/bump.sh {{ dpdk_sys_branch }}