Skip to content

Commit d54bb62

Browse files
committed
Merge pull request #2497 from karwa/refactored-build-script
Refactored build-script-impl for cross-compiling support
2 parents de26657 + 0b6790c commit d54bb62

File tree

7 files changed

+976
-607
lines changed

7 files changed

+976
-607
lines changed

CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,11 @@ function(is_sdk_requested name result_var_name)
469469
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${name}")
470470
set("${result_var_name}" "TRUE" PARENT_SCOPE)
471471
else()
472-
if("${SWIFT_SDKS}" STREQUAL "")
473-
set("${result_var_name}" "TRUE" PARENT_SCOPE)
472+
list(FIND SWIFT_SDKS "${name}" sdk_index)
473+
if(${sdk_index} EQUAL -1)
474+
set("${result_var_name}" "FALSE" PARENT_SCOPE)
474475
else()
475-
list(FIND SWIFT_SDKS "${name}" sdk_index)
476-
if(${sdk_index} EQUAL -1)
477-
set("${result_var_name}" "FALSE" PARENT_SCOPE)
478-
else()
479-
set("${result_var_name}" "TRUE" PARENT_SCOPE)
480-
endif()
476+
set("${result_var_name}" "TRUE" PARENT_SCOPE)
481477
endif()
482478
endif()
483479
endfunction()

utils/SwiftBuildSupport.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,35 @@ def get_preset_options(substitutions, preset_file_names, preset_name):
194194
"': " + ", ".join(missing_opts))
195195
sys.exit(1)
196196

197+
# Migrate 'swift-sdks' parameter to 'stdlib-deployment-targets'
198+
for opt in build_script_impl_opts:
199+
if opt.startswith("--swift-sdks"):
200+
sdksToConfigure = opt.split("=")[1].split(";")
201+
tgts = []
202+
# Expand SDKs in to their deployment targets
203+
from swift_build_support.targets import StdlibDeploymentTarget
204+
for sdk in sdksToConfigure:
205+
if sdk == "OSX":
206+
tgts += StdlibDeploymentTarget.OSX.allArchs
207+
elif sdk == "IOS":
208+
tgts += StdlibDeploymentTarget.iOS.allArchs
209+
elif sdk == "IOS_SIMULATOR":
210+
tgts += StdlibDeploymentTarget.iOSSimulator.allArchs
211+
elif sdk == "TVOS":
212+
tgts += StdlibDeploymentTarget.AppleTV.allArchs
213+
elif sdk == "TVOS_SIMULATOR":
214+
tgts += StdlibDeploymentTarget.AppleTVSimulator.allArchs
215+
elif sdk == "WATCHOS":
216+
tgts += StdlibDeploymentTarget.AppleWatch.allArchs
217+
elif sdk == "WATCHOS_SIMULATOR":
218+
tgts += StdlibDeploymentTarget.AppleWatchSimulator.allArchs
219+
220+
build_script_opts.append("--stdlib-deployment-targets=" +
221+
" ".join(tgts))
222+
# Filter the swift-sdks parameter
223+
build_script_impl_opts = [opt for opt in build_script_impl_opts
224+
if not opt.startswith("--swift-sdks")]
225+
197226
return build_script_opts + ["--"] + build_script_impl_opts
198227

199228

utils/build-presets.ini

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ dash-dash
3232
verbose-build
3333
build-ninja
3434

35-
swift-sdks=OSX;IOS;IOS_SIMULATOR;TVOS;TVOS_SIMULATOR;WATCHOS;WATCHOS_SIMULATOR
36-
3735
# Build static standard library because it is used
3836
# to build external projects.
3937
build-swift-static-stdlib
@@ -76,7 +74,7 @@ skip-build-tvos
7674
skip-test-tvos
7775
skip-build-watchos
7876
skip-test-watchos
79-
swift-sdks=OSX
77+
stdlib-deployment-targets=macosx-x86_64
8078
swift-primary-variant-sdk=OSX
8179
swift-primary-variant-arch=x86_64
8280

@@ -406,7 +404,7 @@ skip-build-tvos
406404
skip-test-tvos
407405
skip-build-watchos
408406
skip-test-watchos
409-
swift-sdks=OSX
407+
stdlib-deployment-targets=macosx-x86_64
410408
swift-primary-variant-sdk=OSX
411409
swift-primary-variant-arch=x86_64
412410

@@ -671,7 +669,6 @@ build-ninja
671669
build-swift-static-stdlib
672670
build-swift-stdlib-unittest-extra
673671
compiler-vendor=apple
674-
swift-sdks=OSX;IOS;IOS_SIMULATOR;TVOS;TVOS_SIMULATOR;WATCHOS;WATCHOS_SIMULATOR
675672

676673
install-swift
677674
install-lldb

utils/build-script

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ from swift_build_support import products # noqa (E402)
4646
from swift_build_support import shell # noqa (E402)
4747
import swift_build_support.tar # noqa (E402)
4848
import swift_build_support.targets # noqa (E402)
49+
from swift_build_support.targets import StdlibDeploymentTarget # noqa (E402)
4950
from swift_build_support.cmake import CMake # noqa (E402)
5051
from swift_build_support.workspace import Workspace # noqa(E402)
5152
from swift_build_support.workspace import compute_build_subdir # noqa(E402)
@@ -312,13 +313,13 @@ details of the setups of other systems or automated environments.""")
312313
help="The host target. LLVM, Clang, and Swift will be built for this "
313314
"target. The built LLVM and Clang will be used to compile Swift "
314315
"for the cross-compilation targets.",
315-
default=swift_build_support.targets.host_target())
316+
default=StdlibDeploymentTarget.host_target())
316317
targets_group.add_argument(
317318
"--stdlib-deployment-targets",
318319
help="list of targets to compile or cross-compile the Swift standard "
319320
"library for. %(default)s by default.",
320321
nargs="*",
321-
default=swift_build_support.targets.stdlib_deployment_targets())
322+
default=StdlibDeploymentTarget.default_stdlib_deployment_targets())
322323

323324
projects_group = parser.add_argument_group(
324325
title="Options to select projects")
@@ -1185,6 +1186,11 @@ details of the setups of other systems or automated environments.""")
11851186
if args.build_subdir is None:
11861187
args.build_subdir = compute_build_subdir(args)
11871188

1189+
# Add optional stdlib-deployment-targets
1190+
if args.android:
1191+
args.stdlib_deployment_targets.append(
1192+
StdlibDeploymentTarget.Android.armv7)
1193+
11881194
workspace = Workspace(
11891195
source_root=SWIFT_SOURCE_ROOT,
11901196
build_root=os.path.join(SWIFT_BUILD_ROOT, args.build_subdir))
@@ -1233,7 +1239,7 @@ details of the setups of other systems or automated environments.""")
12331239
build_script_impl_args = [
12341240
"--workspace", workspace.source_root,
12351241
"--build-dir", workspace.build_root,
1236-
"--install-prefix", os.path.abspath(args.install_prefix),
1242+
"--install-prefix", args.install_prefix,
12371243
"--host-target", args.host_target,
12381244
"--stdlib-deployment-targets",
12391245
" ".join(args.stdlib_deployment_targets),

0 commit comments

Comments
 (0)