fix: various mac build fixes and improvements [DIP-311] #112
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The recent macos sdk v15 update has caused a number of issues with our builds that require various tweaks to our build settings to fix.
Switch to ninja for cmake generator
The
cmake
build process involves bootstrapping a gnu make binary from source. The update has caused some strange build errors during this process. More info can be found in the ticket I've created here: bazel-contrib/rules_foreign_cc#1099In the meantime we can just switch to using the ninja generator.
Drop support for shared linking
We make liberal use of "weak linking" for various purposes across the codebase - usually implemented using function pointers for (I assume) portability.
However, this means that most of our libraries can't really be built as shared libraries due to resulting "undefined reference" errors.
In bazel the build system will by default always try to build the shared library unless
linkstatic
is set toTrue
. So on mac this was causing errors during the normal build. Not sure why linux was not having problems (all our CMake builds fail when-DBUILD_SHARED_LIBS=TRUE
).To fix this I added
-undefined dynamic_lookup
to the link flags on mac to tell the linker we'll supply the symbols later at the final link step.Now with the update, for whatever reason these flags appear to be causing the following crash on m1 macs when the linker tries to link a binary:
Since we've never really supported shared linking except in some exceptional cases, I've disabled shared library builds by default across all our code and thus can remove the problematic flags (and probably get a perf boost as well).
Make the minimum macos target consistent
Another annoyance with the mac builds was that the bazel code was getting compiled with a different macos deployment target than the cmake libraries, which resulting in the build output getting spammed with linker warnings referencing this difference.
On my system the bazel target was
13.0
, while the cmake value was13.6
. I'm not sure how (as of our current version of bazel 6.2) this value is computed.In CMake it's interpolated from the system.
To fix this I've wired up our toolchain to respect the macos_minimum_os flags and add
-mmacos-version-min
to our build. This is just taken from the most recentHEAD
ofbazel
which is not in 6.x.The CMake side requires explicitly setting CMAKE_OSX_DEPLOYMENT_TARGET variable to the same value.
It would be better if
rules_foreign_cc
also respected themacos_minimum_os
flag so the value would not have to be hardcoded. We can perhaps open a ticket to request this.13.0
seems like a reasonable minimum deployment target since these builds are only intended for development machines.Testing
I've tested these changes on m1 and intel macs as well as the following test PR's: