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

Virtual hermetic frameworks #277

Merged
merged 3 commits into from
Jul 21, 2021

Conversation

jerrymarino
Copy link
Contributor

Add the ability to virtualize the framework structure. swift and clang
compile as frameworks but the files don't move and we load them via VFS.
The VFS is llvm's in-memory file system declared by JSON. VFS is already
in use but this uses it in a very different way.

This fixes many issues:

  1. we don't hit O(n) deps includes - removing thousands of framework
    search paths
  2. we don't have to "clean" frameworks. This feature added quite a bit
    of overhead and isn't necesary since it's declarative
  3. imports are fully again. traditionally a build system uses -F on a
    build directory. This causes problems with reproducible builds.

It cut clean build time in half in a big hybrid app from rules_ios
baseline. More interestingly, hot top level compiler invocations are
down nearly .5 orders of magnitude.

Remaining tasks:

  • address xcodeproj integration
  • duplicate test suite to run with this on/off
  • address xcframework imports ( right now we're using -F )

Relates to: #211

@jerrymarino jerrymarino force-pushed the jmarino/starlark_virtual_frameworks_rebased branch from e20d7d4 to e9dc1b0 Compare July 16, 2021 21:34
Copy link
Contributor

@gyfelton gyfelton left a comment

Choose a reason for hiding this comment

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

This is awesome....
Here is my TODOs for this PR:

  1. Checkout how it impacts building of rules_ios projects before and after via studying the output in bazel-out
  2. DO the same for downstream project such as our own.

Also we need to consider at least some tests to safeguard this? At least some kind of scripts to verify the output of json files?

Lastly I would assign to a contributor outside Square to confirm it makes sense to them, unless we use the feature flag to guard everything.

rules/framework.bzl Show resolved Hide resolved
import_vfsoverlays.append(dep[VFSOverlayInfo].vfs_info)

# Progated interface headers - this must encompass all of them
propagated_interface_headers = []
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an array of depset correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if virtualize_frameworks:
import_vfsoverlays = []
for dep in ctx.attr.vfs:
if not VFSOverlayInfo in dep:
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the situation where a dep of attr.vfs is not a VFSOverlayInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You'll find this in the main callsite of framework_packing - there's a few edges around imported frameworks and we pass this in ATM

rules/framework.bzl Show resolved Hide resolved
rules/framework/vfs_overlay.bzl Outdated Show resolved Hide resolved
rules/framework/vfs_overlay.bzl Outdated Show resolved Hide resolved
rules/library.bzl Outdated Show resolved Hide resolved
rules/library.bzl Show resolved Hide resolved
rules/library.bzl Show resolved Hide resolved
rules/library.bzl Outdated Show resolved Hide resolved
rules/library.bzl Outdated Show resolved Hide resolved
rules/framework.bzl Outdated Show resolved Hide resolved
@@ -0,0 +1,4 @@
feature_names = struct(
# Virtualize means that swift,clang read from llvm's in-memory file system
virtualize_frameworks = "apple.virtualize_frameworks",
Copy link
Contributor

Choose a reason for hiding this comment

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

If there any reason why we treat it as a feature? Could we simply delete the old way to simplify the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's easier to iterate on code that's behind a feautre. This and we don't want to disrupt the old code path and may roll this out as an a/b test. Probably longer term we'd want to remove the useage of frameworks altogether

Copy link
Contributor Author

Choose a reason for hiding this comment

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

( that is, no remove the "frameworks" as a feature )

rules/library.bzl Outdated Show resolved Hide resolved
rules/library.bzl Outdated Show resolved Hide resolved
@jerrymarino
Copy link
Contributor Author

Thanks again for all the comments on the PR - making another pass to cleanup all of your suggestions 🙏 🥳

@gyfelton regarding the tests, we might be able to come up with some sort of test cases, my plan is to run the existing examples with the feature on - we might need to spin up more .github actions. The feature shouldn't impact any other projects if they don't enable the feature - which is another benefit of making it a feature!

@jerrymarino jerrymarino enabled auto-merge (squash) July 21, 2021 00:43
Add the ability to virtualize the framework structure. swift and clang
compile as frameworks but the files don't move and we load them via VFS.
The VFS is llvm's in-memory file system declared by JSON. VFS is already
in use but this uses it in a very different way.

This fixes many issues:
1. we don't hit O(n) deps includes - removing thousands of framework
search paths
2. we don't have to "clean" frameworks. This feature added quite a bit
of overhead and isn't necesary since it's declarative
3. imports are fully again. traditionally a build system uses -F on a
build directory. This causes problems with reproducible builds.

It cut clean build time in half in a big hybrid app from rules_ios
baseline. More interestingly, hot top level compiler invocations are
down nearly .5 orders of magnitude.

Remaining tasks:
- address xcodeproj integration
- duplicate test suite to run with this on/off
- address xcframework imports ( right now we're using -F )

Relates to: #211
@jerrymarino jerrymarino force-pushed the jmarino/starlark_virtual_frameworks_rebased branch from 07c2a6a to 3396e48 Compare July 21, 2021 00:48
@jerrymarino jerrymarino force-pushed the jmarino/starlark_virtual_frameworks_rebased branch from 7b1d30a to d929aa6 Compare July 21, 2021 01:19
This required adding a way to build ios_application deps as a framework.
If this feature is on, the apps need to have it set since they don't
build as a framework

Note that the line removed was always true so simplify it.
@jerrymarino jerrymarino force-pushed the jmarino/starlark_virtual_frameworks_rebased branch from 313ae5d to 24b928a Compare July 21, 2021 02:28
@jerrymarino jerrymarino enabled auto-merge (squash) July 21, 2021 02:46
@jerrymarino jerrymarino merged commit 884a44d into master Jul 21, 2021
@jerrymarino jerrymarino deleted the jmarino/starlark_virtual_frameworks_rebased branch July 21, 2021 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants