-
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
Draft: Attempt at Mac OS compilation #184
base: main
Are you sure you want to change the base?
Conversation
motiejus@mtwork:/code/bazel-zig-cc$ bazel build --spawn_strategy=local --platforms @zig_sdk//libc_aware/platform:macos_aarch64_sdk.13.1 test/c:which_libc INFO: Analyzed target //test/c:which_libc (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //test/c:which_libc up-to-date: bazel-bin/test/c/which_libc INFO: Elapsed time: 0.071s, Critical Path: 0.00s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action motiejus@mtwork:/code/bazel-zig-cc$ file bazel-bin/test/c/which_libc bazel-bin/test/c/which_libc: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE> motiejus@mtwork:/code/bazel-zig-cc$
But need to go back to see what hacks I added
bazel build --spawn_strategy=local --platforms @zig_sdk//libc_aware/platform:macos_aarch64_sdk.14.2 test/c:which_libc --sandbox_debug -s INFO: Build completed successfully, 4 total actions
toolchain/private/defs.bzl
Outdated
"external/hermetic_cc_toolchain~~toolchains~macos_sdk_{}".format(macos_sdk_version), | ||
"-F", | ||
"external/hermetic_cc_toolchain~~toolchains~macos_sdk_{}/Frameworks".format(macos_sdk_version), | ||
"-L", | ||
"external/hermetic_cc_toolchain~~toolchains~macos_sdk_{}/lib".format(macos_sdk_version), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why external/macos_sdk_…
path doesn't work. Is it how the repository was defined? I'm not sure if this is idiomatic bazel to depend on an external path with ~
s, I'd imagine these are 'non-public' paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are bzlmod canonical repo paths, which are not guaranteed to be deterministic. You'll want to instead resolve them with some combination of Label
and repository_ctx.path
// HACK: if OS is macos, then force the ABI triple to "none". | ||
if (!mem.eql(u8, got_os, "macos")) | ||
return RunMode{ .cc = triple }; | ||
|
||
if (mem.eql(u8, got_arch, "aarch64")) | ||
return RunMode{ .cc = "aarch64-macos-none" }; | ||
|
||
if (mem.eql(u8, got_arch, "x86_64")) | ||
return RunMode{ .cc = "x86_64-macos-none"}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these hacks are to get macos-arm64-sdk.14.2
to be recognized by zig with an expected target ABI.
toolchain/private/defs.bzl
Outdated
"libc/darwin", | ||
"libc/include/any-macos-any", | ||
"libc/include/any-macos-any", | ||
] + _INCLUDE_TAIL, | ||
linkopts = ["-Wl,-headerpad_max_install_names"], | ||
linkopts = macos_sdk_opts, | ||
dynamic_library_linkopts = ["-Wl,-undefined=dynamic_lookup"], | ||
supports_dynamic_linker = True, | ||
cxx_builtin_include_directories = [ | ||
"external/hermetic_cc_toolchain~~toolchains~macos_sdk_{}/include".format(macos_sdk_version) | ||
], | ||
sdk_include_files = [ | ||
"@macos_sdk_{}//:Frameworks".format(macos_sdk_version), | ||
# "@macos_sdk_{}//:usr_include".format(macos_sdk_version), | ||
], | ||
sdk_lib_files = ["@macos_sdk_{}//:usr_lib".format(macos_sdk_version)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found these by trial and error and compiling against a target that expects Mac OS SDK ( the example in #10 (comment) )
fatal error: 'CFNetwork/CFProxySupport.h' file not found
hit error: unsupported linker arg: -no_pie
@chrisirhc nice work so far! Happy to help test this when ready. |
Realized that hexops is an incomplete sysroot, so I went with unpacking a pkg.
I believe it's the issue reported in ziglang/zig#20243 But I guess this is progress. |
Attempt to get a working macos branch.
This is a continuation of the work in https://github.com/motiejus/hermetic_cc_toolchain/tree/macos .
NOTE: I have no idea what I'm doing. I'm piecing together the previous threads about sysroot from the readme.
I have no idea what the zig or gcc options mean.
There are a number of hacks in this branch, so this is still WIP.
TODOs:
Fixes #10