1
Fork 0
Commit Graph

183 Commits

Author SHA1 Message Date
Motiejus Jakštys c023c217a5 contrib/own_zig.md: clarify zig-bootstrap instructions 2022-09-22 11:39:39 +03:00
Ken Micklas 64b6c702db Fix include root path for macos-aarch64 2022-09-15 22:19:06 +03:00
Ken Micklas ba0b0376ea Move Label dependencies above archive fetching to reduce restarts 2022-09-15 22:18:43 +03:00
Motiejus Jakštys f161caf870 bump to zig 0.10.0-dev.3999+fda6d4477
llvm 15
2022-09-14 11:54:04 +03:00
Motiejus Jakštys bf32b5ee92 repository_rule: depend on $BAZEL_ZIG_CC_CACHE_PREFIX
Otherwise the repository doesn't get re-downloaded/wiped when this
parameter changes.
2022-09-12 13:46:07 +03:00
Motiejus Jakštys 2f0ae4affa target_musl: remove linkopts
These flags were added in this commit:

    commit 58a04fbfec
    Author: Motiejus Jakštys <motiejus@jakstys.lt>
    Date:   Tue Jun 15 09:10:15 2021 +0300

        bump zig

I am still quite puzzled on why I did this and in such a commit: it
bumps the zig version and changes the linker flag.

Working alone, experimentation time? Probably something like this.
Anyhow, this is a good example of the real value of code reviews.
2022-09-02 13:21:39 +03:00
Motiejus Jakštys e1d699f7ed upgrade to 0.10.0-dev.3838+77f31ebbb 2022-09-01 09:28:43 +03:00
Motiejus Jakštys 79674a1d96 replace /usr/bin/env sh with /bin/sh
/bin/sh exists in NixOS and in fact is the only file in `/bin`:

    $ docker run -ti --rm nixos/nix ls /bin /usr/bin
    /bin:
    sh

    /usr/bin:
    env

More context in
https://lists.sr.ht/~motiejus/bazel-zig-cc/%3CCAFVMu-pvNx%2BpeQYdge_fvmSGrHDmn78VmoYwTxkDgMjbzfVAwQ%40mail.gmail.com%3E
2022-08-30 09:21:27 +03:00
Motiejus Jakštys 342b239bb9 nit: style of cache prefix definition 2022-08-29 14:44:38 +03:00
Motiejus Jakštys e861c5b4be cache_prefix: clean up OS logic
'Windows' and 'Other' and guessing of cache prefix was convoluted
2022-08-29 13:01:09 +03:00
Fabian Hahn a410141ca4 add cache prefix configuration for Windows 2022-08-28 20:18:21 +03:00
Motiejus Jakštys 15f9578591 use a specific template if cache prefix is known 2022-08-26 10:55:29 +03:00
Ken Micklas 0612c6ed9c Support configuring cache prefix with an environment variable
The user may want to build with `--sandbox_tmpfs_path=/tmp`, in which
case the Zig cache will not be shared between sandboxes, massively
slowing down the build. With this feature, the user can pass flags
like `--repo_env=BAZEL_ZIG_CC_CACHE_PREFIX=$HOME/.cache/bazel-zig-cc`
together with `--sandbox_writable_path=$HOME/.cache/bazel-zig-cc` to
put the cache somewhere else which can be shared between sandboxes.
2022-08-26 10:47:25 +03:00
Motiejus Jakštys 23d9b9d39e [macos] remove libc/include/{}-macos.{}-gnu
This seems to be absent in the Zig SDK for macos targets.

Reported-by: Mike Eastham <meastham@tecton.ai>
2022-08-23 18:12:02 +03:00
Luis Holanda f13e59a30a Add missing include path for MacOS platforms
While integrating the project into our Bazel workspace, we had some
problems while building protoc in an Intel MacBook.

From my testing, the issue seems to be caused by missing include path
in the toolchain configuration to the `-none` variant of the headers.
More details below.

The issue can be reproduced directly inside `bazel-zig-cc` by including
the protobuf workspace as a dependency:

+http_archive(
+    name = "com_google_protobuf",
+    sha256 = "2d9084d3dd13b86ca2e811d2331f780eb86f6d7cb02b405426e3c80dcbfabf25",
+    strip_prefix = "protobuf-3.21.1",
+    url = "https://github.com/protocolbuffers/protobuf/archive/v3.21.1.zip",
+)
+
+load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
+
+protobuf_deps()

