Skip to content

Commit 2b923f3

Browse files
author
Doug Coleman
committed
utils: Add swiftenvs, which allow the overriding of compiler tools.
1 parent 49941c5 commit 2b923f3

File tree

13 files changed

+615
-160
lines changed

13 files changed

+615
-160
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ swift_configure_components()
420420
# lipo is used to create universal binaries.
421421
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
422422
include(SwiftDarwin)
423-
if(SWIFT_LIPO)
424-
set(LIPO ${SWIFT_LIPO})
423+
if(CMAKE_LIPO)
424+
set(CMAKE_LIPO ${CMAKE_LIPO})
425425
else()
426-
find_toolchain_tool(LIPO "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" lipo)
426+
find_toolchain_tool(CMAKE_LIPO "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" lipo)
427427
endif()
428428
endif()
429429

benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ if(NOT SWIFT_LIBRARY_PATH)
147147
endif()
148148

149149
# If the CMAKE_C_COMPILER is already clang, don't find it again,
150-
# thus allowing the --host-cc build-script argument to work here.
150+
# thus allowing the --cmake-c-compiler build-script argument to work here.
151151
get_filename_component(c_compiler ${CMAKE_C_COMPILER} NAME)
152152

153153
if(${c_compiler} STREQUAL "clang")

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ function (swift_benchmark_compile_archopts)
349349
${objcfile}
350350
"-o" "${OUTPUT_EXEC}"
351351
COMMAND
352-
"codesign" "-f" "-s" "-" "${OUTPUT_EXEC}")
352+
${CMAKE_CODESIGN} "-f" "-s" "-" "${OUTPUT_EXEC}")
353353
set(new_output_exec "${OUTPUT_EXEC}" PARENT_SCOPE)
354354
endfunction()
355355

benchmark/scripts/generate_harness/CMakeLists.txt_template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if(NOT SWIFT_LIBRARY_PATH)
6868
endif()
6969

7070
# If the CMAKE_C_COMPILER is already clang, don't find it again,
71-
# thus allowing the --host-cc build-script argument to work here.
71+
# thus allowing the --cmake-c-compiler build-script argument to work here.
7272
get_filename_component(c_compiler ${CMAKE_C_COMPILER} NAME)
7373

7474
if(${c_compiler} STREQUAL "clang")

cmake/modules/AddSwift.cmake

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -465,22 +465,22 @@ function(_add_swift_lipo_target)
465465
is_darwin_based_sdk("${LIPO_SDK}" IS_DARWIN)
466466
if(IS_DARWIN)
467467
if(LIPO_CODESIGN)
468-
set(codesign_command COMMAND "codesign" "-f" "-s" "-" "${LIPO_OUTPUT}")
468+
set(codesign_command COMMAND "${CMAKE_CODESIGN}" "-f" "-s" "-" "${LIPO_OUTPUT}")
469469
endif()
470470
# Use lipo to create the final binary.
471471
add_custom_command_target(unused_var
472-
COMMAND "${LIPO}" "-create" "-output" "${LIPO_OUTPUT}" ${source_binaries}
473-
${codesign_command}
474-
CUSTOM_TARGET_NAME "${LIPO_TARGET}"
475-
OUTPUT "${LIPO_OUTPUT}"
476-
DEPENDS ${source_targets})
472+
COMMAND "${CMAKE_LIPO}" "-create" "-output" "${LIPO_OUTPUT}" ${source_binaries}
473+
${codesign_command}
474+
CUSTOM_TARGET_NAME "${LIPO_TARGET}"
475+
OUTPUT "${LIPO_OUTPUT}"
476+
DEPENDS ${source_targets})
477477
else()
478478
# We don't know how to create fat binaries for other platforms.
479479
add_custom_command_target(unused_var
480-
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${source_binaries}" "${LIPO_OUTPUT}"
481-
CUSTOM_TARGET_NAME "${LIPO_TARGET}"
482-
OUTPUT "${LIPO_OUTPUT}"
483-
DEPENDS ${source_targets})
480+
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${source_binaries}" "${LIPO_OUTPUT}"
481+
CUSTOM_TARGET_NAME "${LIPO_TARGET}"
482+
OUTPUT "${LIPO_OUTPUT}"
483+
DEPENDS ${source_targets})
484484
endif()
485485
endfunction()
486486

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ function(handle_gyb_source_single dependency_out_var_name)
4141
${SWIFT_GYB_FLAGS}
4242
${GYB_SINGLE_FLAGS})
4343

