diff --git a/Example/.bazelrc b/Example/.bazelrc index abda0ddb..e396b2a6 100644 --- a/Example/.bazelrc +++ b/Example/.bazelrc @@ -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 diff --git a/Example/HelloWorld/BUILD b/Example/HelloWorld/BUILD index c55543aa..0ee96364 100644 --- a/Example/HelloWorld/BUILD +++ b/Example/HelloWorld/BUILD @@ -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") diff --git a/Example/MODULE.bazel b/Example/MODULE.bazel index 02899d0e..1f6972ed 100644 --- a/Example/MODULE.bazel +++ b/Example/MODULE.bazel @@ -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") \ No newline at end of file diff --git a/Example/scripts/lldb_launch_and_debug.sh b/Example/scripts/lldb_launch_and_debug.sh index f4c22033..5167030d 100755 --- a/Example/scripts/lldb_launch_and_debug.sh +++ b/Example/scripts/lldb_launch_and_debug.sh @@ -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. diff --git a/README.md b/README.md index 118bd13f..0e93c1b8 100644 --- a/README.md +++ b/README.md @@ -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") diff --git a/Sources/SourceKitBazelBSP/RequestHandlers/PrepareHandler.swift b/Sources/SourceKitBazelBSP/RequestHandlers/PrepareHandler.swift index 637038a8..0acbf31e 100644 --- a/Sources/SourceKitBazelBSP/RequestHandlers/PrepareHandler.swift +++ b/Sources/SourceKitBazelBSP/RequestHandlers/PrepareHandler.swift @@ -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) } @@ -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 @@ -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)", diff --git a/Sources/SourceKitBazelBSP/Server/BaseServerConfig.swift b/Sources/SourceKitBazelBSP/Server/BaseServerConfig.swift index 238f8d00..14d15a33 100644 --- a/Sources/SourceKitBazelBSP/Server/BaseServerConfig.swift +++ b/Sources/SourceKitBazelBSP/Server/BaseServerConfig.swift @@ -34,6 +34,7 @@ package struct BaseServerConfig: Equatable { let dependencyRulesToDiscover: [DependencyRuleType] let topLevelTargetsToExclude: [String] let dependencyTargetsToExclude: [String] + let appleSupportRepoName: String package init( bazelWrapper: String, @@ -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 @@ -55,5 +57,6 @@ package struct BaseServerConfig: Equatable { self.dependencyRulesToDiscover = dependencyRulesToDiscover self.topLevelTargetsToExclude = topLevelTargetsToExclude self.dependencyTargetsToExclude = dependencyTargetsToExclude + self.appleSupportRepoName = appleSupportRepoName } } diff --git a/Sources/sourcekit-bazel-bsp/Commands/Serve.swift b/Sources/sourcekit-bazel-bsp/Commands/Serve.swift index ca2ae80d..d03cd635 100644 --- a/Sources/sourcekit-bazel-bsp/Commands/Serve.swift +++ b/Sources/sourcekit-bazel-bsp/Commands/Serve.swift @@ -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...") @@ -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)") diff --git a/rules/setup_sourcekit_bsp.bzl b/rules/setup_sourcekit_bsp.bzl index fb260b6d..dc012074 100644 --- a/rules/setup_sourcekit_bsp.bzl +++ b/rules/setup_sourcekit_bsp.bzl @@ -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, @@ -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", + ), }, )