Skip to content

Commit

Permalink
feat: update WORKSPACE example for new flow
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonThomasJonesARM committed Nov 28, 2024
1 parent 29c63be commit d68999b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 29 deletions.
63 changes: 39 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,25 @@ http_archive(
],
)
load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")
load("@hermetic_cc_toolchain//toolchain:defs.bzl", host_zig_toolchain, zig_toolchains = "toolchains")
_COMMON_EXEC_PLATFORMS = [
("linux", "amd64"),
("linux", "arm64"),
("windows", "amd64"),
("macos", "arm64"),
("macos", "amd64"),
]
# Plain zig_toolchains() will pick reasonable defaults. See
# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and
# download URL.
zig_toolchains()
[zig_toolchains(
exec_arch = arch,
exec_os = os,
) for os, arch in _COMMON_EXEC_PLATFORMS]
host_zig_toolchain()
```

And this to `.bazelrc` on a Unix-y systems:
Expand Down Expand Up @@ -256,7 +269,7 @@ To the list of libc aware toolchains and platforms:
```
$ bazel query @zig_sdk//libc_aware/toolchain/...
$ bazel query @zig_sdk//libc_aware/platform/...
```
```

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

|Bazel (zig) name | Go name |
|---------------- | -------- |
|`x86_64` | `amd64` |
|`aarch64` | `arm64` |
|`wasm32` | `wasm` |
|`macos` | `darwin` |
|`wasi` | `wasip1` |
| Bazel (zig) name | Go name |
| ---------------- | -------- |
| `x86_64` | `amd64` |
| `aarch64` | `arm64` |
| `wasm32` | `wasm` |
| `macos` | `darwin` |
| `wasi` | `wasip1` |

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

## Incompatibilities with clang and gcc

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

### UBSAN and "SIGILL: Illegal Instruction"
Expand Down Expand Up @@ -379,9 +392,11 @@ $ docker run -e CC=/usr/bin/false -ti --rm -v "$PWD:/x" -w /x debian:bookworm-sl
# ./ci/release
# ./ci/zig-wrapper
```

## Communication

We maintain two channels for comms:

- Github issues and pull requests.
- Slack: `#zig` in bazelbuild.slack.com.

Expand All @@ -404,19 +419,19 @@ accessed like this:

Guidelines for maintainers[^2]:

* Communicate intent precisely.
* Edge cases matter.
* Favor reading code over writing code.
* Only one obvious way to do things.
* Runtime crashes are better than bugs.
* Compile errors are better than runtime crashes.
* Incremental improvements.
* Avoid local maximums.
* Reduce the amount one must remember.
* Focus on code rather than style.
* Resource allocation may fail; resource deallocation must succeed.
* Memory is a resource.
* Together we serve the users.
- Communicate intent precisely.
- Edge cases matter.
- Favor reading code over writing code.
- Only one obvious way to do things.
- Runtime crashes are better than bugs.
- Compile errors are better than runtime crashes.
- Incremental improvements.
- Avoid local maximums.
- Reduce the amount one must remember.
- Focus on code rather than style.
- Resource allocation may fail; resource deallocation must succeed.
- Memory is a resource.
- Together we serve the users.

On a more practical note:

Expand Down
17 changes: 15 additions & 2 deletions examples/rules_cc/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,25 @@ http_archive(
],
)

load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")
load("@hermetic_cc_toolchain//toolchain:defs.bzl", "host_zig_toolchain", zig_toolchains = "toolchains")

_COMMON_EXEC_PLATFORMS = [
("linux", "amd64"),
("linux", "arm64"),
("windows", "amd64"),
("macos", "arm64"),
("macos", "amd64"),
]

# Plain zig_toolchains() will pick reasonable defaults. See
# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and
# download URL.
zig_toolchains()
[zig_toolchains(
exec_arch = arch,
exec_os = os,
) for os, arch in _COMMON_EXEC_PLATFORMS]

host_zig_toolchain()

register_toolchains(
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",
Expand Down
3 changes: 3 additions & 0 deletions toolchain/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def toolchains(
exec_arch = exec_arch,
)

def host_zig_toolchain():
host_zig_repository(name = "zig_sdk")

def _quote(s):
return "'" + s.replace("'", "'\\''") + "'"

Expand Down
19 changes: 16 additions & 3 deletions tools/releaser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,33 @@ http_archive(
],
)
load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")
load("@hermetic_cc_toolchain//toolchain:defs.bzl", host_zig_toolchain, zig_toolchains = "toolchains")
_COMMON_EXEC_PLATFORMS = [
("linux", "amd64"),
("linux", "arm64"),
("windows", "amd64"),
("macos", "arm64"),
("macos", "amd64"),
]
# Plain zig_toolchains() will pick reasonable defaults. See
# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and
# download URL.
zig_toolchains()
[zig_toolchains(
exec_arch = arch,
exec_os = os,
) for os, arch in _COMMON_EXEC_PLATFORMS]
host_zig_toolchain()
`, version, shasum)
}

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

for _, gotpath := range _boilerplateFiles {
Expand Down

0 comments on commit d68999b

Please sign in to comment.