Skip to content

Commit 93e8b92

Browse files
authored
Merge pull request #614 from apple/cherry-pick-a76b464108e70336e41632511ede3991f9d633e0
[5.4] [Build Script Helper] Do not pass `-Ddispatch_DIR` to the Yams CMake …
2 parents b71abc6 + 9b02e85 commit 93e8b92

File tree

4 files changed

+101
-62
lines changed

4 files changed

+101
-62
lines changed

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
272272
/// Test generation of explicit module build jobs for dependency modules when the driver
273273
/// is invoked with -experimental-explicit-module-build
274274
func testExplicitModuleBuildJobs() throws {
275+
#if arch(arm64)
276+
// Disabled on Apple Silicon
277+
// rdar://77109455
278+
throw XCTSkip()
279+
#endif
275280
try withTemporaryDirectory { path in
276281
let main = path.appending(component: "testExplicitModuleBuildJobs.swift")
277282
try localFileSystem.writeFileContents(main) {
@@ -376,6 +381,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
376381
}
377382

378383
func testImmediateModeExplicitModuleBuild() throws {
384+
#if arch(arm64)
385+
// Disabled on Apple Silicon
386+
// rdar://77109455
387+
throw XCTSkip()
388+
#endif
379389
try withTemporaryDirectory { path in
380390
let main = path.appending(component: "testExplicitModuleBuildJobs.swift")
381391
try localFileSystem.writeFileContents(main) {
@@ -458,6 +468,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
458468
// The macOS-only restriction is temporary while Clang's dependency scanner
459469
// is gaining the ability to perform name-based module lookup.
460470
#if os(macOS)
471+
#if arch(arm64)
472+
// Disabled on Apple Silicon
473+
// rdar://76609781
474+
throw XCTSkip()
475+
#endif
461476
try withTemporaryDirectory { path in
462477
try localFileSystem.changeCurrentWorkingDirectory(to: path)
463478
let main = path.appending(component: "testExplicitModuleBuildEndToEnd.swift")

Tests/SwiftDriverTests/JobExecutorTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ extension DarwinToolchain {
9090
final class JobExecutorTests: XCTestCase {
9191
func testDarwinBasic() throws {
9292
#if os(macOS)
93+
#if arch(arm64)
94+
// Disabled on Apple Silicon
95+
// rdar://76609781
96+
throw XCTSkip()
97+
#endif
9398
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(),
9499
processSet: ProcessSet(),
95100
fileSystem: localFileSystem,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ final class SwiftDriverTests: XCTestCase {
19031903

19041904
let expectedDefaultContents: String
19051905
#if os(macOS)
1906-
expectedDefaultContents = "x86_64-apple-macosx"
1906+
expectedDefaultContents = "-apple-macosx"
19071907
#elseif os(Linux)
19081908
expectedDefaultContents = "-unknown-linux"
19091909
#else

Utilities/build-script-helper.py

Lines changed: 80 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
else:
1818
shared_lib_ext = '.so'
1919
macos_deployment_target = '10.15'
20-
macos_target_architectures = ['x86_64','arm64']
20+
21+
def error(message):
22+
print("--- %s: error: %s" % (os.path.basename(sys.argv[0]), message))
23+
sys.stdout.flush()
24+
raise SystemExit(1)
2125

2226
# Tools constructed as a part of the a development build toolchain
2327
driver_toolchain_tools = ['swift', 'swift-frontend', 'clang', 'swift-help',
@@ -146,10 +150,19 @@ def should_test_parallel():
146150
return False
147151
return True
148152

149-
def handle_invocation(toolchain_bin, args):
153+
def handle_invocation(args):
150154
swiftpm_args = get_swiftpm_options(args)
151-
155+
toolchain_bin = os.path.join(args.toolchain, 'bin')
152156
swift_exec = os.path.join(toolchain_bin, 'swift')
157+
swiftc_exec = os.path.join(toolchain_bin, 'swiftc')
158+
159+
# Platform-specific targets for which we must build swift-driver
160+
if args.cross_compile_hosts:
161+
targets = args.cross_compile_hosts
162+
elif platform.system() == 'Darwin':
163+
targets = [get_build_target(swiftc_exec, args) + macos_deployment_target]
164+
else:
165+
targets = [get_build_target(swiftc_exec, args)]
153166

154167
env = os.environ
155168
# Use local dependencies (i.e. checked out next to swift-driver).
@@ -163,7 +176,7 @@ def handle_invocation(toolchain_bin, args):
163176
env['SDKROOT'] = args.sysroot
164177

165178
if args.action == 'build':
166-
build_using_cmake(args, toolchain_bin, args.build_path)
179+
build_using_cmake(args, toolchain_bin, args.build_path, targets)
167180

168181
elif args.action == 'clean':
169182
print('Cleaning ' + args.build_path)
@@ -181,8 +194,8 @@ def handle_invocation(toolchain_bin, args):
181194
swiftpm('test', swift_exec, test_args, env)
182195
elif args.action == 'install':
183196
if platform.system() == 'Darwin':
184-
build_using_cmake(args, toolchain_bin, args.build_path)
185-
install(args, args.build_path)
197+
build_using_cmake(args, toolchain_bin, args.build_path, targets)
198+
install(args, args.build_path, targets)
186199
else:
187200
bin_path = swiftpm_bin_path(swift_exec, swiftpm_args, env)
188201
swiftpm('build', swift_exec, swiftpm_args, env)
@@ -197,12 +210,16 @@ def non_darwin_install(swiftpm_bin_path, toolchain, verbose):
197210
for exe in ['swift-driver', 'swift-help']:
198211
install_binary(exe, swiftpm_bin_path, toolchain_bin, verbose)
199212

200-
def install(args, build_dir):
213+
def install(args, build_dir, targets):
201214
# Construct and install universal swift-driver, swift-help executables
202215
# and libSwiftDriver, libSwiftOptions libraries, along with their dependencies.
203-
toolchain_bin = os.path.join(args.toolchain, 'bin')
204-
toolchain_lib = os.path.join(args.toolchain, 'lib', 'swift', 'macosx')
205-
toolchain_include = os.path.join(args.toolchain, 'include', 'swift')
216+
for prefix in args.install_prefixes:
217+
install_swiftdriver(args, build_dir, prefix, targets)
218+
219+
def install_swiftdriver(args, build_dir, prefix, targets) :
220+
install_bin = os.path.join(prefix, 'bin')
221+
install_lib = os.path.join(prefix, 'lib', 'swift', 'macosx')
222+
install_include = os.path.join(prefix, 'include', 'swift')
206223
universal_dir = os.path.join(build_dir, 'universal-apple-macos%s' % macos_deployment_target)
207224
bin_dir = os.path.join(universal_dir, 'bin')
208225
lib_dir = os.path.join(universal_dir, 'lib')
@@ -211,35 +228,35 @@ def install(args, build_dir):
211228
mkdir_p(lib_dir)
212229

213230
# swift-driver and swift-help
214-
install_executables(args, build_dir, bin_dir, toolchain_bin)
231+
install_executables(args, build_dir, bin_dir, install_bin, targets)
215232

216233
# libSwiftDriver and libSwiftDriverExecution and libSwiftOptions
217-
install_libraries(args, build_dir, lib_dir, toolchain_lib)
234+
install_libraries(args, build_dir, lib_dir, install_lib, targets)
218235

219236
# Binary Swift Modules:
220237
# swift-driver: SwiftDriver.swiftmodule, SwiftOptions.swiftmodule
221238
# TODO: swift-argument-parser: ArgumentParser.swiftmodule (disabled until needed)
222239
# swift-tools-support-core: TSCUtility.swiftmodule, TSCLibc.swiftmodule, TSCBasic.swiftmodule
223-
install_binary_swift_modules(args, build_dir, toolchain_lib)
240+
install_binary_swift_modules(args, build_dir, install_lib, targets)
224241

225242
# Modulemaps for C Modules:
226243
# TSCclibc
227-
install_c_module_includes(args, build_dir, toolchain_include)
244+
install_c_module_includes(args, build_dir, install_include)
228245

229246
# Install universal binaries for swift-driver and swift-help into the toolchain bin
230247
# directory
231-
def install_executables(args, build_dir, universal_bin_dir, toolchain_bin_dir):
248+
def install_executables(args, build_dir, universal_bin_dir, toolchain_bin_dir, targets):
232249
for exe in ['swift-driver', 'swift-help']:
233250
# Fixup rpaths
234-
for arch in macos_target_architectures:
235-
exe_bin_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
251+
for target in targets:
252+
exe_bin_path = os.path.join(build_dir, target,
236253
args.configuration, 'bin', exe)
237-
driver_lib_dir_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
254+
driver_lib_dir_path = os.path.join(build_dir, target,
238255
args.configuration, 'lib')
239256
delete_rpath(driver_lib_dir_path, exe_bin_path, args.verbose)
240257

241258
for lib in ['swift-tools-support-core', 'swift-argument-parser']:
242-
lib_dir_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
259+
lib_dir_path = os.path.join(build_dir, target,
243260
args.configuration, 'dependencies',
244261
lib, 'lib')
245262
delete_rpath(lib_dir_path, exe_bin_path, args.verbose)
@@ -251,22 +268,22 @@ def install_executables(args, build_dir, universal_bin_dir, toolchain_bin_dir):
251268
output_bin_path = os.path.join(universal_bin_dir, exe)
252269
lipo_cmd = ['lipo']
253270
# Inputs
254-
for arch in macos_target_architectures:
255-
input_bin_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
271+
for target in targets:
272+
input_bin_path = os.path.join(build_dir, target,
256273
args.configuration, 'bin', exe)
257274
lipo_cmd.append(input_bin_path)
258275
lipo_cmd.extend(['-create', '-output', output_bin_path])
259276
subprocess.check_call(lipo_cmd)
260277
install_binary(exe, universal_bin_dir, toolchain_bin_dir, args.verbose)
261278

262279
# Install shared libraries for the driver and its dependencies into the toolchain
263-
def install_libraries(args, build_dir, universal_lib_dir, toolchain_lib_dir):
280+
def install_libraries(args, build_dir, universal_lib_dir, toolchain_lib_dir, targets):
264281
# Fixup the SwiftDriver rpath for libSwiftDriver and libSwiftDriverExecution
265282
for lib in ['libSwiftDriver', 'libSwiftDriverExecution']:
266-
for arch in macos_target_architectures:
267-
lib_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
283+
for target in targets:
284+
lib_path = os.path.join(build_dir, target,
268285
args.configuration, 'lib', lib + shared_lib_ext)
269-
driver_lib_dir_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
286+
driver_lib_dir_path = os.path.join(build_dir, target,
270287
args.configuration, 'lib')
271288
delete_rpath(driver_lib_dir_path, lib_path, args.verbose)
272289

@@ -275,11 +292,11 @@ def install_libraries(args, build_dir, universal_lib_dir, toolchain_lib_dir):
275292
tsc_libs = map(lambda d: os.path.join('dependencies', 'swift-tools-support-core', 'lib', d),
276293
['libTSCBasic', 'libTSCLibc', 'libTSCUtility'])
277294
for lib in driver_libs + tsc_libs:
278-
for arch in macos_target_architectures:
279-
lib_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
295+
for target in targets:
296+
lib_path = os.path.join(build_dir, target,
280297
args.configuration, lib + shared_lib_ext)
281298
for dep in ['swift-tools-support-core', 'llbuild']:
282-
lib_dir_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
299+
lib_dir_path = os.path.join(build_dir, target,
283300
args.configuration, 'dependencies',
284301
dep, 'lib')
285302
delete_rpath(lib_dir_path, lib_path, args.verbose)
@@ -289,57 +306,57 @@ def install_libraries(args, build_dir, universal_lib_dir, toolchain_lib_dir):
289306
package_subpath = args.configuration
290307
for lib in ['libSwiftDriver', 'libSwiftOptions', 'libSwiftDriverExecution']:
291308
install_library(args, build_dir, package_subpath, lib,
292-
universal_lib_dir, toolchain_lib_dir, 'swift-driver')
309+
universal_lib_dir, toolchain_lib_dir, 'swift-driver', targets)
293310

294311
# Instal the swift-tools-support core shared libraries into the toolchain lib
295312
package_subpath = os.path.join(args.configuration, 'dependencies', 'swift-tools-support-core')
296313
for lib in ['libTSCBasic', 'libTSCLibc', 'libTSCUtility']:
297314
install_library(args, build_dir, package_subpath, lib,
298-
universal_lib_dir, toolchain_lib_dir, 'swift-tools-support-core')
315+
universal_lib_dir, toolchain_lib_dir, 'swift-tools-support-core', targets)
299316

300317
package_subpath = os.path.join(args.configuration, 'dependencies', 'swift-argument-parser')
301318
install_library(args, build_dir, package_subpath, 'libArgumentParser',
302-
universal_lib_dir, toolchain_lib_dir,'swift-argument-parser')
319+
universal_lib_dir, toolchain_lib_dir,'swift-argument-parser', targets)
303320

304321
package_subpath = os.path.join(args.configuration, 'dependencies', 'llbuild')
305322
for lib in ['libllbuildSwift', 'libllbuild']:
306323
install_library(args, build_dir, package_subpath, lib,
307-
universal_lib_dir, toolchain_lib_dir,'llbuild')
324+
universal_lib_dir, toolchain_lib_dir,'llbuild', targets)
308325

309326
# Create a universal shared-library file and install it into the toolchain lib
310327
def install_library(args, build_dir, package_subpath, lib_name,
311-
universal_lib_dir, toolchain_lib_dir, package_name):
328+
universal_lib_dir, toolchain_lib_dir, package_name, targets):
312329
shared_lib_file = lib_name + shared_lib_ext
313330
output_dylib_path = os.path.join(universal_lib_dir, shared_lib_file)
314331
lipo_cmd = ['lipo']
315-
for arch in macos_target_architectures:
316-
input_lib_path = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
332+
for target in targets:
333+
input_lib_path = os.path.join(build_dir, target,
317334
package_subpath, 'lib', shared_lib_file)
318335
lipo_cmd.append(input_lib_path)
319336
lipo_cmd.extend(['-create', '-output', output_dylib_path])
320337
subprocess.check_call(lipo_cmd)
321338
install_binary(shared_lib_file, universal_lib_dir, toolchain_lib_dir, args.verbose)
322339

323340
# Install binary .swiftmodule files for the driver and its dependencies into the toolchain lib
324-
def install_binary_swift_modules(args, build_dir, toolchain_lib_dir):
341+
def install_binary_swift_modules(args, build_dir, toolchain_lib_dir, targets):
325342
# The common subpath from a project's build directory to where its build products are found
326343
product_subpath = 'swift'
327344

328345
# swift-driver
329346
package_subpath = os.path.join(args.configuration, product_subpath)
330347
for module in ['SwiftDriver', 'SwiftOptions']:
331-
install_module(args, build_dir, package_subpath, toolchain_lib_dir, module)
348+
install_module(args, build_dir, package_subpath, toolchain_lib_dir, module, targets)
332349

333350
# swift-tools-support-core
334351
package_subpath = os.path.join(args.configuration, 'dependencies', 'swift-tools-support-core',
335352
product_subpath)
336353
for module in ['TSCUtility', 'TSCLibc', 'TSCBasic']:
337-
install_module(args, build_dir, package_subpath, toolchain_lib_dir, module)
354+
install_module(args, build_dir, package_subpath, toolchain_lib_dir, module, targets)
338355

339356
# swift-argument-parser
340357
package_subpath = os.path.join(args.configuration, 'dependencies', 'swift-argument-parser',
341358
product_subpath)
342-
install_module(args, build_dir, package_subpath, toolchain_lib_dir, 'ArgumentParser')
359+
install_module(args, build_dir, package_subpath, toolchain_lib_dir, 'ArgumentParser', targets)
343360

344361
# Install the modulemaps and headers of the driver's C module dependencies into the toolchain
345362
# include directory
@@ -349,16 +366,16 @@ def install_c_module_includes(args, build_dir, toolchain_include_dir):
349366
'TSCclibc', 'include')
350367
install_include_artifacts(args, toolchain_include_dir, tscc_include_dir, 'TSCclibc')
351368

352-
def install_module(args, build_dir, package_subpath, toolchain_lib, module_name):
369+
def install_module(args, build_dir, package_subpath, toolchain_lib, module_name, targets):
353370
toolchain_module_dir = os.path.join(toolchain_lib, module_name + '.swiftmodule')
354371
mkdir_p(toolchain_module_dir)
355-
for arch in macos_target_architectures:
356-
swift_dir = os.path.join(build_dir, arch + '-apple-macos' + macos_deployment_target,
372+
for target in targets:
373+
swift_dir = os.path.join(build_dir, target,
357374
package_subpath)
358375
for fileext in ['.swiftmodule', '.swiftdoc']:
359376
install_binary(module_name + fileext, swift_dir, toolchain_module_dir, args.verbose)
360377
os.rename(os.path.join(toolchain_module_dir, module_name + fileext),
361-
os.path.join(toolchain_module_dir, arch + '-apple-macos' + fileext))
378+
os.path.join(toolchain_module_dir, target + fileext))
362379

363380
# Copy over the contents of a module's include directory contents (modulemap, headers, etc.)
364381
def install_include_artifacts(args, toolchain_include_dir, src_include_dir, dst_module_name):
@@ -367,15 +384,8 @@ def install_include_artifacts(args, toolchain_include_dir, src_include_dir, dst_
367384
shutil.rmtree(toolchain_module_include_dir, ignore_errors=True)
368385
shutil.copytree(src_include_dir, toolchain_module_include_dir)
369386

370-
def build_using_cmake(args, toolchain_bin, build_dir):
387+
def build_using_cmake(args, toolchain_bin, build_dir, targets):
371388
swiftc_exec = os.path.join(toolchain_bin, 'swiftc')
372-
373-
# Platform-specific targets for which we must build swift-driver
374-
if platform.system() == 'Darwin':
375-
targets = [x + '-apple-macos' + macos_deployment_target for x in macos_target_architectures]
376-
else:
377-
targets = [get_build_target(swiftc_exec, args)]
378-
379389
swift_flags = []
380390
if args.configuration == 'debug':
381391
swift_flags.append('-Onone')
@@ -460,9 +470,6 @@ def build_yams_using_cmake(args, target, swiftc_exec, build_dir, base_cmake_flag
460470
yams_cmake_flags.append('-DCMAKE_C_FLAGS=-target %s' % target)
461471
else:
462472
yams_cmake_flags.append('-DCMAKE_C_FLAGS=-fPIC -target %s' % target)
463-
if args.dispatch_build_dir:
464-
yams_cmake_flags.append(get_dispatch_cmake_arg(args))
465-
466473
if args.foundation_build_dir:
467474
yams_cmake_flags.append(get_foundation_cmake_arg(args))
468475
yams_swift_flags = swift_flags[:]
@@ -551,6 +558,18 @@ def main():
551558
def add_common_args(parser):
552559
parser.add_argument('--package-path', metavar='PATH', help='directory of the package to build', default='.')
553560
parser.add_argument('--toolchain', required=True, metavar='PATH', help='build using the toolchain at PATH')
561+
parser.add_argument(
562+
'--prefix',
563+
dest='install_prefixes',
564+
nargs='*',
565+
help='paths (relative to the project root) where to install build products [%(default)s]',
566+
metavar='PATHS')
567+
parser.add_argument(
568+
'--cross-compile-hosts',
569+
dest='cross_compile_hosts',
570+
nargs='*',
571+
help='List of cross compile hosts targets.',
572+
default=[])
554573
parser.add_argument('--ninja-bin', metavar='PATH', help='ninja binary to use for testing')
555574
parser.add_argument('--cmake-bin', metavar='PATH', help='cmake binary to use for building')
556575
parser.add_argument('--build-path', metavar='PATH', default='.build', help='build in the given path')
@@ -573,8 +592,6 @@ def add_common_args(parser):
573592
install_parser = subparsers.add_parser('install', help='build the package')
574593
add_common_args(install_parser)
575594

576-
577-
578595
args = parser.parse_args(sys.argv[1:])
579596

580597
# Canonicalize paths
@@ -587,18 +604,20 @@ def add_common_args(parser):
587604
else:
588605
args.sysroot = None
589606

590-
if args.toolchain:
591-
toolchain_bin = os.path.join(args.toolchain, 'bin')
592-
else:
593-
toolchain_bin = ''
607+
if args.cross_compile_hosts and not all('apple-macos' in target for target in args.cross_compile_hosts):
608+
error('Cross-compilation is currently only supported for the Darwin platform.')
594609

595610
if args.dispatch_build_dir:
596611
args.dispatch_build_dir = os.path.abspath(args.dispatch_build_dir)
597612

598613
if args.foundation_build_dir:
599614
args.foundation_build_dir = os.path.abspath(args.foundation_build_dir)
600615

601-
handle_invocation(toolchain_bin, args)
616+
# If a separate prefix has not been specified, installed into the specified toolchain
617+
if not args.install_prefixes:
618+
args.install_prefixes = [args.toolchain]
619+
620+
handle_invocation(args)
602621

603622
if __name__ == '__main__':
604623
main()

0 commit comments

Comments
 (0)