-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support local OSX SDK #10
Comments
W are not planning to add support non-hermetic osx compilation with bazel-zig-cc. If we go with osx support, it needs to be hermetic. Zig supports linking MachO, but it needs the libc definitions (tbd files). That is the biggest problem, which are gray area (feel free to search for We are open, though, to support tbd files via a user-provided http_archive. |
If there were some way of providing the |
I have no idea. It's probably not too difficult, but I never tried. We did not get to the point to try it at Uber too. If someone in the community needs it and implements support for this sysroot, we will review/accept the PR. |
My research led me to rules_apple where cc_library could be linked like this https://github.com/bazelbuild/rules_apple/blob/master/test/starlark_tests/resources/kext_resources/BUILD I have not tested whether this copt could be added to rules_go just yet, but if it could then that would solve my problem. @motiejus how do you solve building application with transitive deps depending on MacOS libraries like this? Do you simply block these deps from being used at Uber entirely? |
I have only (and by extension Uber) used As for how to compile more OSX applications, here are the rough steps:
You are welcome to wait (Uber may get to it, but I can't promise anything; someone might as well do it too), implement this yourself or ask/pay someone in the community to implement it for you. Like I said before, if we get a patch that adds a |
Is there something to do to have access to CoreFoundation? We recently updated our dependency on protobuf that since v22.0 depends on abseil that itself internally depends on CoreFoundation: Since then, building any
Our zig_toolchain is configured following the Use case: always compile with zig cc instructions, so with a list of unconditionally added toolchains, and with Is it possible to have such a setup working? Or is zig-cc not an option anymore? I'm posting this question here, because it's related to the original issue, but please let me know if I should create a new one. |
I am honestly surprised you were able to compile a real binary to osx using
I'm afraid it won't be actionable, since osx target is not supported in hermetic_cc_toolchain until someone does the work and implements it. |
Yes it worked perfectly for several month, up until that dependency on abseil got added. I guess I got lucky and my use case was quite trivial, haha.
Ok that was my understanding, I was just curious if somehow it was different if the only dependency on OSX SDK was CoreFoundation, but I guess not. Thank you @motiejus, that's some incredible work you've done there! |
This comes up often. Reopening for visibility. Also see my comment in #104 (comment) |
- `.bazelrc`: `sandbox_add_mount_pair=/tmp` is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. The top-level project itself is not bzlmod yet, because that's book-keeping (it can already be used with bzlmod, so this is purely book-keeping). We can tackle this out of band with dependency updates.
- `.bazelrc`: `sandbox_add_mount_pair=/tmp` is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. The top-level project itself is not bzlmod yet, because that's book-keeping (it can already be used with bzlmod, so this is purely book-keeping). We can tackle this out of band with dependency updates. Fixes #134
- bump bazel to 6.4.0 - bump rules_go, gazelle, platforms - enable bzlmod - remove WORKSPACE - remove `gofmt`, github.com//issues/136 - remove Go MacOS x86_64 tests, github.com//issues/10
- `.bazelrc`: `sandbox_add_mount_pair=/tmp/zig-cache` (if you can) or `/tmp` (if not) is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. Fixes #134
- `.bazelrc`: `sandbox_add_mount_pair=/tmp/zig-cache` (if you can) or `/tmp` (if not) is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. Fixes #134
- `.bazelrc`: `sandbox_add_mount_pair=/tmp/zig-cache` (if you can) or `/tmp` (if not) is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. Fixes #134.
- `.bazelrc`: `sandbox_add_mount_pair=/tmp/zig-cache` (if you can) or `/tmp` (if not) is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. Fixes #134.
- `.bazelrc`: `sandbox_add_mount_pair=/tmp/zig-cache` (if you can) or `/tmp` (if not) is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. Fixes #134.
- `.bazelrc`: `sandbox_add_mount_pair=/tmp/zig-cache` (if you can) or `/tmp` (if not) is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. Fixes #134.
- `.bazelrc`: `sandbox_add_mount_pair=/tmp/zig-cache` (if you can) or `/tmp` (if not) is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. Fixes #134.
- `.bazelrc`: `sandbox_add_mount_pair=/tmp/zig-cache` (if you can) or `/tmp` (if not) is now required everywhere. - `.bazelrc` and `README`: remove deprecated/now-default flags. - `README`: add links to #10 and #83. - `README`: mention bzlmod. - `examples/*/.bazelrc`: make them the same for a better recommendation. Fixes #134.
I have some updates on that front: ziglang/zig#10299 (comment) Also, here is a repo rule to download and unpack it: load(
"@bazel_tools//tools/build_defs/repo:utils.bzl",
"get_auth",
"patch",
"workspace_and_buildfile",
)
def _http_pkg_archive_impl(rctx):
if rctx.attr.build_file and rctx.attr.build_file_content:
fail("Only one of build_file and build_file_content can be provided.")
rctx.download(
url = rctx.attr.urls,
output = ".downloaded.pkg",
sha256 = rctx.attr.sha256,
canonical_id = " ".join(rctx.attr.urls),
auth = get_auth(rctx, rctx.attr.urls),
)
res = rctx.execute(["/usr/sbin/pkgutil", "--expand-full", ".downloaded.pkg", "tmp"])
if res.return_code != 0:
fail("Failed to extract package: {}".format(res.stdout))
rctx.delete(".downloaded.pkg")
strip_prefix = "tmp/Payload/"
if rctx.attr.strip_prefix:
strip_prefix += rctx.attr.strip_prefix + "/"
extracted = rctx.path(strip_prefix)
if not extracted.is_dir or not extracted.exists:
fail("Extracted package does not contain expected directory: {}".format(strip_prefix))
entries = extracted.readdir(watch = "no")
for entry in entries:
rctx.execute(["mv", str(entry), entry.basename])
rctx.delete(extracted)
workspace_and_buildfile(rctx)
patch(rctx)
http_pkg_archive = repository_rule(
_http_pkg_archive_impl,
attrs = {
"urls": attr.string_list(mandatory = True),
"sha256": attr.string(mandatory = True),
"strip_prefix": attr.string(),
"build_file": attr.label(allow_single_file = True),
"build_file_content": attr.string(),
"workspace_file": attr.label(allow_single_file = True),
"workspace_file_content": attr.string(),
},
) |
I have looked into this briefly; looks like those .pkg files are just a xar format which can be extracted by Download using this ziglang/zig#10299 (comment) |
However, i believe this sysroot repository rule can be built separately and should live in https://github.com/bazelbuild/rules_apple |
Toolchain setup
Error outputs
Gazelle generated build files
Bazel version is 6.0.0 on M1 Mac.
Using Grail's toolchain, the sysroot is set to OSX SDK dynamically with https://github.com/grailbio/bazel-toolchain/blob/069ee4e20ec605a6c76c1798658e17175b2eb35e/toolchain/internal/sysroot.bzl#L24-L39
Ultimately this should affect
cxx_builtin_include_directories
andbuiltin_sysroot
attribute when callcc_common. create_cc_toolchain_config_info()
The text was updated successfully, but these errors were encountered: