Skip to content

Commit f6adbb6

Browse files
committed
Merge pull request #948 from modocache/build-script-host-target
[build-script] There can only be one host target
2 parents 4d1f00e + c1a746b commit f6adbb6

File tree

4 files changed

+89
-58
lines changed

4 files changed

+89
-58
lines changed

utils/build-script

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ from SwiftBuildSupport import (
3737
sys.path.append(os.path.join(os.path.dirname(__file__), 'swift_build_support'))
3838
import swift_build_support.clang
3939
import swift_build_support.cmake
40+
import swift_build_support.targets
4041
from swift_build_support.migration import migrate_impl_args
4142

4243

@@ -288,6 +289,15 @@ It is a policy decision aimed at making the builds uniform across all
288289
environments and easily reproducible by engineers who are not familiar with the
289290
details of the setups of other systems or automated environments.""")
290291

292+
targets_group = parser.add_argument_group(
293+
title="Host and cross-compilation targets.")
294+
targets_group.add_argument(
295+
"--host-target",
296+
help="The host target. LLVM, Clang, and Swift will be built for this "
297+
"target. The built LLVM and Clang will be used to compile Swift "
298+
"for the cross-compilation targets.",
299+
default=swift_build_support.targets.host_target())
300+
291301
projects_group = parser.add_argument_group(
292302
title="Options to select projects")
293303
projects_group.add_argument("-l", "--lldb",
@@ -541,8 +551,13 @@ the number of parallel build jobs to use""",
541551
args = parser.parse_args(migrate_impl_args(sys.argv[1:], [
542552
'--darwin-xcrun-toolchain',
543553
'--cmake',
554+
'--host-target',
544555
]))
545556

557+
if args.host_target is None:
558+
print_with_argv0("Unknown operating system.")
559+
return 1
560+
546561
# Build cmark if any cmark-related options were specified.
547562
if (args.cmark_build_variant is not None):
548563
args.build_cmark = True
@@ -772,6 +787,7 @@ the number of parallel build jobs to use""",
772787
build_script_impl_args = [
773788
os.path.join(SWIFT_SOURCE_ROOT, "swift", "utils", "build-script-impl"),
774789
"--build-dir", build_dir,
790+
"--host-target", args.host_target,
775791
"--host-cc", host_clang.cc,
776792
"--host-cxx", host_clang.cxx,
777793
"--darwin-xcrun-toolchain", args.darwin_xcrun_toolchain,

utils/build-script-impl

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ KNOWN_SETTINGS=(
170170
install-foundation "" "whether to install foundation"
171171
install-libdispatch "" "whether to install libdispatch"
172172
darwin-install-extract-symbols "" "whether to extract symbols with dsymutil during installations"
173+
host-target "" "The host target. LLVM, Clang, and Swift will be built for this target. The built LLVM and Clang will be used to compile Swift for the cross-compilation targets. **This argument is required**"
173174
cross-compile-tools-deployment-targets "" "space-separated list of targets to cross-compile host Swift tools for"
174175
skip-merge-lipo-cross-compile-tools "" "set to skip running merge-lipo after installing cross-compiled host Swift tools"
175176
darwin-deployment-version-osx "10.9" "minimum deployment target version for OS X"
@@ -739,60 +740,11 @@ if [[ "$(uname -s)" == "Darwin" ]] ; then
739740
TOOLCHAIN_PREFIX=$(echo ${INSTALL_PREFIX} | sed -E 's/\/usr$//')
740741
fi
741742

742-
# A list of deployment targets to compile the Swift host tools for, in cases
743-
# where we can run the resulting binaries natively on the build machine.
744-
NATIVE_TOOLS_DEPLOYMENT_TARGETS=()
745743

746744
# A list of deployment targets to cross-compile the Swift host tools for.
747745
# We can't run the resulting binaries on the build machine.
748746
CROSS_TOOLS_DEPLOYMENT_TARGETS=()
749747

750-
# Determine the native deployment target for the build machine, that will be
751-
# used to jumpstart the standard library build when cross-compiling.
752-
case "$(uname -s -m)" in
753-
Linux\ x86_64)
754-
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
755-
"linux-x86_64"
756-
)
757-
;;
758-
Linux\ armv7*)
759-
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
760-
"linux-armv7"
761-
)
762-
;;
763-
Linux\ aarch64)
764-
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
765-
"linux-aarch64"
766-
)
767-
;;
768-
Linux\ ppc64)
769-
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
770-
"linux-powerpc64"
771-
)
772-
;;
773-
Linux\ ppc64le)
774-
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
775-
"linux-powerpc64le"
776-
)
777-
;;
778-
Darwin\ x86_64)
779-
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
780-
"macosx-x86_64"
781-
)
782-
;;
783-
784-
FreeBSD\ amd64)
785-
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
786-
"freebsd-x86_64"
787-
)
788-
;;
789-
790-
*)
791-
echo "Unknown operating system"
792-
exit 1
793-
;;
794-
esac
795-
796748
# Sanitize the list of cross-compilation targets.
797749
for t in ${CROSS_COMPILE_TOOLS_DEPLOYMENT_TARGETS} ; do
798750
case ${t} in
@@ -1376,7 +1328,7 @@ fi
13761328
# Configure and build each product
13771329
#
13781330
# Start with native deployment targets because the resulting tools are used during cross-compilation.
1379-
for deployment_target in "${NATIVE_TOOLS_DEPLOYMENT_TARGETS[@]}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"; do
1331+
for deployment_target in "${HOST_TARGET}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"; do
13801332
set_deployment_target_based_options
13811333

13821334
case "${COMPILER_VENDOR}" in
@@ -1561,11 +1513,10 @@ for deployment_target in "${NATIVE_TOOLS_DEPLOYMENT_TARGETS[@]}" "${CROSS_TOOLS_
15611513
"${LLVM_SOURCE_DIR}"
15621514
)
15631515
if [[ $(is_cross_tools_deployment_target ${deployment_target}) ]] ; then
1564-
# FIXME: don't hardcode macosx-x86_64.
15651516
cmake_options=(
15661517
"${cmake_options[@]}"
1567-
-DLLVM_TABLEGEN=$(build_directory macosx-x86_64 llvm)/bin/llvm-tblgen
1568-
-DCLANG_TABLEGEN=$(build_directory macosx-x86_64 llvm)/bin/clang-tblgen
1518+
-DLLVM_TABLEGEN=$(build_directory "${HOST_TARGET}" llvm)/bin/llvm-tblgen
1519+
-DCLANG_TABLEGEN=$(build_directory "${HOST_TARGET}" llvm)/bin/clang-tblgen
15691520
)
15701521
fi
15711522

@@ -1592,10 +1543,9 @@ for deployment_target in "${NATIVE_TOOLS_DEPLOYMENT_TARGETS[@]}" "${CROSS_TOOLS_
15921543
build_perf_testsuite_this_time=false
15931544
build_tests_this_time=false
15941545

1595-
# FIXME: don't hardcode macosx-x86_64.
1596-
native_llvm_tools_path="$(build_directory macosx-x86_64 llvm)/bin"
1597-
native_clang_tools_path="$(build_directory macosx-x86_64 llvm)/bin"
1598-
native_swift_tools_path="$(build_directory macosx-x86_64 swift)/bin"
1546+
native_llvm_tools_path="$(build_directory "${HOST_TARGET}" llvm)/bin"
1547+
native_clang_tools_path="$(build_directory "${HOST_TARGET}" llvm)/bin"
1548+
native_swift_tools_path="$(build_directory "${HOST_TARGET}" swift)/bin"
15991549

16001550
cmake_options=(
16011551
"${cmake_options[@]}"
@@ -2111,7 +2061,7 @@ for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
21112061
done
21122062
done
21132063

2114-
for deployment_target in "${NATIVE_TOOLS_DEPLOYMENT_TARGETS[@]}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"; do
2064+
for deployment_target in "${HOST_TARGET}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"; do
21152065
set_deployment_target_based_options
21162066

21172067
for product in "${PRODUCTS[@]}"; do
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# swift_build_support/targets.py - Build target helpers -*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
11+
import platform
12+
13+
14+
def host_target():
15+
"""
16+
Return the build target for the current host machine, if it is one of the
17+
recognized targets. Otherwise, return None.
18+
"""
19+
system = platform.system()
20+
machine = platform.machine()
21+
22+
if system == 'Linux':
23+
if machine == 'x86_64':
24+
return 'linux-x86_64'
25+
elif machine.startswith('armv7'):
26+
# linux-armv7* is canonicalized to 'linux-armv7'
27+
return 'linux-armv7'
28+
elif machine == 'aarch64':
29+
return 'linux-aarch64'
30+
elif machine == 'ppc64':
31+
return 'linux-powerpc64'
32+
elif machine == 'ppc64le':
33+
return 'linux-powerpc64le'
34+
35+
elif system == 'Darwin':
36+
if machine == 'x86_64':
37+
return 'macosx-x86_64'
38+
39+
elif system == 'FreeBSD':
40+
if machine == 'amd64':
41+
return 'freebsd-x86_64'
42+
43+
return None
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# test_targets.py - Unit tests for swift_build_support.targets -*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
11+
import unittest
12+
13+
from swift_build_support.targets import host_target
14+
15+
16+
class HostTargetTestCase(unittest.TestCase):
17+
def test_is_not_none_on_this_platform(self):
18+
self.assertIsNotNone(host_target())
19+
20+
21+
if __name__ == '__main__':
22+
unittest.main()

0 commit comments

Comments
 (0)