Skip to content
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

Rewrite bundle_static to be much more efficient. #8386

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

alexreinking
Copy link
Member

The bundle_static function now detects the private static dependencies on the given target (in our case, always Halide) and uses the platform librarian tool to merge static dependencies into a static library. It picks which tool to use by checking, in order:

  • When targeting Windows, it looks for lib.exe.
  • When targeting macOS, it checks if libtool is the Apple libtool.
  • Whether ar is GNU ar and if so, generates an MRI script.
  • Otherwise, a FATAL_ERROR is issued.

To mark a static library for bundling, we link privately and use the $<BUILD_LOCAL_INTERFACE:...> generator expression. This prevents it from being exported, too.

With this PR, imported static dependencies besides LLVM (wabt, flatbuffers) can be bundled, too. Previously, they were only bundled when vendored via FetchContent.

The generator expression that implements this logic is quite complex. It involves meta-programming generator expressions during evaluation and then evaluating them. Even so, this saves a considerable amount of time unpacking LLVM into a temporary directory and adding the objects to the link line (the previous approach).

@alexreinking alexreinking added the release_notes For changes that may warrant a note in README for official releases. label Aug 10, 2024
return()
endif ()

# The following code is quite subtle. First, it "recursively" (up to a depth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent comment.

@alexreinking alexreinking merged commit 6dc2b3e into main Aug 12, 2024
16 checks passed
LebedevRI pushed a commit to LebedevRI/Halide that referenced this pull request Aug 13, 2024
The `bundle_static` function now detects the private static dependencies
on the given target (in our case, always Halide) and uses the platform
librarian tool to merge static dependencies into a static library. It
picks which tool to use by checking, in order:

* When targeting Windows, it looks for `lib.exe`.
* When targeting macOS, it checks if `libtool` is the Apple libtool.
* Whether `ar` is GNU ar and if so, generates an MRI script.
* Otherwise, a `FATAL_ERROR` is issued.

To mark a static library for bundling, we link privately and use
the `$<BUILD_LOCAL_INTERFACE:...>` generator expression. This prevents
it from being exported, too.

The generator expression that implements this logic is quite complex.
It involves meta-programming generator expressions during evaluation
and then evaluating them. Even so, this saves a considerable amount of
time unpacking LLVM into a temporary directory and adding the objects
to the link line (the previous approach).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_notes For changes that may warrant a note in README for official releases.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants