Skip to content

Commit

Permalink
Switch to static binary
Browse files Browse the repository at this point in the history
This now uses https://github.com/keith/StaticInternalSwiftSyntaxParser
instead of trying to use a dylib

Fixes #2
  • Loading branch information
keith committed Feb 10, 2022
1 parent 02e2a64 commit 37afcc5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

This repo provides a bazel target for
[`SwiftSyntax`](https://github.com/apple/swift-syntax). Most importantly
it handles vendoring `lib_InternalSwiftSyntaxParser` so your tool
doesn't depend on the specific Xcode path (or version) of your users.
it handles vendoring `lib_InternalSwiftSyntaxParser` as a static library
so your tool doesn't depend on a specific Xcode.app path or version.

## Usage

1. Make sure you've setup
[`rules_swift`](https://github.com/bazelbuild/rules_swift). Then add
this to your `WORKSPACE`
[`rules_apple`](https://github.com/bazelbuild/rules_apple)
2. Go to the [releases
page](https://github.com/keith/swift-syntax-bazel/releases) to grab
the snippet for the Xcode version you want
the WORKSPACE snippet for the Xcode version you're using
3. Add this target to your `deps`:

```bzl
Expand All @@ -31,14 +30,7 @@ binary would end up with a `rpath` like this:
```

This meant if you used a remote bazel cache in your builds, everyone's
Xcode path would have to match for this to work correctly. With this
repo, and using bazel's
[`cc_import`](https://docs.bazel.build/versions/main/be/c-cpp.html#cc_import)
to depend on the library, you end up with a `rpath` that is relative,
and points into bazel's execroot:

```
@loader_path/../../_solib_darwin_x86_64/_U@com_Ugithub_Ukeith_Uswift_Usyntax_S_S_Clibrary___U
```

Meaning it will be portable across machines.
Xcode path would have to match for this to work correctly. This repo
links [a static
binary](https://github.com/keith/StaticInternalSwiftSyntaxParser) for
`lib_InternalSwiftSyntaxParser` instead.
9 changes: 3 additions & 6 deletions SwiftSyntax.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ cc_library(
tags = ["swift_module"],
)

cc_import(
name = "library",
shared_library = "@com_github_keith_lib_internalswiftsyntaxparser//:library",
)

swift_library(
name = "SwiftSyntax",
srcs = glob(["Sources/SwiftSyntax/**/*.swift"]),
module_name = "SwiftSyntax",
private_deps = ["_CSwiftSyntax"] + select({
"@platforms//os:macos": ["library"],
"@platforms//os:macos": [
"@StaticInternalSwiftSyntaxParser//:lib_InternalSwiftSyntaxParser",
],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
Expand Down
26 changes: 15 additions & 11 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ def swift_syntax_deps():
if not native.existing_rule("build_bazel_rules_swift"):
fail("error: this depends on rules_swift but that wasn't setup")

if not native.existing_rule("build_bazel_rules_apple"):
fail("error: this depends on rules_apple but that wasn't setup")

http_archive(
name = "com_github_keith_lib_internalswiftsyntaxparser",
sha256 = "085083c1c2a2d1f9f5e46c827aaf1f3e46dfb92dd4d9c298c7255dcb6a573ab9",
url = "https://github.com/keith/lib_InternalSwiftSyntaxParser/releases/download/13.0.13A233/lib_InternalSwiftSyntaxParser.dylib.zip",
name = "StaticInternalSwiftSyntaxParser",
url = "https://github.com/keith/StaticInternalSwiftSyntaxParser/releases/download/5.5.2/lib_InternalSwiftSyntaxParser.xcframework.zip",
sha256 = "96bbc9ab4679953eac9ee46778b498cb559b8a7d9ecc658e54d6679acfbb34b8",
build_file_content = """
filegroup(
name = "library",
srcs = ["lib_InternalSwiftSyntaxParser.dylib"],
visibility = ["@com_github_keith_swift_syntax//:__pkg__"],
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_static_framework_import")
apple_static_framework_import(
name = "lib_InternalSwiftSyntaxParser",
framework_imports = ["lib_InternalSwiftSyntaxParser.xcframework/macos-arm64_x86_64/lib_InternalSwiftSyntaxParser.framework/lib_InternalSwiftSyntaxParser"],
visibility = ["//visibility:public"],
)
""",
)

http_archive(
name = "com_github_keith_swift_syntax",
build_file = "@com_github_keith_swift_syntax_bazel//:SwiftSyntax.BUILD",
sha256 = "ad7ba9d6647d2155c597144545cb7d6f7089ffbe50c467c31bbb946a27df4b6b",
strip_prefix = "swift-syntax-cf40be70deaf4ce7d44eb1a7e14299c391e2363f",
# Point in time from the release/5.5 branch, should be updated to the tag once it exists
url = "https://github.com/apple/swift-syntax/archive/cf40be70deaf4ce7d44eb1a7e14299c391e2363f.tar.gz",
sha256 = "39b5f08e3691df7b2c7c82b787e5ecc9c2b9e9cc69e7355cc6885ad6cee633b7",
strip_prefix = "swift-syntax-0.50500.0",
url = "https://github.com/apple/swift-syntax/archive/refs/tags/0.50500.0.tar.gz",
)

0 comments on commit 37afcc5

Please sign in to comment.