-
Notifications
You must be signed in to change notification settings - Fork 27
Sets up setup executable rule for integrating into Bazel projects #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
Merged
rockbruno
merged 15 commits into
spotify:main
from
maxwellE:maxwelle/add-bazel-configs-to-tool-code
Aug 19, 2025
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c8b56b3
start
maxwellE 6be2312
More updates
maxwellE cec7f98
more updates
maxwellE 93af02d
add bazel build validation
maxwellE 8d1da3f
more updates
maxwellE e294e1f
more updates
maxwellE 9f58799
more updates
maxwellE 9bbf9c7
gitignore
maxwellE 03b5af1
working
maxwellE ca91302
more updates
maxwellE c0672f5
symlink
maxwellE ab405c9
more deps
maxwellE 4749ea2
update readme
maxwellE d56c5f0
add apple support
maxwellE c195c6a
mod tidy
maxwellE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| common --enable_bzlmod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 7.4.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,5 @@ Package.resolved | |
| .*.sw? | ||
| __pycache__ | ||
| /.vscode/ | ||
| swift-cmark | ||
| swift-cmark | ||
| bazel-* | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| bazel_dep(name = "rules_swift", version = "3.1.1", repo_name = "build_bazel_rules_swift") | ||
| bazel_dep(name = "rules_swift_package_manager", version = "1.3.0") | ||
| bazel_dep(name = "rules_apple", version = "4.1.2", repo_name = "build_bazel_rules_apple") | ||
|
|
||
| swift_deps = use_extension( | ||
| "@rules_swift_package_manager//:extensions.bzl", | ||
| "swift_deps", | ||
| ) | ||
| swift_deps.from_package( | ||
| resolved = "//:Package.resolved", | ||
| swift = "//:Package.swift", | ||
| ) | ||
| use_repo( | ||
| swift_deps, | ||
| "swift_package", | ||
| "swiftpkg_sourcekit_lsp", | ||
| "swiftpkg_swift_argument_parser", | ||
| "swiftpkg_swift_protobuf", | ||
| # The name of the Swift package repositories will be added to this declaration in step 4 after | ||
| # running `bazel mod tidy`. | ||
| # NOTE: The name of the Bazel external repository for a Swift package is `swiftpkg_xxx` where | ||
| # `xxx` is the Swift package identity, lowercase, with punctuation replaced by `hyphen`. For | ||
| # example, the repository name for apple/swift-nio is `swiftpkg_swift_nio`. | ||
| ) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") | ||
|
|
||
| swift_library( | ||
| name = "BazelProtobufBindings", | ||
| srcs = glob(["**/*.swift"], allow_empty = False), | ||
| module_name = "BazelProtobufBindings", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "@swiftpkg_swift_protobuf//:SwiftProtobuf", | ||
| ], | ||
| package_name = "sourcekit-bazel-bsp", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") | ||
|
|
||
| swift_library( | ||
| name = "SourceKitBazelBSP", | ||
| srcs = glob(["**/*.swift"], allow_empty = False), | ||
| module_name = "SourceKitBazelBSP", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//Sources/BazelProtobufBindings", | ||
| "@swiftpkg_sourcekit_lsp//:BuildServerProtocol", | ||
| "@swiftpkg_sourcekit_lsp//:LSPBindings", | ||
| ], | ||
| package_name = "sourcekit-bazel-bsp", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary") | ||
|
|
||
| swift_binary( | ||
| name = "sourcekit-bazel-bsp", | ||
| srcs = glob(["**/*.swift"], allow_empty = False), | ||
| deps = [ | ||
| "//Sources/SourceKitBazelBSP", | ||
| "@swiftpkg_swift_argument_parser//:ArgumentParser", | ||
| "@swiftpkg_swift_protobuf//:SwiftProtobuf", | ||
| ], | ||
| visibility = ["//visibility:public"], | ||
| package_name = "sourcekit-bazel-bsp", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| exports_files([ | ||
| "bsp_config.json.tpl", | ||
| "setup_sourcekit_bsp.sh.tpl", | ||
| ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "name": "sourcekit-bazel-bsp", | ||
| "version": "0.0.1", | ||
| "bspVersion": "2.2.0", | ||
| "languages": [ | ||
| "c", | ||
| "cpp", | ||
| "objective-c", | ||
| "objective-cpp", | ||
| "swift" | ||
| ], | ||
| "argv": [%argv%] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| def _setup_sourcekit_bsp_impl(ctx): | ||
| rendered_bsp_config = ctx.actions.declare_file("config.json") | ||
| bsp_config_argv = [ | ||
| ".bsp/sourcekit-bazel-bsp", | ||
| "serve", | ||
| ] | ||
| for target in ctx.attr.targets: | ||
| bsp_config_argv.append("--target") | ||
| bsp_config_argv.append(target.label) | ||
| bsp_config_argv.append("--bazel-wrapper") | ||
| bsp_config_argv.append(ctx.attr.bazel_wrapper) | ||
| for index_flag in ctx.attr.index_flags: | ||
| bsp_config_argv.append("--index-flag") | ||
| bsp_config_argv.append(index_flag) | ||
| for files_to_watch in ctx.attr.files_to_watch: | ||
| bsp_config_argv.append("--files-to-watch") | ||
| bsp_config_argv.append(files_to_watch) | ||
| ctx.actions.expand_template( | ||
| template = ctx.file._bsp_config_template, | ||
| output = rendered_bsp_config, | ||
| substitutions = { | ||
| "%argv%": ", ".join(["\"%s\"" % arg for arg in bsp_config_argv]), | ||
| }, | ||
| ) | ||
| executable = ctx.actions.declare_file("setup_sourcekit_bsp.sh") | ||
| ctx.actions.expand_template( | ||
| template = ctx.file._setup_sourcekit_bsp_script, | ||
| is_executable = True, | ||
| output = executable, | ||
| substitutions = { | ||
| "%bsp_config_path%": rendered_bsp_config.short_path, | ||
| "%sourcekit_bazel_bsp_path%": ctx.executable._sourcekit_bazel_bsp_tool.short_path, | ||
| }, | ||
| ) | ||
| tools_runfiles = ctx.runfiles( | ||
| files = [ | ||
| ctx.executable._sourcekit_bazel_bsp_tool, | ||
| rendered_bsp_config, | ||
| ], | ||
| ) | ||
| return DefaultInfo( | ||
| executable = executable, | ||
| files = depset(direct = [executable]), | ||
| runfiles = tools_runfiles, | ||
| ) | ||
|
|
||
|
|
||
| setup_sourcekit_bsp = rule( | ||
| implementation = _setup_sourcekit_bsp_impl, | ||
| executable = True, | ||
| doc = "Sets up the sourcekit-bazel-bsp in the current workspace using the provided configuration.", | ||
| attrs = { | ||
| "_bsp_config_template": attr.label( | ||
| doc = "The template for the sourcekit-bazel-bsp configuration.", | ||
| default = "//rules:bsp_config.json.tpl", | ||
| allow_single_file = True, | ||
| ), | ||
| "_setup_sourcekit_bsp_script": attr.label( | ||
| doc = "The script for setting up the sourcekit-bazel-bsp.", | ||
| default = "//rules:setup_sourcekit_bsp.sh.tpl", | ||
| allow_single_file = True, | ||
| ), | ||
| "_sourcekit_bazel_bsp_tool": attr.label( | ||
| doc = "The sourcekit-bazel-bsp binary.", | ||
| default = "//Sources/sourcekit-bazel-bsp", | ||
| cfg = "exec", | ||
| executable = True, | ||
| ), | ||
| "targets": attr.label_list( | ||
| doc = "The targets to set up the sourcekit-bazel-bsp for.", | ||
| mandatory = True, | ||
| ), | ||
| "bazel_wrapper": attr.string( | ||
| doc = "The bazel wrapper to use.", | ||
| default = "bazel", | ||
| ), | ||
| "index_flags": attr.string_list( | ||
| doc = "The index flags to use.", | ||
| ), | ||
| "files_to_watch": attr.string_list( | ||
| doc = "The files to watch.", | ||
| ), | ||
| }, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| sourcekit_bazel_bsp_path="%sourcekit_bazel_bsp_path%" | ||
| bsp_config_path="%bsp_config_path%" | ||
|
|
||
| cp "${bsp_config_path}" "$BUILD_WORKSPACE_DIRECTORY/.bsp/config.json" | ||
| cp "${sourcekit_bazel_bsp_path}" "$BUILD_WORKSPACE_DIRECTORY/.bsp/sourcekit-bazel-bsp" | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.