And then executing:

bazel build --platforms @zig_sdk//platform:darwin_amd64 @com_google_protobuf//:protoc

The command fails with the same error both in native compilation and
cross-compiling from Linux. The error:

ERROR: <output_base>/external/zlib/BUILD.bazel:37:11: Compiling compress.c failed: undeclared inclusion(s) in rule '@zlib//:zlib':
this rule is missing dependency declarations for the following files included by 'compress.c':
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/cdefs.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_symbol_aliasing.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/machine/limits.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/i386/limits.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/i386/_limits.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/syslimits.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/machine/types.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/i386/types.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/i386/_types.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_types/_int8_t.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_types/_uintptr_t.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/machine/_types.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_pthread/_pthread_types.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/machine/endian.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/i386/endian.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/libkern/_OSByteOrder.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/libkern/i386/_OSByteOrder.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_types/_fd_def.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/Availability.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/AvailabilityInternal.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_pthread/_pthread_attr_t.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_pthread/_pthread_cond_t.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_pthread/_pthread_condattr_t.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_pthread/_pthread_rwlock_t.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_pthread/_pthread_rwlockattr_t.h'
  '<output_base>/external/zig_sdk/lib/libc/include/x86_64-macos.10-none/sys/_pthread/_pthread_t.h'
Target @com_google_protobuf//:protoc failed to build

(<output_base> replaced manually to keep the description sane)

Note that the specific rule included in the error message will vary due
to parallelism, but the error is always the same and the missing paths
always have the same prefix (up to `x86_64-macos.10-none`).

After applying the patch, we confirmed that both native and cross compilations
works as expected and can properly build protoc.

Signed-off-by: Luis Holanda <luiscmholanda@gmail.com>
2022-08-23 18:11:54 +03:00
Motiejus Jakštys db7beefbe4 c++: fall back to cache dir in /tmp
rules_go is making calls that do `env - <...>` and are setting neither
TMPDIR nor HOME. So we should always fallback somewhere.
2022-08-12 09:25:37 +03:00
Motiejus Jakštys e50d1597f4 upgrade zig sdk to one of last night 2022-08-12 05:38:34 +03:00
Motiejus Jakštys 771fcc5bc6 bump to go 1.19
Removing --no-gc-sections, because that's now in Go. Whoo!
2022-08-12 05:21:24 +03:00
Luis Holanda c4125cf13b Support NixOS and others non-FHS Linux distros
As it expects Bash to be at `/bin/bash`, the current implementation
fails to execute on NixOS, given that there bash is in a non-standard
path (i.g. `/nix/store/<hash>-bash-interactive-<version>/bin/bash`).

This patch specifically changes `/bin/bash` paths to use `/usr/bin/env bash`,
which should give the correct path in every Unix system.

Signed-off-by: Luis Holanda <luiscmholanda@gmail.com>
2022-07-28 12:44:57 -07:00
Motiejus Jakštys 64a7007a23 fastbuild: remove -O0
this is the default in zig cc now
2022-07-12 14:53:02 +03:00
Motiejus Jakštys df11a2af38 bump zig to 0.10.0-dev.2977+7d2e14267"
changes:
- upgrade from llvm 13 to llvm 14
- add --compress-debug-sections=zlib
2022-07-12 14:09:11 +03:00
Motiejus Jakštys 0818e20167 bump zig upstream 2022-07-04 15:39:41 +03:00
Motiejus Jakštys de0350405d lint 2022-07-04 15:32:36 +03:00
Motiejus Jakštys 527ebbc863 fastbuild: replace -gmlt with -O0
- -gmlt is a noop in zig, because -g is a default anyway.
- -O0 was fixed in ziglang/zig 02ba3cb25cc8ee2637c6fb7bcb935722490ba05c
2022-07-01 13:54:03 +03:00
Motiejus Jakštys b7da83e13e upgrade zig sdk
Also fix darwin zigtarget to none; see 5b813f1a2acdc1668e39008b02a234f3da724552 of zig
2022-06-28 12:47:23 +03:00
Motiejus Jakštys 4cfc30dd1c [fastbuild] use -fno-lto
This is very cache-unfriendly, because quite a lot of work is done
during the final linking stage. Let's see how this improves performance
of fastbuild.
2022-06-21 08:45:03 +03:00
laurynasl b73d167c6c Support bazel compilation_mode
Bazel has a special command line option (--compilation_mode) for specifying how
c artifacts should be compiled. Copy over the implementation without too much
thought on whether they make sense.

See https://docs.bazel.build/versions/main/user-manual.html#flag--compilation_mode.

!!! Due to a regression in zig-cc, debug symbols are available under --compilation_mode opt

```
laurynasl@laurynasl ~/bazel-zig-cc
 % bazel build -c opt //test/c:which_libc 2>/dev/null && bazel-bin/test/c/which_libc && gdb -batch --ex 'info line main' bazel-bin/test/c/which_libc
glibc_2.19
Line 4 of "test/c/main.c" starts at address 0x2014f0 <main> and ends at 0x2014f1 <main+1>.
laurynasl@laurynasl ~/bazel-zig-cc
 % bazel build -c dbg //test/c:which_libc 2>/dev/null && bazel-bin/test/c/which_libc && gdb -batch --ex 'info line main' bazel-bin/test/c/which_libc
glibc_2.19
Line 4 of "test/c/main.c" starts at address 0x201500 <main> and ends at 0x201504 <main+4>.
laurynasl@laurynasl ~/bazel-zig-cc
 % bazel build -c fastbuild //test/c:which_libc 2>/dev/null && bazel-bin/test/c/which_libc && gdb -batch --ex 'info line main' bazel-bin/test/c/which_libc
glibc_2.19
Function "main" not defined.
```
2022-06-17 14:46:13 +00:00
Motiejus Jakštys 86ae317685 zig sdk: rename {ext} to {_ext}
Also update README and release scripts
2022-06-06 10:32:42 +03:00
Motiejus Jakštys 91ef17196b windows: add dynamic_library_linkopts
The patchset was created before
921fda9260, which added an option to
zig_cc_toolchain_config, causing a "soft merge conflict" after merging.
2022-06-06 10:30:39 +03:00
Fabian Hahn 72475ee012 added support for Windows targets 2022-06-02 05:27:22 +03:00
Fabian Hahn 4a6eef7945 added Windows host support 2022-06-02 05:27:22 +03:00
Jeremy Volkman a0511ca5ee Pass "-Wl,-undefined=dynamic_lookup" for dynamic libraries on darwin.
This linker flag causes undefined symbols to be ignored, which is the
default behavior on linux but not macos. This is required when building
shared libraries to use as e.g. Python modules. This also matches what
Bazel's built-in macos cc toolchain does.
2022-06-01 11:49:13 +03:00
Jeremy Volkman 921fda9260 Adds dynamic_library_linkopts to zig_cc_toolchain_config
If specified, the flags in dynamic_library_linkopts are included in
cpp_link_dynamic_library and cpp_link_nodeps_dynamic_library actions.
2022-06-01 11:49:13 +03:00
Motiejus Jakštys 8fec0e3441 zig sdk: download from zig upstream as well as jakstys.lt
Now that the toolchain supports multiple mirrors, we can have more
robust defaults: try ziglang.org first, then dl.jakstys.lt when that one
removes the build we rely on.

This will make builds less prone to inevitable failures of my home
server.
2022-05-18 10:42:51 +03:00
Motiejus Jakštys 0044260206 upgrade zig to 0.10.0-dev.2252+a4369918b 2022-05-17 14:41:02 +03:00
Motiejus Jakštys 4fa5eff207 [linux-aarch64] fix top-level include path 2022-05-06 10:46:32 +03:00
Motiejus Jakštys 94d5864cb7 move `--no-gc-sections` hack to the toolchain definition
Thanks laurynasl for the tip.
2022-05-05 14:36:36 +03:00
Motiejus Jakštys 9ce21b5276 [zig ld] --gc-sections workaround + tests
`zig cc` emits `--gc-sections` for the linker, which is incompatbile
with what CGo thinks about linking.

This commit adds a workaround: it will add `--no-gc-sections` to the
linking step if the command is not specified (falling back to the
default behavior of gcc/clang).