44-
set(gyb_tool "${SWIFT_SOURCE_DIR}/utils/gyb")
45-
set(gyb_tool_source "${gyb_tool}" "${gyb_tool}.py")
44+
if(NOT "${CMAKE_GYB}" STREQUAL "")
45+
set(gyb_tool "${CMAKE_GYB}")
46+
set(gyb_tool_source "${gyb_tool}" "${gyb_tool}")
47+
else()
48+
set(gyb_tool "${SWIFT_SOURCE_DIR}/utils/gyb")
49+
set(gyb_tool_source "${gyb_tool}" "${gyb_tool}.py")
50+
endif()
4651

4752
get_filename_component(dir "${GYB_SINGLE_OUTPUT}" DIRECTORY)
4853
get_filename_component(basename "${GYB_SINGLE_OUTPUT}" NAME)

utils/build-script

Lines changed: 105 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,6 @@ class BuildScriptInvocation(object):
601601
"--host-target", args.host_target,
602602
"--stdlib-deployment-targets",
603603
" ".join(args.stdlib_deployment_targets),
604-
"--host-cc", toolchain.cc,
605-
"--host-cxx", toolchain.cxx,
606604
"--darwin-xcrun-toolchain", args.darwin_xcrun_toolchain,
607605
"--darwin-deployment-version-osx=%s" % (
608606
args.darwin_deployment_version_osx),
@@ -613,6 +611,8 @@ class BuildScriptInvocation(object):
613611
"--darwin-deployment-version-watchos=%s" % (
614612
args.darwin_deployment_version_watchos),
615613
"--cmake", toolchain.cmake,
614+
"--cmake-c-compiler", toolchain.cc,
615+
"--cmake-cxx-compiler", toolchain.cxx,
616616
"--cmark-build-type", args.cmark_build_variant,
617617
"--llvm-build-type", args.llvm_build_variant,
618618
"--swift-build-type", args.swift_build_variant,
@@ -682,6 +682,14 @@ class BuildScriptInvocation(object):
682682
"--distcc",
683683
"--distcc-pump=%s" % toolchain.distcc_pump
684684
]
685+
if args.swiftenv_path:
686+
impl_args += [ "--swiftenv-path=%s" % args.swiftenv_path]
687+
if args.swiftenv_recreate:
688+
impl_args += [ "--swiftenv-recreate"]
689+
if args.swiftenv_script:
690+
impl_args += [ "--swiftenv-script=%s" % args.swiftenv_script]
691+
if args.swiftenv_make:
692+
impl_args += [ "--swiftenv-make=%s" % args.swiftenv_make]
685693
if args.enable_asan:
686694
impl_args += ["--enable-asan"]
687695
if args.enable_ubsan:
@@ -819,12 +827,6 @@ class BuildScriptInvocation(object):
819827
"--toolchain-prefix",
820828
swift_build_support.targets.darwin_toolchain_prefix(
821829
args.install_prefix),
822-
"--host-lipo", toolchain.lipo,
823-
]
824-
825-
if toolchain.libtool is not None:
826-
impl_args += [
827-
"--host-libtool", toolchain.libtool,
828830
]
829831

830832
# If we have extra_swift_args, combine all of them together and then
@@ -1044,6 +1046,47 @@ def clean_delay():
10441046
print('\b\b\b\bnow.')
10451047

10461048

1049+
def handle_swiftenv_args(args):
1050+
# Find clang in swiftenv if present
1051+
if args.swiftenv_path is None:
1052+
if args.swiftenv_recreate:
1053+
print(sys.argv[0], "error: using a swiftenv_recreate to make a swiftenv requires a destination in --swiftenv-path=", file=sys.stderr)
1054+
sys.exit(2) # 2 is the same as `argparse` error exit code.
1055+
1056+
if args.swiftenv_script is not None:
1057+
print(sys.argv[0], "error: using a swiftenv_script to make a swiftenv requires a destination in --swiftenv-path=", file=sys.stderr)
1058+
sys.exit(2) # 2 is the same as `argparse` error exit code.
1059+
1060+
if args.swiftenv_make is not None:
1061+
print(sys.argv[0], "error: using a swiftenv_make to make a swiftenv requires a destination in --swiftenv-path=", file=sys.stderr)
1062+
sys.exit(2) # 2 is the same as `argparse` error exit code.
1063+
1064+
if args.swiftenv_path is not None:
1065+
# mkdir the swiftenv_path
1066+
if not os.path.exists(args.swiftenv_path):
1067+
os.makedirs(args.swiftenv_path)
1068+
1069+
# Only use swiftenv_make/swiftenv_script if one is provided
1070+
# utils/swiftenv-make is default
1071+
if args.swiftenv_make is None:
1072+
args.swiftenv_make = os.path.join(
1073+
SWIFT_SOURCE_ROOT, "swift", "utils", "swiftenv-make")
1074+
else:
1075+
args.swiftenv_make = os.path.abspath(args.swiftenv_make)
1076+
1077+
# utils/swiftenv-script is default
1078+
if args.swiftenv_script is None:
1079+
args.swiftenv_script = os.path.join(
1080+
SWIFT_SOURCE_ROOT, "swift", "utils", "swiftenv-script")
1081+
else:
1082+
args.swiftenv_script = os.path.abspath(args.swiftenv_script)
1083+
1084+
print("args.swiftenv_path", args.swiftenv_path)
1085+
print("args.swiftenv_recreate", args.swiftenv_recreate)
1086+
print("args.swiftenv_make", args.swiftenv_make)
1087+
print("args.swiftenv_script", args.swiftenv_script)
1088+
1089+
10471090
# Main entry point for the preset mode.
10481091
def main_preset():
10491092
parser = argparse.ArgumentParser(
@@ -1070,6 +1113,19 @@ def main_preset():
10701113
"--show-presets",
10711114
help="list all presets and exit",
10721115
action=arguments.action.optional_bool)
1116+
parser.add_argument(
1117+
"--swiftenv-path",
1118+
help="the absolute path to a directory containing replacement compiler commands")
1119+
parser.add_argument(
1120+
"--swiftenv-recreate",
1121+
help="a flag that, when present, will recreate the swiftenv",
1122+
action=arguments.action.optional_bool)
1123+
parser.add_argument(
1124+
"--swiftenv-script",
1125+
help="the absolute path to a script that takes the place of toolchain commands, default uses utils/swiftenv-script")
1126+
parser.add_argument(
1127+
"--swiftenv-make",
1128+
help="the absolute path to a script that will set up a swiftenv, default uses utils/swiftenv-make")
10731129
parser.add_argument(
10741130
"--distcc",
10751131
help="use distcc",
@@ -1125,6 +1181,17 @@ def main_preset():
11251181
if args.build_jobs:
11261182
build_script_args += ["--jobs", str(args.build_jobs)]
11271183

1184+
handle_swiftenv_args(args)
1185+
1186+
if args.swiftenv_path is not None:
1187+
build_script_args += ["--swiftenv-path", str(args.swiftenv_path)]
1188+
if args.swiftenv_recreate:
1189+
build_script_args += ["--swiftenv-recreate"]
1190+
if args.swiftenv_make is not None:
1191+
build_script_args += ["--swiftenv-make", str(args.swiftenv_make)]
1192+
if args.swiftenv_script is not None:
1193+
build_script_args += ["--swiftenv-script", str(args.swiftenv_script)]
1194+
11281195
diagnostics.note(
11291196
"using preset '" + args.preset + "', which expands to \n\n" +
11301197
shell.quote_command(build_script_args) + "\n")
@@ -1981,27 +2048,31 @@ iterations with -O",
19812048
metavar="PATH")
19822049

