Skip to content

Commit d68999b

Browse files
feat: update WORKSPACE example for new flow
1 parent 29c63be commit d68999b

File tree

4 files changed

+73
-29
lines changed

4 files changed

+73
-29
lines changed

README.md

+39-24
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,25 @@ http_archive(
5050
],
5151
)
5252
53-
load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")
53+
load("@hermetic_cc_toolchain//toolchain:defs.bzl", host_zig_toolchain, zig_toolchains = "toolchains")
54+
55+
_COMMON_EXEC_PLATFORMS = [
56+
("linux", "amd64"),
57+
("linux", "arm64"),
58+
("windows", "amd64"),
59+
("macos", "arm64"),
60+
("macos", "amd64"),
61+
]
5462
5563
# Plain zig_toolchains() will pick reasonable defaults. See
5664
# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and
5765
# download URL.
58-
zig_toolchains()
66+
[zig_toolchains(
67+
exec_arch = arch,
68+
exec_os = os,
69+
) for os, arch in _COMMON_EXEC_PLATFORMS]
70+
71+
host_zig_toolchain()
5972
```
6073

6174
And this to `.bazelrc` on a Unix-y systems:
@@ -256,7 +269,7 @@ To the list of libc aware toolchains and platforms:
256269
```
257270
$ bazel query @zig_sdk//libc_aware/toolchain/...
258271
$ bazel query @zig_sdk//libc_aware/platform/...
259-
```
272+
```
260273

261274
Libc-aware toolchains are especially useful when relying on
262275
[transitions][transitions], as transitioning `extra_platforms` will cause the
@@ -288,13 +301,13 @@ This is a guardrail.
288301
Both Go and Bazel naming schemes are accepted. For convenience with
289302
Go, the following Go-style toolchain aliases are created:
290303

291-
|Bazel (zig) name | Go name |
292-
|---------------- | -------- |
293-
|`x86_64` | `amd64` |
294-
|`aarch64` | `arm64` |
295-
|`wasm32` | `wasm` |
296-
|`macos` | `darwin` |
297-
|`wasi` | `wasip1` |
304+
| Bazel (zig) name | Go name |
305+
| ---------------- | -------- |
306+
| `x86_64` | `amd64` |
307+
| `aarch64` | `arm64` |
308+
| `wasm32` | `wasm` |
309+
| `macos` | `darwin` |
310+
| `wasi` | `wasip1` |
298311

299312
For example, the toolchain `linux_amd64_gnu.2.28` is aliased to
300313
`x86_64-linux-gnu.2.28`. To find out which toolchains can be registered or
@@ -306,7 +319,7 @@ $ bazel query @zig_sdk//toolchain/...
306319

307320
## Incompatibilities with clang and gcc
308321

309-
`zig cc` is *almost* a drop-in replacement for clang/gcc. This section lists
322+
`zig cc` is _almost_ a drop-in replacement for clang/gcc. This section lists
310323
some of the discovered differences and ways to live with them.
311324

312325
### UBSAN and "SIGILL: Illegal Instruction"
@@ -379,9 +392,11 @@ $ docker run -e CC=/usr/bin/false -ti --rm -v "$PWD:/x" -w /x debian:bookworm-sl
379392
# ./ci/release
380393
# ./ci/zig-wrapper
381394
```
395+
382396
## Communication
383397

384398
We maintain two channels for comms:
399+
385400
- Github issues and pull requests.
386401
- Slack: `#zig` in bazelbuild.slack.com.
387402

@@ -404,19 +419,19 @@ accessed like this:
404419

405420
Guidelines for maintainers[^2]:
406421

407-
* Communicate intent precisely.
408-
* Edge cases matter.
409-
* Favor reading code over writing code.
410-
* Only one obvious way to do things.
411-
* Runtime crashes are better than bugs.
412-
* Compile errors are better than runtime crashes.
413-
* Incremental improvements.
414-
* Avoid local maximums.
415-
* Reduce the amount one must remember.
416-
* Focus on code rather than style.
417-
* Resource allocation may fail; resource deallocation must succeed.
418-
* Memory is a resource.
419-
* Together we serve the users.
422+
- Communicate intent precisely.
423+
- Edge cases matter.
424+
- Favor reading code over writing code.
425+
- Only one obvious way to do things.
426+
- Runtime crashes are better than bugs.
427+
- Compile errors are better than runtime crashes.
428+
- Incremental improvements.
429+
- Avoid local maximums.
430+
- Reduce the amount one must remember.
431+
- Focus on code rather than style.
432+
- Resource allocation may fail; resource deallocation must succeed.
433+
- Memory is a resource.
434+
- Together we serve the users.
420435

421436
On a more practical note:
422437

examples/rules_cc/WORKSPACE

+15-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,25 @@ http_archive(
1414
],
1515
)
1616

17-
load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")
17+
load("@hermetic_cc_toolchain//toolchain:defs.bzl", "host_zig_toolchain", zig_toolchains = "toolchains")
18+
19+
_COMMON_EXEC_PLATFORMS = [
20+
("linux", "amd64"),
21+
("linux", "arm64"),
22+
("windows", "amd64"),
23+
("macos", "arm64"),
24+
("macos", "amd64"),
25+
]
1826

1927
# Plain zig_toolchains() will pick reasonable defaults. See
2028
# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and
2129
# download URL.
22-
zig_toolchains()
30+
[zig_toolchains(
31+
exec_arch = arch,
32+
exec_os = os,
33+
) for os, arch in _COMMON_EXEC_PLATFORMS]
34+
35+
host_zig_toolchain()
2336

2437
register_toolchains(
2538
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",

toolchain/defs.bzl

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def toolchains(
8989
exec_arch = exec_arch,
9090
)
9191

92+
def host_zig_toolchain():
93+
host_zig_repository(name = "zig_sdk")
94+
9295
def _quote(s):
9396
return "'" + s.replace("'", "'\\''") + "'"
9497

tools/releaser/main.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,33 @@ http_archive(
236236
],
237237
)
238238
239-
load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")
239+
load("@hermetic_cc_toolchain//toolchain:defs.bzl", host_zig_toolchain, zig_toolchains = "toolchains")
240+
241+
_COMMON_EXEC_PLATFORMS = [
242+
("linux", "amd64"),
243+
("linux", "arm64"),
244+
("windows", "amd64"),
245+
("macos", "arm64"),
246+
("macos", "amd64"),
247+
]
240248
241249
# Plain zig_toolchains() will pick reasonable defaults. See
242250
# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and
243251
# download URL.
244-
zig_toolchains()
252+
[zig_toolchains(
253+
exec_arch = arch,
254+
exec_os = os,
255+
) for os, arch in _COMMON_EXEC_PLATFORMS]
256+
257+
host_zig_toolchain()
245258
`, version, shasum)
246259
}
247260

248261
// updateBoilerplate updates all example files with the given version.
249262
func updateBoilerplate(repoRoot string, boilerplate string) error {
250263
const (
251264
startMarker = `load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")` + "\n"
252-
endMarker = "zig_toolchains()\n"
265+
endMarker = "host_zig_repository()\n"
253266
)
254267

255268
for _, gotpath := range _boilerplateFiles {

0 commit comments

Comments
 (0)