-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define configuration settings to support SPM conditions (#179)
Related to #153.
- Loading branch information
Showing
18 changed files
with
447 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 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,26 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") | ||
load(":apple_platform_types.bzl", "apple_platform_types") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
[ | ||
config_setting( | ||
name = platform_type, | ||
values = {"apple_platform_type": platform_type}, | ||
) | ||
for platform_type in apple_platform_types.all_values | ||
] | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob(["*"]), | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "apple_platform_types", | ||
srcs = ["apple_platform_types.bzl"], | ||
) |
19 changes: 19 additions & 0 deletions
19
config_settings/bazel/apple_platform_type/apple_platform_types.bzl
This file contains 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,19 @@ | ||
"""Module for Bazel's Apple platform types.""" | ||
|
||
# NOTE: If entries are added/removed from apple_platform_types, be sure | ||
# to update the config_setting and selects.config_setting_group declarations in | ||
# //config_settings/spm_platform/BUILD.bazel. | ||
|
||
# List of valid values for Bazel's --apple_platform_type | ||
apple_platform_types = struct( | ||
macos = "macos", | ||
ios = "ios", | ||
tvos = "tvos", | ||
watchos = "watchos", | ||
all_values = [ | ||
"macos", | ||
"ios", | ||
"tvos", | ||
"watchos", | ||
], | ||
) |
This file contains 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,25 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") | ||
load(":compilation_modes.bzl", "compilation_modes") | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
[ | ||
config_setting( | ||
name = comp_mode, | ||
values = {"compilation_mode": comp_mode}, | ||
) | ||
for comp_mode in compilation_modes.all_values | ||
] | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob(["*"]), | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "compilation_modes", | ||
srcs = ["compilation_modes.bzl"], | ||
visibility = ["//visibility:public"], | ||
) |
12 changes: 12 additions & 0 deletions
12
config_settings/bazel/compilation_mode/compilation_modes.bzl
This file contains 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 @@ | ||
"""Module for Bazel compilation modes.""" | ||
|
||
compilation_modes = struct( | ||
debug = "dbg", | ||
optimized = "opt", | ||
fast = "fastbuild", | ||
all_values = [ | ||
"dbg", | ||
"opt", | ||
"fastbuild", | ||
], | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains 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,34 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@bazel_skylib//lib:selects.bzl", "selects") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") | ||
load(":configurations.bzl", "configurations") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
# Bazel compilation modes | ||
# https://bazel.build/docs/user-manual#compilation-mode | ||
SPM_CONFIG_TO_COMPILATION_MODE = { | ||
configurations.debug: "//config_settings/bazel/compilation_mode:dbg", | ||
configurations.release: "//config_settings/bazel/compilation_mode:opt", | ||
} | ||
|
||
[ | ||
selects.config_setting_group( | ||
name = spm_config, | ||
match_all = [bzl_comp_mode], | ||
) | ||
for (spm_config, bzl_comp_mode) in SPM_CONFIG_TO_COMPILATION_MODE.items() | ||
] | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob(["*"]), | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "configurations", | ||
srcs = ["configurations.bzl"], | ||
) |
This file contains 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 @@ | ||
"""Module for Swift package mananger configuration.""" | ||
|
||
# Derived from BuildConfiguration values | ||
# https://github.com/apple/swift-package-manager/blob/main/Sources/PackageDescription/BuildSettings.swift | ||
configurations = struct( | ||
debug = "debug", | ||
release = "release", | ||
all_values = [ | ||
"debug", | ||
"release", | ||
], | ||
) |
This file contains 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,49 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@bazel_skylib//lib:selects.bzl", "selects") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") | ||
load(":platforms.bzl", "platforms") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
# NOTE: Ensure that the list of spm_platforms in spm_platforms.bzl stays in | ||
# sync with the config_setting and selects.config_setting_group declarations. | ||
|
||
# MARK: - Platform | ||
|
||
# NOTE: The Bazel Apple platform type values match those of the corresponding | ||
# SPM platforms. If they ever diverge, we will need to add a mapping | ||
# somewhere. | ||
|
||
[ | ||
selects.config_setting_group( | ||
name = platform, | ||
match_any = [ | ||
"//config_settings/bazel/apple_platform_type:{}".format(platform), | ||
"@platforms//os:{}".format(platform), | ||
], | ||
) | ||
for platform in platforms.apple_platforms | ||
] | ||
|
||
[ | ||
config_setting( | ||
name = platform, | ||
constraint_values = [ | ||
"@platforms//os:{}".format(platform), | ||
], | ||
) | ||
for platform in platforms.non_apple_platforms | ||
] | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob(["*"]), | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "platforms", | ||
srcs = ["platforms.bzl"], | ||
) |
This file contains 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,39 @@ | ||
"""Module for Swift package manager platforms.""" | ||
|
||
# NOTE: Ensure that the list of spm_platforms below stays in sync with the | ||
# config_setting and selects.config_setting_group declarations in | ||
# //config_settings/spm_platform/BUILD.bazel. | ||
|
||
# Derived from Platform values | ||
# https://github.com/apple/swift-package-manager/blob/main/Sources/PackageDescription/SupportedPlatforms.swift | ||
# Not sure how to map the following SPM platforms: maccatalyst, driverkit | ||
|
||
_APPLE_PLATFORMS = [ | ||
"macos", | ||
"ios", | ||
"tvos", | ||
"watchos", | ||
] | ||
|
||
_NON_APPLE_PLATFORMS = [ | ||
"linux", | ||
"windows", | ||
"android", | ||
"wasi", | ||
"openbsd", | ||
] | ||
|
||
platforms = struct( | ||
macos = "macos", | ||
ios = "ios", | ||
tvos = "tvos", | ||
watchos = "watchos", | ||
linux = "linux", | ||
windows = "windows", | ||
android = "android", | ||
wasi = "wasi", | ||
openbsd = "openbsd", | ||
apple_platforms = _APPLE_PLATFORMS, | ||
non_apple_platforms = _NON_APPLE_PLATFORMS, | ||
all_values = _APPLE_PLATFORMS + _NON_APPLE_PLATFORMS, | ||
) |
This file contains 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,37 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@bazel_skylib//lib:selects.bzl", "selects") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") | ||
load(":platform_configurations.bzl", "platform_configurations") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
[ | ||
selects.config_setting_group( | ||
name = platform_configurations.new_name( | ||
pc.platform, | ||
pc.configuration, | ||
), | ||
match_all = [ | ||
"//config_settings/spm/configuration:{}".format(pc.configuration), | ||
"//config_settings/spm/platform:{}".format(pc.platform), | ||
], | ||
) | ||
for pc in platform_configurations.all_values | ||
] | ||
|
||
bzl_library( | ||
name = "platform_configurations", | ||
srcs = ["platform_configurations.bzl"], | ||
deps = [ | ||
"//config_settings/spm/configuration:configurations", | ||
"//config_settings/spm/platform:platforms", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob(["*"]), | ||
visibility = ["//:__subpackages__"], | ||
) |
28 changes: 28 additions & 0 deletions
28
config_settings/spm/platform_configuration/platform_configurations.bzl
This file contains 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,28 @@ | ||
"""Module for SPM platform-configuration combinations.""" | ||
|
||
load("//config_settings/spm/configuration:configurations.bzl", "configurations") | ||
load("//config_settings/spm/platform:platforms.bzl", "platforms") | ||
|
||
def _new(platform, configuration): | ||
return struct( | ||
platform = platform, | ||
configuration = configuration, | ||
) | ||
|
||
def _new_name(platform, configuration): | ||
return "{platform}_{configuration}".format( | ||
configuration = configuration, | ||
platform = platform, | ||
) | ||
|
||
_ALL_VALUES = [ | ||
_new(platform, configuration) | ||
for configuration in configurations.all_values | ||
for platform in platforms.all_values | ||
] | ||
|
||
platform_configurations = struct( | ||
new = _new, | ||
new_name = _new_name, | ||
all_values = _ALL_VALUES, | ||
) |
This file contains 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 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
Oops, something went wrong.