Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ common --ios_simulator_version="18.6"

# rules_swift flags migration
# --swiftcopt and --host_swiftcopt are deprecated
common --flag_alias=swiftcopt=@build_bazel_rules_swift//swift:copt
common --flag_alias=host_swiftcopt=@build_bazel_rules_swift//swift:exec_copt
common --flag_alias=swiftcopt=@rules_swift//swift:copt
common --flag_alias=host_swiftcopt=@rules_swift//swift:exec_copt
common --swiftcopt=-whole-module-optimization
common --host_swiftcopt=-whole-module-optimization

Expand Down
8 changes: 4 additions & 4 deletions Example/HelloWorld/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template_rule")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application", "ios_unit_test")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application", "macos_command_line_application", "macos_unit_test")
load("@build_bazel_rules_apple//apple:watchos.bzl", "watchos_application", "watchos_extension", "watchos_unit_test")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_interop_hint", "swift_library")
load("@rules_apple//apple:ios.bzl", "ios_application", "ios_unit_test")
load("@rules_apple//apple:macos.bzl", "macos_application", "macos_command_line_application", "macos_unit_test")
load("@rules_apple//apple:watchos.bzl", "watchos_application", "watchos_extension", "watchos_unit_test")
load("@rules_swift//swift:swift.bzl", "swift_interop_hint", "swift_library")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@sourcekit_bazel_bsp//rules:setup_sourcekit_bsp.bzl", "setup_sourcekit_bsp")
load("//tools:apple.bzl", "IOS_MINIMUM_OS_VERSION", "WATCHOS_MINIMUM_OS_VERSION", "MACOS_MINIMUM_OS_VERSION")
Expand Down
4 changes: 1 addition & 3 deletions Example/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ local_path_override(
bazel_dep(
name = "rules_swift",
version = "3.3.0",
repo_name = "build_bazel_rules_swift",
)

bazel_dep(
name = "rules_apple",
version = "4.3.2",
repo_name = "build_bazel_rules_apple",
)

bazel_dep(name = "apple_support", version = "1.24.5", repo_name = "build_bazel_apple_support")
bazel_dep(name = "apple_support", version = "1.24.5")
bazel_dep(name = "rules_cc", version = "0.2.16")
bazel_dep(name = "aspect_bazel_lib", version = "2.13.0")
2 changes: 1 addition & 1 deletion Example/scripts/lldb_launch_and_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ EOF
# We need --remote_download_regex because the files that lldb needs won't usually be downloaded by Bazel
# when using flags like --remote_download_toplevel and the such.
ADDITIONAL_FLAGS+=("--remote_download_regex=.*\.indexstore/.*|.*\.(a|cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|yaml)$")
ADDITIONAL_FLAGS+=("--@build_bazel_rules_apple//apple/build_settings:ios_device=${SIMULATOR_INFO}")
ADDITIONAL_FLAGS+=("--@rules_apple//apple/build_settings:ios_device=${SIMULATOR_INFO}")

# Remove the default lldbinit file created by rules_xcodeproj if it exists.
# This prevents Xcode details from leaking over to our builds.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The next step is to integrate sourcekit-bazel-bsp with your project:
bazel_dep(name = "sourcekit_bazel_bsp", version = "0.5.0", repo_name = "sourcekit_bazel_bsp")
```

- Define a `setup_sourcekit_bsp` rule in a BUILD.bazel file of your choice and [configure it](rules/setup_sourcekit_bsp.bzl#L86) for your desired setup:
- Define a `setup_sourcekit_bsp` rule in a BUILD.bazel file of your choice and [configure it](rules/setup_sourcekit_bsp.bzl#L89) for your desired setup:

```python
load("@sourcekit_bazel_bsp//rules:setup_sourcekit_bsp.bzl", "setup_sourcekit_bsp")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ final class PrepareHandler {
platform: labelToBuild.topLevelParentConfig.platform,
cpuArch: labelToBuild.topLevelParentConfig.cpuArch,
devDir: initializedConfig.devDir,
xcodeVersion: initializedConfig.xcodeVersion
xcodeVersion: initializedConfig.xcodeVersion,
appleSupportRepoName: initializedConfig.baseConfig.appleSupportRepoName
)
argsToLabelsMap[args, default: []].append(labelToBuild.label)
}
Expand Down Expand Up @@ -200,7 +201,8 @@ final class PrepareHandler {
platform: String,
cpuArch: String,
devDir: String,
xcodeVersion: String
xcodeVersion: String,
appleSupportRepoName: String
) -> [String] {
// As of writing, Bazel does not provides a "build X as if it were a child of Y" flag.
// This means that to compile individual libraries accurately, we need to replicate
Expand All @@ -223,7 +225,7 @@ final class PrepareHandler {
return "cpus"
}()
return [
"--platforms=@build_bazel_apple_support//platforms:\(friendlyPlatName)_\(cpuArch)",
"--platforms=@\(appleSupportRepoName)//platforms:\(friendlyPlatName)_\(cpuArch)",
"--\(friendlyPlatName)_\(cpuFlagName)=\(cpuArch)",
"--apple_platform_type=\(friendlyPlatName)",
"--apple_split_cpu=\(cpuArch)",
Expand Down
5 changes: 4 additions & 1 deletion Sources/SourceKitBazelBSP/Server/BaseServerConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ package struct BaseServerConfig: Equatable {
let dependencyRulesToDiscover: [DependencyRuleType]
let topLevelTargetsToExclude: [String]
let dependencyTargetsToExclude: [String]
let appleSupportRepoName: String

package init(
bazelWrapper: String,
Expand All @@ -44,7 +45,8 @@ package struct BaseServerConfig: Equatable {
topLevelRulesToDiscover: [TopLevelRuleType] = TopLevelRuleType.allCases,
dependencyRulesToDiscover: [DependencyRuleType] = DependencyRuleType.allCases,
topLevelTargetsToExclude: [String] = [],
dependencyTargetsToExclude: [String] = []
dependencyTargetsToExclude: [String] = [],
appleSupportRepoName: String = "apple_support"
) {
self.bazelWrapper = bazelWrapper
self.targets = targets
Expand All @@ -55,5 +57,6 @@ package struct BaseServerConfig: Equatable {
self.dependencyRulesToDiscover = dependencyRulesToDiscover
self.topLevelTargetsToExclude = topLevelTargetsToExclude
self.dependencyTargetsToExclude = dependencyTargetsToExclude
self.appleSupportRepoName = appleSupportRepoName
}
}
9 changes: 8 additions & 1 deletion Sources/sourcekit-bazel-bsp/Commands/Serve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ struct Serve: ParsableCommand {
)
var dependencyTargetToExclude: [String] = []

@Option(
help:
"The name of the apple_support external repository in your workspace. Change this if using a different name."
)
var appleSupportRepoName: String = "apple_support"

func run() throws {
logger.info("`serve` invoked, initializing BSP server...")

Expand All @@ -98,7 +104,8 @@ struct Serve: ParsableCommand {
topLevelRulesToDiscover: topLevelRulesToDiscover,
dependencyRulesToDiscover: dependencyRulesToDiscover,
topLevelTargetsToExclude: topLevelTargetToExclude,
dependencyTargetsToExclude: dependencyTargetToExclude
dependencyTargetsToExclude: dependencyTargetToExclude,
appleSupportRepoName: appleSupportRepoName
)

logger.debug("Initializing BSP with targets: \(targets)")
Expand Down
7 changes: 7 additions & 0 deletions rules/setup_sourcekit_bsp.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def _setup_sourcekit_bsp_impl(ctx):
if files_to_watch:
bsp_config_argv.append("--files-to-watch")
bsp_config_argv.append(files_to_watch)
if ctx.attr.apple_support_repo_name:
bsp_config_argv.append("--apple-support-repo-name")
bsp_config_argv.append(ctx.attr.apple_support_repo_name)
ctx.actions.expand_template(
template = ctx.file._bsp_config_template,
output = rendered_bsp_config,
Expand Down Expand Up @@ -146,5 +149,9 @@ setup_sourcekit_bsp = rule(
doc = "Instead of attempting to build targets individually, build the top-level parent. If your project contains build_test targets for your individual libraries and you're passing them as the top-level targets for the BSP, you can use this flag to build those targets directly for better predictability and caching.",
default = False,
),
"apple_support_repo_name": attr.string(
doc = "The name of the apple_support external repository in your workspace. Change this if using a different name.",
default = "apple_support",
),
},
)
Loading