19832050
parser.add_argument(
1984-
"--host-cc",
2051+
"--cmake-c-compiler",
19852052
help="the absolute path to CC, the 'clang' compiler for the host "
19862053
"platform. Default is auto detected.",
19872054
type=arguments.type.executable,
19882055
metavar="PATH")
19892056
parser.add_argument(
1990-
"--host-cxx",
2057+
"--cmake-cxx-compiler",
19912058
help="the absolute path to CXX, the 'clang++' compiler for the host "
19922059
"platform. Default is auto detected.",
19932060
type=arguments.type.executable,
19942061
metavar="PATH")
19952062
parser.add_argument(
1996-
"--host-lipo",
1997-
help="the absolute path to lipo. Default is auto detected.",
1998-
type=arguments.type.executable,
1999-
metavar="PATH")
2063+
"--swiftenv-path",
2064+
help="the absolute path to a directory containing replacement compiler commands")
20002065
parser.add_argument(
2001-
"--host-libtool",
2002-
help="the absolute path to libtool. Default is auto detected.",
2003-
type=arguments.type.executable,
2004-
metavar="PATH")
2066+
"--swiftenv-recreate",
2067+
help="a flag that, when present, will recreate the swiftenv",
2068+
default="false",
2069+
action=arguments.action.optional_bool)
2070+
parser.add_argument(
2071+
"--swiftenv-script",
2072+
help="the absolute path to a script that takes the place of toolchain commands")
2073+
parser.add_argument(
2074+
"--swiftenv-make",
2075+
help="the absolute path to a script that will set up a swiftenv, default uses utils/swiftenv-make")
20052076
parser.add_argument(
20062077
"--distcc",
20072078
help="use distcc in pump mode",
@@ -2173,14 +2244,22 @@ iterations with -O",
21732244
# Prepare and validate toolchain
21742245
toolchain = host_toolchain(xcrun_toolchain=args.darwin_xcrun_toolchain)
21752246

2176-
if args.host_cc is not None:
2177-
toolchain.cc = args.host_cc
2178-
if args.host_cxx is not None:
2179-
toolchain.cxx = args.host_cxx
2180-
if args.host_lipo is not None:
2181-
toolchain.lipo = args.host_lipo
2182-
if args.host_libtool is not None:
2183-
toolchain.libtool = args.host_libtool
2247+
# Abstracted swiftenv_args for --preset and not
2248+
handle_swiftenv_args(args)
2249+
2250+
# Let args.cmake_c_compiler win over swiftenv's cc/cxx
2251+
if args.cmake_c_compiler is None and args.swiftenv_path is not None:
2252+
if os.path.exists(args.swiftenv_path + "/clang"):
2253+
args.cmake_c_compiler = args.swiftenv_path + "/clang"
2254+
if args.cmake_cxx_compiler is None and args.swiftenv_path is not None:
2255+
if os.path.exists(args.swiftenv_path + "/clang++"):
2256+
args.cmake_cxx_compiler = args.swiftenv_path + "/clang++"
2257+
2258+
if args.cmake_c_compiler is not None:
2259+
toolchain.cc = args.cmake_c_compiler
2260+
if args.cmake_cxx_compiler is not None:
2261+
toolchain.cxx = args.cmake_cxx_compiler
2262+
21842263
if args.cmake is not None:
21852264
toolchain.cmake = args.cmake
21862265

0 commit comments

Comments
 (0)