From 9df26453dbf0ddb42e5e2dd8c1790683208fba1f Mon Sep 17 00:00:00 2001 From: Logan Shire Date: Sun, 5 Jan 2025 14:02:54 -0300 Subject: [PATCH 1/5] Language mode, experimental features, and upcoming features working --- examples/grpc_2_example/.bazelrc | 0 examples/grpc_2_example/BUILD.bazel | 0 examples/grpc_2_example/MODULE.bazel | 67 ++++++++++++++++++++++ examples/grpc_2_example/Package.resolved | 14 +++++ examples/grpc_2_example/Package.swift | 16 ++++++ examples/grpc_2_example/do_test | 16 ++++++ swiftpkg/internal/pkginfos.bzl | 14 ++++- swiftpkg/internal/swiftpkg_build_files.bzl | 35 +++++++++-- 8 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 examples/grpc_2_example/.bazelrc create mode 100644 examples/grpc_2_example/BUILD.bazel create mode 100644 examples/grpc_2_example/MODULE.bazel create mode 100644 examples/grpc_2_example/Package.resolved create mode 100644 examples/grpc_2_example/Package.swift create mode 100755 examples/grpc_2_example/do_test diff --git a/examples/grpc_2_example/.bazelrc b/examples/grpc_2_example/.bazelrc new file mode 100644 index 000000000..e69de29bb diff --git a/examples/grpc_2_example/BUILD.bazel b/examples/grpc_2_example/BUILD.bazel new file mode 100644 index 000000000..e69de29bb diff --git a/examples/grpc_2_example/MODULE.bazel b/examples/grpc_2_example/MODULE.bazel new file mode 100644 index 000000000..acc569f99 --- /dev/null +++ b/examples/grpc_2_example/MODULE.bazel @@ -0,0 +1,67 @@ +""" +Example module for grpc + proto target generation. +""" + +# rules_go + +bazel_dep(name = "rules_go", version = "0.50.1") + +go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") +go_sdk.host() + +# gazelle + +bazel_dep(name = "gazelle", version = "0.40.0") + +# protobuf + +bazel_dep(name = "protobuf", version = "29.0") + +# rules_proto + +bazel_dep(name = "rules_proto", version = "7.0.2") + +# apple_support + +bazel_dep(name = "apple_support", version = "1.17.1") + +# rules_swift + +bazel_dep(name = "rules_swift", version = "2.2.2") + +# rules_swift_package_manager + +bazel_dep( + name = "rules_swift_package_manager", + version = "0.0.0", +) +local_path_override( + module_name = "rules_swift_package_manager", + path = "../..", +) + +# swift_deps START +swift_deps = use_extension( + "@rules_swift_package_manager//:extensions.bzl", + "swift_deps", +) +swift_deps.from_package( + declare_swift_deps_info = True, + resolved = "//:Package.resolved", + swift = "//:Package.swift", +) +use_repo( + swift_deps, + "swift_deps_info", + "swift_package", + "swiftpkg_testpackage", +) +# swift_deps END + +# rules_apple + +bazel_dep(name = "rules_apple", version = "3.16.1") + +# rules_xcodeproj + +bazel_dep(name = "rules_xcodeproj", version = "2.10.0") diff --git a/examples/grpc_2_example/Package.resolved b/examples/grpc_2_example/Package.resolved new file mode 100644 index 000000000..69c19ee7b --- /dev/null +++ b/examples/grpc_2_example/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "testpackage", + "kind" : "remoteSourceControl", + "location" : "https://github.com/AttilaTheFun/TestPackage.git", + "state" : { + "branch" : "main", + "revision" : "ceed76102796c85dfa51f3e79a8c257ade1a707a" + } + } + ], + "version" : 2 +} diff --git a/examples/grpc_2_example/Package.swift b/examples/grpc_2_example/Package.swift new file mode 100644 index 000000000..17d70285d --- /dev/null +++ b/examples/grpc_2_example/Package.swift @@ -0,0 +1,16 @@ +// swift-tools-version: 5.8 + +import PackageDescription + +let package = Package( + name: "grpc_example", + dependencies: [ + // These are the versions used by rules_swift + // .package(url: "https://github.com/grpc/grpc-swift-extras", exact: "1.0.0-beta.2"), + // .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"), // Required by grpc-swift-extras @ 1.0.0-beta.2 + // .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"), // Required by grpc-swift @ 2.0.0-beta.2 + // .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"), // Required by grpc-swift @ 2.0.0-beta.2 + // .package(url: "https://github.com/apple/swift-protobuf.git", exact: "1.28.1"), // Required by grpc-swift @ 2.0.0-beta.2 + .package(url: "https://github.com/AttilaTheFun/TestPackage.git", branch: "main") + ] +) diff --git a/examples/grpc_2_example/do_test b/examples/grpc_2_example/do_test new file mode 100755 index 000000000..809bb324c --- /dev/null +++ b/examples/grpc_2_example/do_test @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +# Use the Bazel binary specified by the integration test. Otherise, fall back +# to bazel. +bazel="${BIT_BAZEL_BINARY:-bazel}" + +# Generate Swift external deps and update build files +"${bazel}" run //:tidy + +# Ensure that it builds and tests pass +"${bazel}" test //... + +# Ensure that Gazelle doesn't make any changes +"${bazel}" run //:update_build_files -- --mode=diff diff --git a/swiftpkg/internal/pkginfos.bzl b/swiftpkg/internal/pkginfos.bzl index 08aa9a413..49f45ad09 100644 --- a/swiftpkg/internal/pkginfos.bzl +++ b/swiftpkg/internal/pkginfos.bzl @@ -1436,25 +1436,35 @@ def _new_swift_settings(build_settings): """ defines = [] unsafe_flags = [] + language_modes = [] experimental_features = [] + upcoming_features = [] for bs in build_settings: if bs.kind == build_setting_kinds.define: defines.append(bs) elif bs.kind == build_setting_kinds.unsafe_flags: unsafe_flags.append(bs) + elif bs.kind == build_setting_kinds.language_modes: + language_modes.append(bs) elif bs.kind == build_setting_kinds.experimental_features: experimental_features.append(bs) + elif bs.kind == build_setting_kinds.upcoming_features: + upcoming_features.append(bs) else: # We do not recognize the setting. pass if len(defines) == 0 and \ len(unsafe_flags) == 0 and \ - len(experimental_features) == 0: + len(language_modes) == 0 and \ + len(experimental_features) == 0 and \ + len(upcoming_features) == 0: return None return struct( defines = defines, unsafe_flags = unsafe_flags, + language_modes = language_modes, experimental_features = experimental_features, + upcoming_features = upcoming_features, ) def _new_linker_settings(build_settings): @@ -1639,7 +1649,9 @@ build_setting_kinds = struct( linked_framework = "linkedFramework", linked_library = "linkedLibrary", unsafe_flags = "unsafeFlags", + language_modes = "swiftLanguageMode", experimental_features = "enableExperimentalFeature", + upcoming_features = "enableUpcomingFeature", ) # MARK: - API Definition diff --git a/swiftpkg/internal/swiftpkg_build_files.bzl b/swiftpkg/internal/swiftpkg_build_files.bzl index f16a12560..a754ad094 100644 --- a/swiftpkg/internal/swiftpkg_build_files.bzl +++ b/swiftpkg/internal/swiftpkg_build_files.bzl @@ -114,9 +114,11 @@ def _swift_target_build_file(pkg_ctx, target): # Check if any of the sources indicate that the module will be used by # Objective-C code. If so, generate the bridge header file. + features = [] if target.swift_src_info.has_objc_directive and is_library_target: attrs["generates_header"] = True - attrs["features"] = ["swift.propagate_generated_module_map"] + feature = bzl_selects.new(value = "swift.propagate_generated_module_map") + features.append(feature) if target.swift_settings != None: if len(target.swift_settings.defines) > 0: @@ -132,11 +134,32 @@ def _swift_target_build_file(pkg_ctx, target): bzl_selects.new_from_build_setting(bs) for bs in target.swift_settings.unsafe_flags ])) - if len(target.swift_settings.experimental_features) > 0: - for bs in target.swift_settings.experimental_features: - copts.append("-enable-experimental-feature") - copts.extend(lists.flatten(bzl_selects.new_from_build_setting(bs))) - + for bs in target.swift_settings.language_modes: + for language_mode in lists.flatten(bzl_selects.new_from_build_setting(bs)): + new_language_mode = bzl_selects.new( + value = "swift.enable_v" + language_mode.value, + kind = language_mode.kind, + condition = language_mode.condition + ) + features.append(new_language_mode) + for bs in target.swift_settings.experimental_features: + for experimental_feature in lists.flatten(bzl_selects.new_from_build_setting(bs)): + new_experimental_feature = bzl_selects.new( + value = "swift.experimental." + experimental_feature.value, + kind = experimental_feature.kind, + condition = experimental_feature.condition + ) + features.append(new_experimental_feature) + for bs in target.swift_settings.upcoming_features: + for upcoming_feature in lists.flatten(bzl_selects.new_from_build_setting(bs)): + new_upcoming_feature = bzl_selects.new( + value = "swift.upcoming." + upcoming_feature.value, + kind = upcoming_feature.kind, + condition = upcoming_feature.condition + ) + features.append(new_upcoming_feature) + if len(features) > 0: + attrs["features"] = bzl_selects.to_starlark(features, mutually_inclusive = True) if len(copts) > 0: attrs["copts"] = bzl_selects.to_starlark(copts, mutually_inclusive = True) From 8927163105c924de37f2046b59532dceb8562de1 Mon Sep 17 00:00:00 2001 From: Logan Shire Date: Sun, 5 Jan 2025 17:21:54 -0300 Subject: [PATCH 2/5] Tidy --- examples/grpc_2_example/Package.resolved | 14 -------------- .../.bazelrc | 0 .../BUILD.bazel | 0 .../MODULE.bazel | 2 +- examples/swift_protobuf_example/Package.resolved | 15 +++++++++++++++ .../Package.swift | 7 +++---- .../do_test | 0 7 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 examples/grpc_2_example/Package.resolved rename examples/{grpc_2_example => swift_protobuf_example}/.bazelrc (100%) rename examples/{grpc_2_example => swift_protobuf_example}/BUILD.bazel (100%) rename examples/{grpc_2_example => swift_protobuf_example}/MODULE.bazel (97%) create mode 100644 examples/swift_protobuf_example/Package.resolved rename examples/{grpc_2_example => swift_protobuf_example}/Package.swift (70%) rename examples/{grpc_2_example => swift_protobuf_example}/do_test (100%) diff --git a/examples/grpc_2_example/Package.resolved b/examples/grpc_2_example/Package.resolved deleted file mode 100644 index 69c19ee7b..000000000 --- a/examples/grpc_2_example/Package.resolved +++ /dev/null @@ -1,14 +0,0 @@ -{ - "pins" : [ - { - "identity" : "testpackage", - "kind" : "remoteSourceControl", - "location" : "https://github.com/AttilaTheFun/TestPackage.git", - "state" : { - "branch" : "main", - "revision" : "ceed76102796c85dfa51f3e79a8c257ade1a707a" - } - } - ], - "version" : 2 -} diff --git a/examples/grpc_2_example/.bazelrc b/examples/swift_protobuf_example/.bazelrc similarity index 100% rename from examples/grpc_2_example/.bazelrc rename to examples/swift_protobuf_example/.bazelrc diff --git a/examples/grpc_2_example/BUILD.bazel b/examples/swift_protobuf_example/BUILD.bazel similarity index 100% rename from examples/grpc_2_example/BUILD.bazel rename to examples/swift_protobuf_example/BUILD.bazel diff --git a/examples/grpc_2_example/MODULE.bazel b/examples/swift_protobuf_example/MODULE.bazel similarity index 97% rename from examples/grpc_2_example/MODULE.bazel rename to examples/swift_protobuf_example/MODULE.bazel index acc569f99..3a159e7ab 100644 --- a/examples/grpc_2_example/MODULE.bazel +++ b/examples/swift_protobuf_example/MODULE.bazel @@ -54,7 +54,7 @@ use_repo( swift_deps, "swift_deps_info", "swift_package", - "swiftpkg_testpackage", + "swiftpkg_swift_protobuf", ) # swift_deps END diff --git a/examples/swift_protobuf_example/Package.resolved b/examples/swift_protobuf_example/Package.resolved new file mode 100644 index 000000000..4e0eb3866 --- /dev/null +++ b/examples/swift_protobuf_example/Package.resolved @@ -0,0 +1,15 @@ +{ + "originHash" : "60cf222778a0e2535cb4ccd7a820166a4d250e6dc3852a8f320ba5948745e39f", + "pins" : [ + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "edb6ed4919f7756157fe02f2552b7e3850a538e5", + "version" : "1.28.1" + } + } + ], + "version" : 3 +} diff --git a/examples/grpc_2_example/Package.swift b/examples/swift_protobuf_example/Package.swift similarity index 70% rename from examples/grpc_2_example/Package.swift rename to examples/swift_protobuf_example/Package.swift index 17d70285d..6b1ba5f2f 100644 --- a/examples/grpc_2_example/Package.swift +++ b/examples/swift_protobuf_example/Package.swift @@ -1,16 +1,15 @@ -// swift-tools-version: 5.8 +// swift-tools-version: 6.0 import PackageDescription let package = Package( - name: "grpc_example", + name: "swift_protobuf_example", dependencies: [ // These are the versions used by rules_swift // .package(url: "https://github.com/grpc/grpc-swift-extras", exact: "1.0.0-beta.2"), // .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"), // Required by grpc-swift-extras @ 1.0.0-beta.2 // .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"), // Required by grpc-swift @ 2.0.0-beta.2 // .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"), // Required by grpc-swift @ 2.0.0-beta.2 - // .package(url: "https://github.com/apple/swift-protobuf.git", exact: "1.28.1"), // Required by grpc-swift @ 2.0.0-beta.2 - .package(url: "https://github.com/AttilaTheFun/TestPackage.git", branch: "main") + .package(url: "https://github.com/apple/swift-protobuf.git", exact: "1.28.1"), ] ) diff --git a/examples/grpc_2_example/do_test b/examples/swift_protobuf_example/do_test similarity index 100% rename from examples/grpc_2_example/do_test rename to examples/swift_protobuf_example/do_test From 8afb371a25567b5467c450708af2f33c69ebf90f Mon Sep 17 00:00:00 2001 From: Logan Shire Date: Sun, 5 Jan 2025 20:41:33 -0300 Subject: [PATCH 3/5] Address PR comments and update test --- examples/example_infos.bzl | 1 + examples/swift_protobuf_example/.bazelrc | 9 +++++++++ examples/swift_protobuf_example/BUILD.bazel | 11 +++++++++++ examples/swift_protobuf_example/MODULE.bazel | 17 ++++------------- examples/swift_protobuf_example/Package.swift | 4 ---- .../Sources/SwiftProtobufTest.swift | 1 + examples/swift_protobuf_example/do_test | 9 ++------- swiftpkg/tests/swiftpkg_build_files_tests.bzl | 19 ++++++++++++++----- 8 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 examples/swift_protobuf_example/Sources/SwiftProtobufTest.swift diff --git a/examples/example_infos.bzl b/examples/example_infos.bzl index 9931517d6..4325e5a5b 100644 --- a/examples/example_infos.bzl +++ b/examples/example_infos.bzl @@ -146,6 +146,7 @@ _macos_single_bazel_version_test_examples = [ "shake_ios_example", "snapkit_example", "stripe_example", + "swift_protobuf_example", "xcmetrics_example", "tca_example", "symlink_example", diff --git a/examples/swift_protobuf_example/.bazelrc b/examples/swift_protobuf_example/.bazelrc index e69de29bb..b5fc1b379 100644 --- a/examples/swift_protobuf_example/.bazelrc +++ b/examples/swift_protobuf_example/.bazelrc @@ -0,0 +1,9 @@ + +# Import Shared settings +import %workspace%/../../shared.bazelrc + +# Import CI settings. +import %workspace%/../../ci.bazelrc + +# Try to import a local.rc file; typically, written by CI +try-import %workspace%/../../local.bazelrc \ No newline at end of file diff --git a/examples/swift_protobuf_example/BUILD.bazel b/examples/swift_protobuf_example/BUILD.bazel index e69de29bb..54ccdfb9e 100644 --- a/examples/swift_protobuf_example/BUILD.bazel +++ b/examples/swift_protobuf_example/BUILD.bazel @@ -0,0 +1,11 @@ +load("@rules_swift//swift:swift.bzl", "swift_library") + +swift_library( + name = "swift_protobuf_test", + srcs = ["Sources/SwiftProtobufTest.swift"], + module_name = "SwiftProtobufTest", + visibility = ["//visibility:public"], + deps = [ + "@swiftpkg_swift_protobuf//:SwiftProtobuf", + ], +) diff --git a/examples/swift_protobuf_example/MODULE.bazel b/examples/swift_protobuf_example/MODULE.bazel index 3a159e7ab..a3c1f7e53 100644 --- a/examples/swift_protobuf_example/MODULE.bazel +++ b/examples/swift_protobuf_example/MODULE.bazel @@ -2,13 +2,14 @@ Example module for grpc + proto target generation. """ +# cgrindel_bazel_starlib + +bazel_dep(name = "cgrindel_bazel_starlib", version = "0.21.0") + # rules_go bazel_dep(name = "rules_go", version = "0.50.1") -go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") -go_sdk.host() - # gazelle bazel_dep(name = "gazelle", version = "0.40.0") @@ -40,7 +41,6 @@ local_path_override( path = "../..", ) -# swift_deps START swift_deps = use_extension( "@rules_swift_package_manager//:extensions.bzl", "swift_deps", @@ -56,12 +56,3 @@ use_repo( "swift_package", "swiftpkg_swift_protobuf", ) -# swift_deps END - -# rules_apple - -bazel_dep(name = "rules_apple", version = "3.16.1") - -# rules_xcodeproj - -bazel_dep(name = "rules_xcodeproj", version = "2.10.0") diff --git a/examples/swift_protobuf_example/Package.swift b/examples/swift_protobuf_example/Package.swift index 6b1ba5f2f..93fcd57b9 100644 --- a/examples/swift_protobuf_example/Package.swift +++ b/examples/swift_protobuf_example/Package.swift @@ -6,10 +6,6 @@ let package = Package( name: "swift_protobuf_example", dependencies: [ // These are the versions used by rules_swift - // .package(url: "https://github.com/grpc/grpc-swift-extras", exact: "1.0.0-beta.2"), - // .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"), // Required by grpc-swift-extras @ 1.0.0-beta.2 - // .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"), // Required by grpc-swift @ 2.0.0-beta.2 - // .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"), // Required by grpc-swift @ 2.0.0-beta.2 .package(url: "https://github.com/apple/swift-protobuf.git", exact: "1.28.1"), ] ) diff --git a/examples/swift_protobuf_example/Sources/SwiftProtobufTest.swift b/examples/swift_protobuf_example/Sources/SwiftProtobufTest.swift new file mode 100644 index 000000000..99b381c5b --- /dev/null +++ b/examples/swift_protobuf_example/Sources/SwiftProtobufTest.swift @@ -0,0 +1 @@ +import SwiftProtobuf \ No newline at end of file diff --git a/examples/swift_protobuf_example/do_test b/examples/swift_protobuf_example/do_test index 809bb324c..93f62acd1 100755 --- a/examples/swift_protobuf_example/do_test +++ b/examples/swift_protobuf_example/do_test @@ -6,11 +6,6 @@ set -o errexit -o nounset -o pipefail # to bazel. bazel="${BIT_BAZEL_BINARY:-bazel}" -# Generate Swift external deps and update build files -"${bazel}" run //:tidy +# Ensure that it builds +"${bazel}" build //... -# Ensure that it builds and tests pass -"${bazel}" test //... - -# Ensure that Gazelle doesn't make any changes -"${bazel}" run //:update_build_files -- --mode=diff diff --git a/swiftpkg/tests/swiftpkg_build_files_tests.bzl b/swiftpkg/tests/swiftpkg_build_files_tests.bzl index de7c889b7..822c150e8 100644 --- a/swiftpkg/tests/swiftpkg_build_files_tests.bzl +++ b/swiftpkg/tests/swiftpkg_build_files_tests.bzl @@ -156,10 +156,18 @@ _pkg_info = pkginfos.new( ], ), ), + pkginfos.new_build_setting( + kind = build_setting_kinds.language_modes, + values = ["6"], + ), pkginfos.new_build_setting( kind = build_setting_kinds.experimental_features, values = ["BuiltinModule"], ), + pkginfos.new_build_setting( + kind = build_setting_kinds.upcoming_features, + values = ["ExistentialAny"], + ), pkginfos.new_build_setting( kind = build_setting_kinds.unsafe_flags, values = ["-cross-module-optimization"], @@ -552,11 +560,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary") swift_binary( name = "SwiftExecutableTarget.rspm", - copts = [ - "-DSWIFT_PACKAGE", - "-enable-experimental-feature", - "BuiltinModule", - ] + select({ + copts = ["-DSWIFT_PACKAGE"] + select({ "@rules_swift_package_manager//config_settings/spm/platform:ios": ["-DFOOBAR"], "//conditions:default": [], }) + select({ @@ -566,6 +570,11 @@ swift_binary( "@rules_swift_package_manager//config_settings/spm/configuration:release": ["-cross-module-optimization"], "//conditions:default": [], }), + features = [ + "swift.enable_v6", + "swift.experimental.BuiltinModule", + "swift.upcoming.ExistentialAny", + ], module_name = "SwiftExecutableTarget", package_name = "MyPackage", srcs = ["Source/SwiftExecutableTarget/main.swift"], From b8ad51b915466d0af89975e428d4f53044559d11 Mon Sep 17 00:00:00 2001 From: Logan Shire Date: Sun, 5 Jan 2025 21:19:15 -0300 Subject: [PATCH 4/5] Fix repo name --- examples/swift_protobuf_example/BUILD.bazel | 2 +- examples/swift_protobuf_example/MODULE.bazel | 54 ++++++++++---------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/examples/swift_protobuf_example/BUILD.bazel b/examples/swift_protobuf_example/BUILD.bazel index 54ccdfb9e..8cef6ccda 100644 --- a/examples/swift_protobuf_example/BUILD.bazel +++ b/examples/swift_protobuf_example/BUILD.bazel @@ -1,4 +1,4 @@ -load("@rules_swift//swift:swift.bzl", "swift_library") +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") swift_library( name = "swift_protobuf_test", diff --git a/examples/swift_protobuf_example/MODULE.bazel b/examples/swift_protobuf_example/MODULE.bazel index a3c1f7e53..bb5fe1343 100644 --- a/examples/swift_protobuf_example/MODULE.bazel +++ b/examples/swift_protobuf_example/MODULE.bazel @@ -2,34 +2,6 @@ Example module for grpc + proto target generation. """ -# cgrindel_bazel_starlib - -bazel_dep(name = "cgrindel_bazel_starlib", version = "0.21.0") - -# rules_go - -bazel_dep(name = "rules_go", version = "0.50.1") - -# gazelle - -bazel_dep(name = "gazelle", version = "0.40.0") - -# protobuf - -bazel_dep(name = "protobuf", version = "29.0") - -# rules_proto - -bazel_dep(name = "rules_proto", version = "7.0.2") - -# apple_support - -bazel_dep(name = "apple_support", version = "1.17.1") - -# rules_swift - -bazel_dep(name = "rules_swift", version = "2.2.2") - # rules_swift_package_manager bazel_dep( @@ -41,6 +13,32 @@ local_path_override( path = "../..", ) +# core deps + +bazel_dep(name = "cgrindel_bazel_starlib", version = "0.21.0") +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "apple_support", version = "1.17.1") +bazel_dep( + name = "rules_swift", + version = "2.2.2", + repo_name = "build_bazel_rules_swift", +) +bazel_dep( + name = "rules_apple", + version = "3.16.1", + repo_name = "build_bazel_rules_apple", +) + +# apple_cc_configure + +apple_cc_configure = use_extension( + "@apple_support//crosstool:setup.bzl", + "apple_cc_configure_extension", +) +use_repo(apple_cc_configure, "local_config_apple_cc") + +# swift_deps + swift_deps = use_extension( "@rules_swift_package_manager//:extensions.bzl", "swift_deps", From e8211504ff68a22edfbe4442cc2cb2572b4b439d Mon Sep 17 00:00:00 2001 From: Logan Shire Date: Mon, 6 Jan 2025 10:24:30 -0300 Subject: [PATCH 5/5] Tidy --- .bazelrc | 4 +- .github/workflows/ci.yml | 2 + examples/swift_protobuf_example/BUILD.bazel | 38 +++++++++++++++---- examples/swift_protobuf_example/MODULE.bazel | 29 +++++++------- .../Sources/BUILD.bazel | 8 ++++ examples/swift_protobuf_example/WORKSPACE | 1 + .../swift_protobuf_example/WORKSPACE.bzlmod | 2 + swiftpkg/internal/swiftpkg_build_files.bzl | 6 +-- 8 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 examples/swift_protobuf_example/Sources/BUILD.bazel create mode 100644 examples/swift_protobuf_example/WORKSPACE create mode 100644 examples/swift_protobuf_example/WORKSPACE.bzlmod diff --git a/.bazelrc b/.bazelrc index b1416d4e5..a7a13a65b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,7 +1,7 @@ # To update these lines, execute # `bazel run @rules_bazel_integration_test//tools:update_deleted_packages` -build --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Sources/System,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/aaa_test,examples/grpc_example/protos,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/grpc_example/sources/test,examples/grpc_package_example,examples/grpc_package_example/aaa_test,examples/grpc_package_example/protos,examples/grpc_package_example/protos/echo_service,examples/grpc_package_example/sources,examples/grpc_package_example/sources/client,examples/grpc_package_example/sources/server,examples/grpc_package_example/sources/test,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources,examples/messagekit_example/UITests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example -query --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Sources/System,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/aaa_test,examples/grpc_example/protos,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/grpc_example/sources/test,examples/grpc_package_example,examples/grpc_package_example/aaa_test,examples/grpc_package_example/protos,examples/grpc_package_example/protos/echo_service,examples/grpc_package_example/sources,examples/grpc_package_example/sources/client,examples/grpc_package_example/sources/server,examples/grpc_package_example/sources/test,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources,examples/messagekit_example/UITests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example +build --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Sources/System,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/aaa_test,examples/grpc_example/protos,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/grpc_example/sources/test,examples/grpc_package_example,examples/grpc_package_example/aaa_test,examples/grpc_package_example/protos,examples/grpc_package_example/protos/echo_service,examples/grpc_package_example/sources,examples/grpc_package_example/sources/client,examples/grpc_package_example/sources/server,examples/grpc_package_example/sources/test,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources,examples/messagekit_example/UITests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/swift_protobuf_example,examples/swift_protobuf_example/Sources,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example +query --deleted_packages=bzlmod/workspace,bzlmod/workspace/Sources/MyExecutable,bzlmod/workspace/Sources/MyLibrary,bzlmod/workspace/Sources/System,bzlmod/workspace/Tests/MyLibraryTests,examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/firebase_example/crashlytics,examples/google_maps_example,examples/google_maps_example/GoogleMapsExample,examples/google_maps_example/third-party/google-maps-ios-sdk,examples/grpc_example,examples/grpc_example/aaa_test,examples/grpc_example/protos,examples/grpc_example/protos/echo_service,examples/grpc_example/protos/echo_service/requests,examples/grpc_example/protos/echo_service/responses,examples/grpc_example/sources,examples/grpc_example/sources/client,examples/grpc_example/sources/server,examples/grpc_example/sources/test,examples/grpc_package_example,examples/grpc_package_example/aaa_test,examples/grpc_package_example/protos,examples/grpc_package_example/protos/echo_service,examples/grpc_package_example/sources,examples/grpc_package_example/sources/client,examples/grpc_package_example/sources/server,examples/grpc_package_example/sources/test,examples/interesting_deps,examples/interesting_deps/ios,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/ios_sim/third-party/swift-cmark,examples/lottie_ios_example,examples/lottie_ios_example/LottieExample,examples/lottie_ios_example/LottieExampleUITest,examples/messagekit_example,examples/messagekit_example/Sources,examples/messagekit_example/UITests,examples/nimble_example,examples/nimble_example/Sources/NimbleExample,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/resources_example,examples/resources_example/Sources/MyApp,examples/resources_example/Tests/MyAppTests,examples/resources_example/Tests/MyAppUITests,examples/resources_example/third_party,examples/shake_ios_example,examples/shake_ios_example/ShakeIOSExample,examples/shake_ios_example/ShakeIOSExampleUITests,examples/snapkit_example,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/stripe_example,examples/stripe_example/PaymentSheet/PaymentSheetExample,examples/stripe_example/PaymentSheet/PaymentSheetUITest,examples/swift_protobuf_example,examples/swift_protobuf_example/Sources,examples/symlink_example,examples/symlink_example/Sources/ImportFramework,examples/symlink_example/Tests/ImportFrameworkTests,examples/tca_example,examples/tca_example/Sources,examples/tca_example/Tests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example # Import Shared settings import %workspace%/shared.bazelrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3c0958d8..22806632b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,8 @@ jobs: runner: macos-13 - test: '@@//examples:stripe_example_test_bazel_.bazelversion' runner: macos-13 + - test: '@@//examples:swift_protobuf_example_test_bazel_.bazelversion' + runner: macos-13 - test: '@@//examples:symlink_example_test_bazel_.bazelversion' runner: macos-13 - test: '@@//examples:tca_example_test_bazel_.bazelversion' diff --git a/examples/swift_protobuf_example/BUILD.bazel b/examples/swift_protobuf_example/BUILD.bazel index 8cef6ccda..2eb696535 100644 --- a/examples/swift_protobuf_example/BUILD.bazel +++ b/examples/swift_protobuf_example/BUILD.bazel @@ -1,11 +1,33 @@ -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") +load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary") +load("@cgrindel_bazel_starlib//bzltidy:defs.bzl", "tidy") -swift_library( - name = "swift_protobuf_test", - srcs = ["Sources/SwiftProtobufTest.swift"], - module_name = "SwiftProtobufTest", - visibility = ["//visibility:public"], - deps = [ - "@swiftpkg_swift_protobuf//:SwiftProtobuf", +tidy( + name = "tidy", + targets = [ + ":update_build_files", ], ) + +# MARK: - Gazelle + +# Ignore the Swift build folder +# gazelle:exclude .build + +gazelle_binary( + name = "gazelle_bin", + languages = [ + "@bazel_skylib_gazelle_plugin//bzl", + "@rules_swift_package_manager//gazelle", + ], +) + +gazelle( + name = "update_build_files", + data = [ + "@swift_deps_info//:swift_deps_index", + ], + extra_args = [ + "-swift_dependency_index=$(location @swift_deps_info//:swift_deps_index)", + ], + gazelle = ":gazelle_bin", +) diff --git a/examples/swift_protobuf_example/MODULE.bazel b/examples/swift_protobuf_example/MODULE.bazel index bb5fe1343..8610fe38a 100644 --- a/examples/swift_protobuf_example/MODULE.bazel +++ b/examples/swift_protobuf_example/MODULE.bazel @@ -1,9 +1,3 @@ -""" -Example module for grpc + proto target generation. -""" - -# rules_swift_package_manager - bazel_dep( name = "rules_swift_package_manager", version = "0.0.0", @@ -13,14 +7,15 @@ local_path_override( path = "../..", ) -# core deps - bazel_dep(name = "cgrindel_bazel_starlib", version = "0.21.0") bazel_dep(name = "bazel_skylib", version = "1.7.1") -bazel_dep(name = "apple_support", version = "1.17.1") +bazel_dep( + name = "apple_support", + version = "1.17.1", +) bazel_dep( name = "rules_swift", - version = "2.2.2", + version = "2.3.1", repo_name = "build_bazel_rules_swift", ) bazel_dep( @@ -29,7 +24,17 @@ bazel_dep( repo_name = "build_bazel_rules_apple", ) -# apple_cc_configure +bazel_dep( + name = "bazel_skylib_gazelle_plugin", + version = "1.7.1", + dev_dependency = True, +) +bazel_dep( + name = "gazelle", + version = "0.40.0", + dev_dependency = True, + repo_name = "bazel_gazelle", +) apple_cc_configure = use_extension( "@apple_support//crosstool:setup.bzl", @@ -37,8 +42,6 @@ apple_cc_configure = use_extension( ) use_repo(apple_cc_configure, "local_config_apple_cc") -# swift_deps - swift_deps = use_extension( "@rules_swift_package_manager//:extensions.bzl", "swift_deps", diff --git a/examples/swift_protobuf_example/Sources/BUILD.bazel b/examples/swift_protobuf_example/Sources/BUILD.bazel new file mode 100644 index 000000000..ad394704f --- /dev/null +++ b/examples/swift_protobuf_example/Sources/BUILD.bazel @@ -0,0 +1,8 @@ +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_test") + +swift_test( + name = "Sources", + srcs = ["SwiftProtobufTest.swift"], + module_name = "Sources", + deps = ["@swiftpkg_swift_protobuf//:SwiftProtobuf"], +) diff --git a/examples/swift_protobuf_example/WORKSPACE b/examples/swift_protobuf_example/WORKSPACE new file mode 100644 index 000000000..d251ab7ba --- /dev/null +++ b/examples/swift_protobuf_example/WORKSPACE @@ -0,0 +1 @@ +# Intentionally blank: Using bzlmod diff --git a/examples/swift_protobuf_example/WORKSPACE.bzlmod b/examples/swift_protobuf_example/WORKSPACE.bzlmod new file mode 100644 index 000000000..8cf89c330 --- /dev/null +++ b/examples/swift_protobuf_example/WORKSPACE.bzlmod @@ -0,0 +1,2 @@ +# Intentionally blank +# This exists to force Bazel in bzlmod mode to be strict. diff --git a/swiftpkg/internal/swiftpkg_build_files.bzl b/swiftpkg/internal/swiftpkg_build_files.bzl index a754ad094..af97bf495 100644 --- a/swiftpkg/internal/swiftpkg_build_files.bzl +++ b/swiftpkg/internal/swiftpkg_build_files.bzl @@ -139,7 +139,7 @@ def _swift_target_build_file(pkg_ctx, target): new_language_mode = bzl_selects.new( value = "swift.enable_v" + language_mode.value, kind = language_mode.kind, - condition = language_mode.condition + condition = language_mode.condition, ) features.append(new_language_mode) for bs in target.swift_settings.experimental_features: @@ -147,7 +147,7 @@ def _swift_target_build_file(pkg_ctx, target): new_experimental_feature = bzl_selects.new( value = "swift.experimental." + experimental_feature.value, kind = experimental_feature.kind, - condition = experimental_feature.condition + condition = experimental_feature.condition, ) features.append(new_experimental_feature) for bs in target.swift_settings.upcoming_features: @@ -155,7 +155,7 @@ def _swift_target_build_file(pkg_ctx, target): new_upcoming_feature = bzl_selects.new( value = "swift.upcoming." + upcoming_feature.value, kind = upcoming_feature.kind, - condition = upcoming_feature.condition + condition = upcoming_feature.condition, ) features.append(new_upcoming_feature) if len(features) > 0: