Skip to content

Commit 0636a1e

Browse files
author
Karim Alweheshy
committed
inject custom toolchain and make it work
1 parent 2d78cae commit 0636a1e

File tree

13 files changed

+121
-44
lines changed

13 files changed

+121
-44
lines changed

test/internal/pbxproj_partials/write_pbxproj_prefix_tests.bzl

+4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ def write_pbxproj_prefix_test_suite(name):
266266
"some/path/to/index_import",
267267
# resolvedRepositoriesFile
268268
"some/path/to/resolved_repositories_file",
269+
# customToolchainID
270+
"com.rules_xcodeproj.BazelRulesXcodeProj.16B40",
269271
# minimumXcodeVersion
270272
"14.2.1",
271273
# importIndexBuildIndexstores
@@ -332,6 +334,8 @@ def write_pbxproj_prefix_test_suite(name):
332334
"some/path/to/index_import",
333335
# resolvedRepositoriesFile
334336
"some/path/to/resolved_repositories_file",
337+
# customToolchainID
338+
"com.rules_xcodeproj.BazelRulesXcodeProj.16B40",
335339
# minimumXcodeVersion
336340
"14.2.1",
337341
# importIndexBuildIndexstores

tools/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ _XCSCHEMES = [
179179
"bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import",
180180
# resolvedRepositoriesFile
181181
"bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/generators/xcodeproj/xcodeproj_pbxproj_partials/resolved_repositories",
182+
# customToolchainID
183+
"com.rules_xcodeproj.BazelRulesXcodeProj.16B40",
182184
# minimumXcodeVersion
183185
"14.0",
184186
# defaultXcodeConfiguration

tools/generators/pbxproj_prefix/src/Generator/Arguments.swift

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ setting.
4242
)
4343
var resolvedRepositoriesFile: URL
4444

45+
@Argument(help: "The custom toolchain ID.")
46+
var customToolchainID: String
47+
4548
@Argument(help: """
4649
Minimum Xcode version that the generated project supports.
4750
""")

tools/generators/pbxproj_prefix/src/Generator/Environment.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ extension Generator {
3737
_ projectDir: String,
3838
_ resolvedRepositories: String,
3939
_ workspace: String,
40-
_ createBuildSettingsAttribute: CreateBuildSettingsAttribute
40+
_ createBuildSettingsAttribute: CreateBuildSettingsAttribute,
41+
_ customToolchainID: String
4142
) -> String
4243

4344
let pbxProjectPrefixPartial: (

tools/generators/pbxproj_prefix/src/Generator/Generator.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ struct Generator {
6262
),
6363
/*workspace:*/ arguments.workspace,
6464
/*createBuildSettingsAttribute:*/
65-
environment.createBuildSettingsAttribute
65+
environment.createBuildSettingsAttribute,
66+
/*customToolchainID:*/ arguments.customToolchainID
6667
),
6768
/*compatibilityVersion:*/ environment.compatibilityVersion(
6869
arguments.minimumXcodeVersion

tools/generators/pbxproj_prefix/src/Generator/PBXProjectBuildSettings.swift

+3-17
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ extension Generator {
2525
projectDir: String,
2626
resolvedRepositories: String,
2727
workspace: String,
28-
createBuildSettingsAttribute: CreateBuildSettingsAttribute
28+
createBuildSettingsAttribute: CreateBuildSettingsAttribute,
29+
customToolchainID: String
2930
) -> String {
3031
return createBuildSettingsAttribute(buildSettings: [
3132
.init(key: "ALWAYS_SEARCH_USER_PATHS", value: "NO"),
@@ -70,7 +71,6 @@ extension Generator {
7071
key: "BUILD_WORKSPACE_DIRECTORY",
7172
value: #""$(SRCROOT)""#
7273
),
73-
.init(key: "CC", value: #""$(BAZEL_INTEGRATION_DIR)/clang.sh""#),
7474
.init(key: "CLANG_ENABLE_OBJC_ARC", value: "YES"),
7575
.init(key: "CLANG_MODULES_AUTOLINK", value: "NO"),
7676
.init(key: "CODE_SIGNING_ALLOWED", value: "NO"),
@@ -80,23 +80,14 @@ extension Generator {
8080
value: #""$(BUILD_DIR)/$(BAZEL_PACKAGE_BIN_DIR)""#
8181
),
8282
.init(key: "COPY_PHASE_STRIP", value: "NO"),
83-
.init(key: "CXX", value: #""$(BAZEL_INTEGRATION_DIR)/clang.sh""#),
8483
.init(key: "DEBUG_INFORMATION_FORMAT", value: "dwarf"),
8584
.init(key: "DSTROOT", value: #""$(PROJECT_TEMP_DIR)""#),
8685
.init(key: "ENABLE_DEBUG_DYLIB", value: "NO"),
8786
.init(key: "ENABLE_DEFAULT_SEARCH_PATHS", value: "NO"),
8887
.init(key: "ENABLE_STRICT_OBJC_MSGSEND", value: "YES"),
8988
.init(key: "ENABLE_USER_SCRIPT_SANDBOXING", value: "NO"),
9089
.init(key: "GCC_OPTIMIZATION_LEVEL", value: "0"),
91-
.init(key: "LD", value: #""$(BAZEL_INTEGRATION_DIR)/ld""#),
92-
.init(
93-
key: "LDPLUSPLUS",
94-
value: #""$(BAZEL_INTEGRATION_DIR)/ld""#
95-
),
96-
.init(
97-
key: "LIBTOOL",
98-
value: #""$(BAZEL_INTEGRATION_DIR)/libtool""#
99-
),
90+
.init(key: "TOOLCHAINS", value: customToolchainID),
10091
.init(
10192
key: "IMPORT_INDEX_BUILD_INDEXSTORES",
10293
value: importIndexBuildIndexstores ? "YES" : "NO"
@@ -135,13 +126,8 @@ extension Generator {
135126
.init(key: "RULES_XCODEPROJ_BUILD_MODE", value: "bazel"),
136127
.init(key: "SRCROOT", value: workspace.pbxProjEscaped),
137128
.init(key: "SUPPORTS_MACCATALYST", value: "NO"),
138-
.init(
139-
key: "SWIFT_EXEC",
140-
value: #""$(BAZEL_INTEGRATION_DIR)/swiftc""#
141-
),
142129
.init(key: "SWIFT_OBJC_INTERFACE_HEADER_NAME", value: #""""#),
143130
.init(key: "SWIFT_OPTIMIZATION_LEVEL", value: #""-Onone""#),
144-
.init(key: "SWIFT_USE_INTEGRATED_DRIVER", value: "NO"),
145131
.init(key: "SWIFT_VERSION", value: "5.0"),
146132
.init(key: "TAPI_EXEC", value: "/usr/bin/true"),
147133
.init(

tools/generators/pbxproj_prefix/test/PBXProjectBuildSettingsTests.swift

+3-8
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ class PBXProjectBuildSettingsTests: XCTestCase {
3232
BUILD_DIR = "$(SYMROOT)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
3333
BUILD_MARKER_FILE = "$(OBJROOT)/build_marker";
3434
BUILD_WORKSPACE_DIRECTORY = "$(SRCROOT)";
35-
CC = "$(BAZEL_INTEGRATION_DIR)/clang.sh";
3635
CLANG_ENABLE_OBJC_ARC = YES;
3736
CLANG_MODULES_AUTOLINK = NO;
3837
CODE_SIGNING_ALLOWED = NO;
3938
CODE_SIGN_STYLE = Manual;
4039
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(BAZEL_PACKAGE_BIN_DIR)";
4140
COPY_PHASE_STRIP = NO;
42-
CXX = "$(BAZEL_INTEGRATION_DIR)/clang.sh";
4341
DEBUG_INFORMATION_FORMAT = dwarf;
4442
DSTROOT = "$(PROJECT_TEMP_DIR)";
4543
ENABLE_DEBUG_DYLIB = NO;
@@ -53,22 +51,18 @@ class PBXProjectBuildSettingsTests: XCTestCase {
5351
INDEX_IMPORT = "$(BAZEL_EXTERNAL)/index-import";
5452
INSTALL_PATH = "$(BAZEL_PACKAGE_BIN_DIR)/$(TARGET_NAME)/bin";
5553
INTERNAL_DIR = "$(PROJECT_FILE_PATH)/rules_xcodeproj";
56-
LD = "$(BAZEL_INTEGRATION_DIR)/ld";
57-
LDPLUSPLUS = "$(BAZEL_INTEGRATION_DIR)/ld";
5854
LD_DYLIB_INSTALL_NAME = "";
5955
LD_OBJC_ABI_VERSION = "";
6056
LD_RUNPATH_SEARCH_PATHS = "";
61-
LIBTOOL = "$(BAZEL_INTEGRATION_DIR)/libtool";
57+
TOOLCHAINS = "com.rules_xcodeproj.BazelRulesXcodeProj.16B40";
6258
ONLY_ACTIVE_ARCH = YES;
6359
PROJECT_DIR = "/some/project dir";
6460
RESOLVED_REPOSITORIES = "\"\" \"/tmp/workspace\"";
6561
RULES_XCODEPROJ_BUILD_MODE = bazel;
6662
SRCROOT = "/Users/TimApple/Star Board";
6763
SUPPORTS_MACCATALYST = NO;
68-
SWIFT_EXEC = "$(BAZEL_INTEGRATION_DIR)/swiftc";
6964
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
7065
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
71-
SWIFT_USE_INTEGRATED_DRIVER = NO;
7266
SWIFT_VERSION = 5.0;
7367
TAPI_EXEC = /usr/bin/true;
7468
TARGET_TEMP_DIR = "$(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)";
@@ -88,7 +82,8 @@ class PBXProjectBuildSettingsTests: XCTestCase {
8882
projectDir: projectDir,
8983
resolvedRepositories: resolvedRepositories,
9084
workspace: workspace,
91-
createBuildSettingsAttribute: CreateBuildSettingsAttribute()
85+
createBuildSettingsAttribute: CreateBuildSettingsAttribute(),
86+
customToolchainID: "com.rules_xcodeproj.BazelRulesXcodeProj.16B40"
9287
)
9388

9489
// Assert

tools/swiftc_stub/main.swift

+48-15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import Foundation
55
enum PathKey: String {
66
case emitModulePath = "-emit-module-path"
77
case emitObjCHeaderPath = "-emit-objc-header-path"
8+
case emitModuleSourceInfoPath = "-emit-module-source-info-path"
9+
case serializeDiagnosticsPath = "-serialize-diagnostics-path"
10+
case emitDependenciesPath = "-emit-dependencies-path"
11+
case emitABIDescriptorPath = "-emit-abi-descriptor-path"
12+
case emitModuleDocPath = "-emit-module-doc-path"
813
case outputFileMap = "-output-file-map"
914
case sdk = "-sdk"
1015
}
@@ -75,17 +80,17 @@ extension URL {
7580
}
7681
}
7782

78-
/// Touch the Xcode-required `.d` files
83+
/// Touch the Xcode-required `.d` and `-master-emit-module.d` files
7984
func touchDepsFiles(isWMO: Bool, paths: [PathKey: URL]) throws {
8085
guard let outputFileMapPath = paths[PathKey.outputFileMap] else { return }
8186

8287
if isWMO {
83-
let dPath = String(
84-
outputFileMapPath.path.dropLast("-OutputFileMap.json".count) +
85-
"-master.d"
86-
)
87-
var url = URL(fileURLWithPath: dPath)
88-
try url.touch()
88+
let pathNoExtension = String(outputFileMapPath.path.dropLast("-OutputFileMap.json".count))
89+
var masterDFilePath = URL(fileURLWithPath: pathNoExtension + "-master.d")
90+
try masterDFilePath.touch()
91+
92+
var dFilePath = URL(fileURLWithPath: pathNoExtension + ".d")
93+
try dFilePath.touch()
8994
} else {
9095
let data = try Data(contentsOf: outputFileMapPath)
9196
let outputFileMapRaw = try JSONSerialization.jsonObject(
@@ -98,23 +103,28 @@ func touchDepsFiles(isWMO: Bool, paths: [PathKey: URL]) throws {
98103
}
99104

100105
for entry in outputFileMap.values {
101-
guard let dPath = entry["dependencies"] as? String else {
102-
continue
106+
if let dPath = entry["dependencies"] as? String {
107+
var url = URL(fileURLWithPath: dPath)
108+
try url.touch()
103109
}
104-
var url = URL(fileURLWithPath: dPath)
105-
try url.touch()
110+
if let dPath = entry["emit-module-dependencies"] as? String {
111+
var url = URL(fileURLWithPath: dPath)
112+
try url.touch()
113+
}
114+
continue
106115
}
107116
}
108117
}
109118

110-
/// Touch the Xcode-required `.swift{module,doc,sourceinfo}` files
119+
/// Touch the Xcode-required `-master-emit-module.d`, `.{d,abi.json}` and `.swift{module,doc,sourceinfo}` files
111120
func touchSwiftmoduleArtifacts(paths: [PathKey: URL]) throws {
112121
if var swiftmodulePath = paths[PathKey.emitModulePath] {
113-
var swiftdocPath = swiftmodulePath.deletingPathExtension()
122+
let pathNoExtension = swiftmodulePath.deletingPathExtension()
123+
var swiftdocPath = pathNoExtension
114124
.appendingPathExtension("swiftdoc")
115-
var swiftsourceinfoPath = swiftmodulePath.deletingPathExtension()
125+
var swiftsourceinfoPath = pathNoExtension
116126
.appendingPathExtension("swiftsourceinfo")
117-
var swiftinterfacePath = swiftmodulePath.deletingPathExtension()
127+
var swiftinterfacePath = pathNoExtension
118128
.appendingPathExtension("swiftinterface")
119129

120130
try swiftmodulePath.touch()
@@ -126,6 +136,29 @@ func touchSwiftmoduleArtifacts(paths: [PathKey: URL]) throws {
126136
if var generatedHeaderPath = paths[PathKey.emitObjCHeaderPath] {
127137
try generatedHeaderPath.touch()
128138
}
139+
140+
if var path = paths[PathKey.emitModuleSourceInfoPath] {
141+
try path.touch()
142+
}
143+
144+
if var path = paths[PathKey.serializeDiagnosticsPath] {
145+
try path.touch()
146+
}
147+
148+
if var path = paths[PathKey.emitDependenciesPath] {
149+
try path.touch()
150+
}
151+
152+
if var path = paths[PathKey.emitABIDescriptorPath] {
153+
try path.touch()
154+
}
155+
156+
if var path = paths[PathKey.emitModuleDocPath] {
157+
var swiftModulePath = path.deletingPathExtension()
158+
.appendingPathExtension("swiftmodule")
159+
try swiftModulePath.touch()
160+
try path.touch()
161+
}
129162
}
130163

131164
func runSubProcess(executable: String, args: [String]) throws -> Int32 {

xcodeproj/internal/BUILD

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load("//xcodeproj/internal:custom_toolchain.bzl", "custom_toolchain")
23

34
bzl_library(
45
name = "bazel_tools",
@@ -46,3 +47,16 @@ filegroup(
4647
tags = ["manual"],
4748
visibility = ["//:__subpackages__"],
4849
)
50+
51+
custom_toolchain(
52+
name = "rulesxcodeproj_toolchain",
53+
overrides = {
54+
# Use universal_swiftc_stub for all tools
55+
"//" + package_name() + "/bazel_integration_files:clang_binary": "clang,clang++,cc,c++",
56+
"//" + package_name() + "/bazel_integration_files:libtool_binary": "libtool",
57+
"//" + package_name() + "/bazel_integration_files:ld_binary": "ld",
58+
"//tools/swiftc_stub:universal_swiftc_stub": "swiftc,swift-frontend",
59+
},
60+
toolchain_name = "BazelRulesXcodeProj",
61+
visibility = ["//visibility:public"],
62+
)

xcodeproj/internal/bazel_integration_files/BUILD

+22-1
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,29 @@ fi
132132
],
133133
)
134134

135-
# Release
135+
filegroup(
136+
name = "libtool_binary",
137+
srcs = ["libtool"],
138+
tags = ["manual"],
139+
# This is made public for internal use only
140+
visibility = ["//:__subpackages__"],
141+
)
136142

143+
filegroup(
144+
name = "ld_binary",
145+
srcs = ["ld"],
146+
tags = ["manual"],
147+
visibility = ["//:__subpackages__"],
148+
)
149+
150+
filegroup(
151+
name = "clang_binary",
152+
srcs = ["clang.sh"],
153+
tags = ["manual"],
154+
visibility = ["//:__subpackages__"],
155+
)
156+
157+
# Release
137158
filegroup(
138159
name = "release_files",
139160
srcs = glob(

xcodeproj/internal/bazel_integration_files/ld

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ passthrough_args=("${@:1}")
77
while test $# -gt 0
88
do
99
case $1 in
10+
-version_details)
11+
# Pass through for version details
12+
exec "$(xcrun --find ld)" -version_details
13+
;;
14+
1015
*_dependency_info.dat)
1116
ld_version=$(ld -v 2>&1 | grep ^@)
1217
printf "\0%s\0" "$ld_version" > "$1"

xcodeproj/internal/pbxproj_partials.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ def _write_pbxproj_prefix(
658658
),
659659
colorize,
660660
config,
661+
custom_toolchain_id,
661662
default_xcode_configuration,
662663
execution_root_file,
663664
generator_name,
@@ -681,6 +682,7 @@ def _write_pbxproj_prefix(
681682
apple_platform_to_platform_name: Exposed for testing. Don't set.
682683
colorize: A `bool` indicating whether to colorize the output.
683684
config: The name of the `.bazelrc` config.
685+
custom_toolchain_id: The custom toolchain ID.
684686
default_xcode_configuration: The name of the the Xcode configuration to
685687
use when building, if not overridden by custom schemes.
686688
execution_root_file: A `File` containing the absolute path to the Bazel
@@ -740,6 +742,9 @@ def _write_pbxproj_prefix(
740742
# resolvedRepositoriesFile
741743
args.add(resolved_repositories_file)
742744

745+
# customToolchainID
746+
args.add(custom_toolchain_id)
747+
743748
# minimumXcodeVersion
744749
args.add(minimum_xcode_version)
745750

0 commit comments

Comments
 (0)