1
Fork 0

added support for Windows targets

nix
Fabian Hahn 2022-05-29 17:35:17 +01:00 committed by Motiejus Jakštys
parent 4a6eef7945
commit 72475ee012
3 changed files with 39 additions and 1 deletions

View File

@ -152,6 +152,8 @@ register_toolchains(
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain:darwin_amd64",
"@zig_sdk//toolchain:darwin_arm64",
"@zig_sdk//toolchain:windows_amd64",
"@zig_sdk//toolchain:windows_arm64",
)
```
@ -318,6 +320,18 @@ is currently not implemented.
target macos.10 (Catalina), macos.11 (Big Sur) or macos.12 (Monterey). It
currently targets the lowest version, without ability to change it.
## Windows: output file extensions
Bazel won't use common Windows file extensions for built output binaries.
Instead, it will generate binaries with common Unix extensions that you might
have to manually rename before deploying them to an actual Windows system:
| Binary type | Bazel extension | Windows extension |
|----------------|-----------------|-------------------|
| Static library | .a | .lib |
| Shared library | .so | .dll |
| Executable | (no extension) | .exe |
# Known Issues In Upstream
This section lists issues that I've stumbled into when using `zig cc`, and is

View File

@ -1,11 +1,16 @@
load("@bazel-zig-cc//toolchain/private:defs.bzl", "LIBCS")
_CPUS = (("x86_64", "amd64"), ("aarch64", "arm64"))
_OS = {
"linux": ["linux"],
"macos": ["macos", "darwin"],
"windows": ["windows"],
}
def declare_platforms():
# create @zig_sdk//{os}_{arch}_platform entries with zig and go conventions
for zigcpu, gocpu in _CPUS:
for bzlos, oss in {"linux": ["linux"], "macos": ["macos", "darwin"]}.items():
for bzlos, oss in _OS.items():
for os in oss:
declare_platform(gocpu, zigcpu, bzlos, os)

View File

@ -40,6 +40,7 @@ def target_structs():
ret = []
for zigcpu, gocpu in (("x86_64", "amd64"), ("aarch64", "arm64")):
ret.append(_target_darwin(gocpu, zigcpu))
ret.append(_target_windows(gocpu, zigcpu))
ret.append(_target_linux_musl(gocpu, zigcpu))
for glibc in _GLIBCS:
ret.append(_target_linux_gnu(gocpu, zigcpu, glibc))
@ -70,6 +71,24 @@ def _target_darwin(gocpu, zigcpu):
tool_paths = {"ld": "ld64.lld"},
)
def _target_windows(gocpu, zigcpu):
return struct(
gotarget = "windows_{}".format(gocpu),
zigtarget = "{}-windows-gnu".format(zigcpu),
includes = [
"libunwind/include",
"libc/include/any-windows-any",
],
linkopts = [],
copts = [],
bazel_target_cpu = "x64_windows",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:{}".format(zigcpu),
],
tool_paths = {"ld": "ld64.lld"},
)
def _target_linux_gnu(gocpu, zigcpu, glibc_version):
glibc_suffix = "gnu.{}".format(glibc_version)