Skip to content

Commit

Permalink
Add target_build_settings generator
Browse files Browse the repository at this point in the history
Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones committed Nov 2, 2023
1 parent 39205cb commit 92b71eb
Show file tree
Hide file tree
Showing 22 changed files with 2,421 additions and 0 deletions.
164 changes: 164 additions & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _TOOLS = {
"pbxproj_prefix": "//tools/generators/pbxproj_prefix",
"pbxtargetdependencies": "//tools/generators/pbxtargetdependencies",
"swiftc_stub": "//tools/swiftc_stub:swiftc",
"target_build_settings": "//tools/generators/target_build_settings",
"xcschemes": "//tools/generators/xcschemes",
}

Expand All @@ -25,6 +26,9 @@ _TESTS = {
"//tools/generators/lib/PBXProj:PBXProjTests",
"//tools/generators/pbxtargetdependencies:pbxtargetdependencies_tests",
],
"target_build_settings": [
"//tools/generators/target_build_settings:target_build_settings_tests",
],
"xcschemes": [
"//tools/generators/lib/PBXProj:PBXProjTests",
"//tools/generators/lib/XCScheme:XCSchemeTests",
Expand Down Expand Up @@ -199,6 +203,163 @@ _SCHEMES = [
build_configuration = "Release",
),
),
xcode_schemes.scheme(
name = "target_build_settings",
launch_action = xcode_schemes.launch_action(
_TOOLS["target_build_settings"],
args = [
# colorize
"0",
# buildSettingsOutputPath
"/tmp/pbxproj_partials/target_build_settings",
# swiftDebugSettingsOutputPath
"/tmp/pbxproj_partials/swift_debug_settings",
# includeSelfSwiftDebugSettings
"1",
# transitiveSwiftDebugSettingPaths
"2",
"/tmp/pbxproj_partials/transitive_swift_debug_settings_0",
"/tmp/pbxproj_partials/transitive_swift_debug_settings_1",
# deviceFamily
"4",
# extensionSafe
"0",
# generatesDsyms
"1",
# infoPlist
"bazel-out/generated/Info.plist",
# entitlements
"project/level/app.entitlements",
# certificateName
"",
# provisioningProfileName
"",
# teamID
"",
# provisioningProfileIsXcodeManaged
"0",
# packageBinDir
"bazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/Lib",
# previewFrameworkPaths
"",
# previewsIncludePath
"",
# swiftArgs
"-target",
"arm64_32-apple-watchos7.0",
"-sdk",
"__BAZEL_XCODE_SDKROOT__",
"-debug-prefix-map",
"__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR",
"-file-prefix-map",
"__BAZEL_XCODE_DEVELOPER_DIR__=DEVELOPER_DIR",
"-emit-object",
"-output-file-map",
"bazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/Lib/Lib.output_file_map.json",
"-Xfrontend",
"-no-clang-module-breadcrumbs",
"-swift-version",
"4.2",
"-emit-module-path",
"bazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/Lib/Lib.swiftmodule",
"-emit-objc-header-path",
"bazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/Lib/generated/Lib-Swift.h",
"-enable-bare-slash-regex",
"-DNDEBUG",
"-O",
"-whole-module-optimization",
"-Xfrontend",
"-no-serialize-debugging-options",
"-g",
"-Xwrapped-swift=-debug-prefix-pwd-is-dot",
"-Xwrapped-swift=-file-prefix-pwd-is-dot",
"-module-cache-path",
"bazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/_swift_module_cache",
"-Fexternal/_main~non_module_deps~com_github_krzyzanowskim_cryptoswift/CryptoSwift.xcframework/watchos-arm64_32_armv7k",
"-Xcc",
"-Fexternal/_main~non_module_deps~com_github_krzyzanowskim_cryptoswift/CryptoSwift.xcframework/watchos-arm64_32_armv7k",
"-Xcc",
"-iquoteexternal/_main~non_module_deps~com_github_krzyzanowskim_cryptoswift",
"-Xcc",
"-iquotebazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/external/_main~non_module_deps~com_github_krzyzanowskim_cryptoswift",
"-Xcc",
"-iquote.",
"-Xcc",
"-iquotebazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin",
"-Xcc",
"-fmodule-map-file=external/_main~non_module_deps~com_github_krzyzanowskim_cryptoswift/CryptoSwift.xcframework/watchos-arm64_32_armv7k/CryptoSwift.framework/Modules/module.modulemap",
"-Xfrontend",
"-color-diagnostics",
"-num-threads",
"12",
"-module-name",
"Lib",
"-Xwrapped-swift=-global-index-store-import-path=bazel-out/_global_index_store",
"-index-store-path",
"bazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/Lib/Lib.indexstore",
"-Xfrontend",
"-disable-autolink-framework",
"-Xfrontend",
"CryptoSwift",
"-Xfrontend",
"-vfsoverlay",
"-Xfrontend",
"project/relative/overlay.yaml",
"-Xcc",
"-ivfsoverlay=external/overlay.yaml",
"-vfsoverlay",
"bazel-out/generated/overlay.yaml",
"-Xfrontend",
"-explicit-swift-module-map-file",
"-Xfrontend",
"bazel-out/generated/map.json",
"-Xfrontend",
"-load-plugin-executable",
"-Xfrontend",
"bazel-out/generated/macro",
"-parse-as-library",
"-application-extension",
"-static",
"-Xcc",
"-Os",
"-Xcc",
"-DNDEBUG=1",
"-Xcc",
"-Wno-unused-variable",
"-Xcc",
"-Winit-self",
"-Xcc",
"-Wno-extra",
"Lib/Resources.swift",
"bazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/Lib/Lib.swift",
# cParamsOutputPath
"---",
"/tmp/pbxproj_partials/c.compile.params",
# cArgs
"-Os",
"-ivfsoverlay=external/overlay.yaml",
"--config",
"some.cfg",
# cxxParamsOutputPath
"---",
"/tmp/pbxproj_partials/cxx.compile.params",
# cxxArgs
"-Os",
"-D_FORTIFY_SOURCE=2",
"-ivfsoverlay",
"bazel-out/generated/overlay.yaml",
],
diagnostics = _SCHEME_DIAGNOSTICS,
),
profile_action = xcode_schemes.profile_action(
_TOOLS["target_build_settings"],
build_configuration = "Release",
),
test_action = xcode_schemes.test_action(
_TESTS["target_build_settings"],
diagnostics = _SCHEME_DIAGNOSTICS,
),
),
xcode_schemes.scheme(
name = "xcschemes",
launch_action = xcode_schemes.launch_action(
Expand Down Expand Up @@ -274,6 +435,9 @@ xcodeproj(
"//tools/generators/pbxtargetdependencies": [
"//tools/generators/pbxtargetdependencies:README.md",
],
"//tools/generators/target_build_settings": [
"//tools/generators/target_build_settings:README.md",
],
"//tools/generators/xcschemes": [
"//tools/generators/xcschemes:README.md",
],
Expand Down
1 change: 1 addition & 0 deletions tools/generators/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ filegroup(
# "//" + package_name() + "/pbxproj_prefix:release_files",
# "//" + package_name() + "/pbxtargetdependencies:release_files",
# "//" + package_name() + "/selected_model_versions:release_files",
# "//" + package_name() + "/target_build_settings:release_files",
# "//" + package_name() + "/xcschemes:release_files",
],
tags = ["manual"],
Expand Down
8 changes: 8 additions & 0 deletions tools/generators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ information.
- The `PBXProject.targets` property
- Closes the `PBXProject` element
- A set of files, each detailing how a set of configured targets are consolidated together
- [`target_build_settings`](target_build_settings/README.md):
- Run once for each target
- Each target generates a file that contains one or more build settings:
- `DEBUG_INFORMATION_FORMAT`
- `OTHER_CFLAGS`
- `OTHER_SWIFT_FLAGS`
- `SWIFT_COMPILATION_MODE`
- etc.
- `pbxnativetargets`:
- Run once on each shard of all the targets
- All of the `PBXNativeTarget` related objects:
Expand Down
94 changes: 94 additions & 0 deletions tools/generators/target_build_settings/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_universal_binary")
load(
"@build_bazel_rules_apple//apple:macos.bzl",
"macos_command_line_application",
"macos_unit_test",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_binary",
"swift_library",
)

exports_files(["README.md"])

# Generator

swift_library(
name = "target_build_settings.library",
srcs = glob(["src/**/*.swift"]),
module_name = "target_build_settings",
deps = [
"//tools/generators/lib/PBXProj",
"//tools/lib/ToolCommon",
"@com_github_apple_swift_collections//:OrderedCollections",
],
)

# This target exists to keep configurations the same between the generator
# and the tests, which makes the Xcode development experience better. If we used
# `swift_binary` or `apple_universal_binary` in `xcodeproj`, then the
# `macos_unit_test` transition (which is used to be able to set a minimum os
# version on the tests) will create slightly different configurations for our
# `swift_library`s. Maybe https://github.com/bazelbuild/bazel/issues/6526 will
# fix that for us.
macos_command_line_application(
name = "target_build_settings",
minimum_os_version = "13.0",
visibility = ["//visibility:public"],
deps = [":target_build_settings.library"],
)

swift_binary(
name = "target_build_settings_binary",
deps = [":target_build_settings.library"],
)

apple_universal_binary(
name = "universal_target_build_settings",
binary = ":target_build_settings_binary",
forced_cpus = [
"x86_64",
"arm64",
],
minimum_os_version = "13.0",
platform_type = "macos",
visibility = ["//visibility:public"],
)

# Tests

swift_library(
name = "target_build_settings_tests.library",
testonly = True,
srcs = glob(["test/**/*.swift"]),
module_name = "target_build_settings_tests",
deps = [
":target_build_settings.library",
"@com_github_pointfreeco_swift_custom_dump//:CustomDump",
],
)

macos_unit_test(
name = "target_build_settings_tests",
minimum_os_version = "13.0",
visibility = [
"//test:__subpackages__",
"@rules_xcodeproj//xcodeproj:generated",
],
deps = [
":target_build_settings_tests.library",
],
)

# Release

filegroup(
name = "release_files",
srcs = [
"BUILD.release.bazel",
":universal_target_build_settings",
],
tags = ["manual"],
visibility = ["//:__subpackages__"],
)
8 changes: 8 additions & 0 deletions tools/generators/target_build_settings/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")

native_binary(
name = "universal_target_build_settings",
src = "prebuilt_universal_target_build_settings",
out = "universal_target_build_settings",
visibility = ["//visibility:public"],
)
Loading

0 comments on commit 92b71eb

Please sign in to comment.