Related: https://github.com/golang/go/issues/52690
2022-05-05 13:36:58 +03:00
Motiejus Jakštys efca6e6428 remove support for glibc autodetection; this is a hermetic toolchain 2022-04-18 11:45:09 +03:00
Motiejus Jakštys 0c02a827ae README prose, the way I understand it 2022-04-18 11:42:13 +03:00
laurynasl 4d65b80903 Add libc constraint and libc aware toolchains
- Also get rid of @bazel_skylib dependency
2022-04-14 14:29:06 +00:00
laurynasl 68b152067c Fix register toolchain 2022-04-09 00:09:04 +03:00
laurynasl 64be98b830 Hide toolchain internals 2022-04-07 11:23:40 +00:00
Motiejus Jakštys 6ded50ad67 buildifier 2022-04-07 13:21:44 +03:00
laurynasl eedfc3312e Move toolchain definitions to toolchains/ 2022-04-07 12:43:34 +03:00
laurynasl 723e6f051d Move toolchainss under @zig_sdk//platform: 2022-04-07 12:43:34 +03:00
laurynasl d1b0dddf8c Move declare_platforms() to platform/ 2022-04-07 12:43:34 +03:00
laurynasl dd76e0b76f move platforms under @zig_cc//platform: 2022-04-07 12:43:34 +03:00
Ken Micklas ccb68098e6 Use upstream read_user_netrc from Bazel 5.1 2022-03-26 15:56:11 +02:00
Ken Micklas fc62c3a7b7 Remove repo fetch-time uname dependency, use new os.arch instead 2022-03-26 15:56:11 +02:00
Motiejus Jakštys 3492880151 bump to zig-0.10.0-dev.1393+291f5055f 2022-03-18 06:06:08 +01:00
Ken Micklas 9afcddea4f Support netrc for Zig SDK download 2022-03-18 06:04:49 +01:00
Motiejus Jakštys 2895f0c2bf replace `url_format` with `url_formats` 2022-03-18 05:44:22 +01:00
Ken Micklas fb0cf50c44 2022-03-18 05:30:42 +01:00
Ken Micklas fcb3d0432e Starlark's default argument semantics are pretty weird and likely not
what you would expect:
https://github.com/bazelbuild/starlark/blob/master/spec.md#functions

Additionally, this is just easier to read.
2022-03-18 05:30:38 +01:00
Ken Micklas 9ede1507c3 Fix and adjust darwin libc header paths depending on CPU 2022-02-11 06:29:46 +02:00
Ken Micklas 77688d0a45 Interpret arm64 output from uname as aarch64 on mac OS 2022-02-11 06:29:07 +02:00
Motiejus Jakštys bcd9731f92 add @zig_sdk//:<os>_<arch>_platform values 2022-02-03 14:24:26 +02:00
Motiejus Jakštys d27f6be570 upgrade to 0.10.0-dev.513+029844210 2022-02-02 14:59:34 +02:00
Motiejus Jakštys faae381685 upgrade zig to 0.10.0-dev.430+35423b005 2022-01-27 10:52:25 +02:00
Motiejus Jakštys 2d32bfe884 upgrade zig to 0.10.0-dev.399+366c76744
Implements -whole-archive, -no-whole-archive, -s, -S in
50905d88518f92a9b8e492daf8dbb6d38b7c61bf
2022-01-26 05:41:21 +02:00
Motiejus Jakštys 78f3a59f0c [readme] less bragging about the home server 2022-01-25 11:19:52 +02:00
Motiejus Jakštys c3655fbe65 brag about home server reliability 2022-01-25 11:12:18 +02:00
Motiejus Jakštys 23f81117ba Add description about mirrors 2022-01-25 11:05:35 +02:00
Piotr Sikora 230da38f54 Fix include paths when targeting non-x86_64 archs.
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2022-01-25 10:35:29 +02:00
Motiejus Jakštys c3144b8b7b upgrade to zig 0.10.0-dev.283+ba0f72363
Thanks Xavier for https://github.com/ziglang/zig/pull/10587
2022-01-15 09:02:37 +02:00
Motiejus Jakštys 5c2d377eca bring back 0.9.0-dev.1968+ff93486d0
See https://github.com/ziglang/zig/issues/10386
2021-12-22 14:29:49 +02:00
Motiejus Jakštys d1719dd5a5 upgrade zig to 0.9.0 2021-12-22 10:30:22 +02:00
Motiejus Jakštys b1c645b162 zig-0.9.0-dev.1968: upgrade checksums 2021-12-15 13:30:57 +02:00
Motiejus Jakštys 3ce88db8ab upgrade zig to 0.9.0-dev.1968+ff93486d0 2021-12-15 13:26:22 +02:00
Motiejus Jakštys 985e26b474 remove DEFAULT_COPTS
Optimizations should be turned by the user with `-c opt`. We want UBSAN
enabled for non-release builds.
2021-12-13 03:29:10 +02:00
Motiejus Jakštys 66dbf420f7 bump zig to 0.9.0-dev.1950+a76910b69; remove -O3 2021-12-13 03:20:02 +02:00
Motiejus Jakštys f5b7163eb1 upgrade zig 2021-12-09 10:22:26 +02:00
Motiejus Jakštys ce6075b19b upgrade to 0.9.0-dev.1920+de81c504b 2021-12-07 17:27:55 +02:00
Motiejus Jakštys 2ee3c32780 fix darwin include targets; target macos 10 2021-12-07 12:46:52 +02:00
Motiejus Jakštys 780eaff263 add missing include of x86-linux-any
Was added as part of https://github.com/ziglang/zig/issues/9837
2021-12-07 11:53:00 +02:00
Motiejus Jakštys 4fe2552ab1 upgrade zig to 0.9.0-dev.1914+7d1f47313 2021-12-07 09:51:14 +02:00
Motiejus Jakštys 8f5f249227 allow extra versions and url formats
url_format is subject to change, because it should accept multiple
inputs.
2021-12-06 08:07:28 +02:00
Motiejus Jakštys b1a2efb85f remove flock workaround
- Task #9431 (#9439) is in progress.
- The issue sometimes happened on Linux.

Therefore, remove the flock workaround.
2021-12-06 07:53:22 +02:00
Motiejus Jakštys 34b85cf57f buildifier 2021-11-05 19:47:52 +02:00
Motiejus Jakštys f6016ab830 upgrade zig to 0.9.0-dev.1414+cde3dd365 2021-10-20 07:54:01 +03:00
Motiejus Jakštys b0e83bcecc remove typo from URL 2021-10-18 10:29:00 +03:00
Motiejus Jakštys cea7c38560 use zig from dl.jakstys.lt
if anyone has an archive for any other arch, I'll take it.
2021-10-18 10:26:33 +03:00
Motiejus Jakštys feb9291d30 bring back `0.9.0-dev.727+aad459836`
the newer version fails for darwin-amd64 target.
2021-09-14 14:34:39 +03:00
Motiejus Jakštys b6c6c705b8 switch back to dev version
0.8.1 are cherry picks, turns out.
2021-09-13 09:11:35 +03:00
Motiejus Jakštys d8fd27c3ae upgrade zig, add aarch64
- upgrade zig to 0.8.1
- add preliminary aarch64 support. I don't have an aarch64 machine to
  test this with, so landing as-is. However, this will be used as an
  upstream repository, so hopefully the issues, if any, will flow in.
2021-09-13 08:44:58 +03:00
Motiejus Jakštys 3e7f92cea5 unregister default toolchains; update README 2021-08-11 09:37:54 +03:00
Motiejus Jakštys 741289bddd fix allowed toolchains 2021-08-06 12:19:11 +03:00
Motiejus Jakštys 76774cd384 fix tmpdir 2021-08-06 11:32:21 +03:00
Motiejus Jakštys 11f919ea6f fix flock 2021-08-06 11:23:39 +03:00
Motiejus Jakštys 5f5b25d34b use newer arm64 glibc explicitly 2021-08-06 09:49:52 +03:00
Motiejus Jakštys 50c5e58dcd better fcntl64 hack
this file may be included from the assembler; assembler does not
understand the `__asm__` directive.
2021-08-06 09:43:18 +03:00
Motiejus Jakštys e262e3acc5 specify absolute path to glibchack-fcntl.h 2021-08-06 08:44:56 +03:00
Motiejus Jakštys 7b0c37aacd add DEFAULT_COPTS 2021-08-05 15:21:38 +03:00
Motiejus Jakštys bf84ec2090 more aggressive toolchain resolution:
- hardcode gnu.2.19 instead of autodetect
- more tests.
2021-08-05 11:49:17 +03:00
Motiejus Jakštys 005f87a26d more robust toolchain selection 2021-08-05 09:47:34 +03:00
Motiejus Jakštys 4d44d9ffd4 speed first safety later 2021-08-04 19:46:21 +03:00
Motiejus Jakštys 144a87cd4c flock zig toolchain
slower, but more robust.
2021-08-04 15:16:18 +03:00
Motiejus Jakštys 13cba6c244 rework toolchain registration
- support specifying the glibc version.
- support picking the default of musl or glibc.
- create both zig and go conventions for `--extra_toolchains`.
2021-08-04 15:04:14 +03:00
Motiejus Jakštys 6687f16a49 update zig 2021-08-04 13:17:55 +03:00