Skip to content

[cxx-interop] Add infrastructure to build and run tests on multiple targets. #36082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/Interop/Cxx/class/debug-info-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swiftxx-frontend -I %S/Inputs %s -emit-ir -g | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir -g | %FileCheck %s)

// Validate that we don't crash when trying to deserialize C++ type debug info.
// Note, however, that the actual debug info is not generated, see SR-13223.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %swift -I %S/Inputs -enable-cxx-interop -emit-ir %s | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import Destructors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -enable-cxx-interop -I %S/Inputs %s -emit-ir | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import Destructors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import ConstructorCallsFunctionFromNestedStruct

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import ConstructorCallsFunction

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import ConstructorCallsMethod

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import FieldInitCallsFunction

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import MethodCallsFunction

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import MethodCallsMethodFromNestedStruct

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import MethodCallsMethod

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop -validate-tbd-against-ir=none | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir -validate-tbd-against-ir=none | %FileCheck %s)

// TODO: See why -validate-tbd-against-ir=none is needed here (SR-14069)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swiftxx-frontend -I %S/Inputs %s -emit-ir | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

// Verify that non-trival/address-only C++ classes are constructed and accessed
// correctly. Make sure that we correctly IRGen functions that construct
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/extern-var/extern-var-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import ExternVar

Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/namespace/classes-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir -I %S/Inputs -enable-cxx-interop %s | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import Classes

Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/namespace/free-functions-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir -I %S/Inputs -enable-cxx-interop %s | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import FreeFunctions

Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/namespace/templates-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir -I %S/Inputs -enable-cxx-interop %s | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import Templates

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir -I %S/Inputs -enable-cxx-interop %s | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import InlineStaticMemberVar

Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/static/static-member-func-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import StaticMemberFunc

Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/templates/function-template-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import FunctionTemplates

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import LinkageOfSwiftSymbolsForImportedTypes

Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/templates/mangling-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

import Mangling

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

// REQUIRES: rdar67257133

import PartiallyPreDefinedClassTemplate

public func getWrappedMagicInt() -> CInt {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -enable-cxx-interop -I %S/Inputs %s -emit-ir | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

// This tests output needs to be updated for arm64.
// XFAIL: CPU=arm64e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
// RUN: %cxx-all-targets(-I %S/Inputs %s -emit-ir | %FileCheck %s)

// This test checks that the compiler uses well-known witness tables for types
// that have the appropriate size/shape (for example, { i8 x 4 } -> i32).
Expand Down
10 changes: 10 additions & 0 deletions test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,16 @@ if platform.system() != 'Darwin' or swift_test_mode == 'optimize_none_with_impli
#

config.substitutions.append(('%target-clangxx', '%s -std=c++11' % config.target_clang))
config.substitutions.append(('%cxx-all-targets\(([^)]+)\)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that moving this to the next commit is better. Additionally, I'm not sure how I feel about this - this is a really really really complex way to do this. We already push lit well beyond what it should be used as, and this is particularly horrendous. Can we use a different approach for this? I think that adding the subdirectory as a multiple test suites in a lit.local.cfg might be better.

SubstituteCaptures(r"%s -disable-legacy-type-info -enable-cxx-interop -I %s/uswift-macos-arm64/swift -target arm64-apple-macosx10.9 \1 && "
r"%s -disable-legacy-type-info -enable-cxx-interop -I %s/uswift-macos-x86_64/swift -target x86_64-apple-macosx10.9 \1 && "
r"%s -enable-cxx-interop -I %s/uswift-linux-armv7/swift -target armv7-unknown-linux-androideabi \1 &&"
r"%s -enable-cxx-interop -I %s/uswift-windows-x86_64/swift -target x86_64-unknown-windows-msvc \1 "
% (config.swift_frontend, shell_quote(os.path.realpath(swift_obj_root).replace("\\", "/")),
config.swift_frontend, shell_quote(os.path.realpath(swift_obj_root).replace("\\", "/")),
config.swift_frontend, shell_quote(os.path.realpath(swift_obj_root).replace("\\", "/")),
config.swift_frontend, shell_quote(os.path.realpath(swift_obj_root).replace("\\", "/"))) )
))
config.substitutions.append(('%target-swiftxx-frontend', '%s -enable-cxx-interop' % config.target_swift_frontend))

config.substitutions.append(('%target-runtime', config.target_runtime))
Expand Down
110 changes: 96 additions & 14 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ NINJA_SOURCE_DIR="${WORKSPACE}/ninja"
SWIFT_SOURCE_DIR="${WORKSPACE}/swift"
LLVM_SOURCE_DIR="${WORKSPACE}/llvm-project/llvm"
CMARK_SOURCE_DIR="${WORKSPACE}/cmark"
USWIFT_SOURCE_DIR="${WORKSPACE}/uswift"
LLDB_SOURCE_DIR="${WORKSPACE}/llvm-project/lldb"
LLBUILD_SOURCE_DIR="${WORKSPACE}/llbuild"
STRESSTEST_PACKAGE_DIR="${WORKSPACE}/swift-stress-tester"
Expand All @@ -1266,6 +1267,7 @@ PRODUCTS=(llvm)
[[ "${SKIP_BUILD_LIBCXX}" ]] || PRODUCTS+=(libcxx)
[[ "${SKIP_BUILD_LIBICU}" ]] || PRODUCTS+=(libicu)
[[ "${SKIP_BUILD_SWIFT}" ]] || PRODUCTS+=(swift)
PRODUCTS+=(uswift)
[[ "${SKIP_BUILD_LLDB}" ]] || PRODUCTS+=(lldb)
[[ "${SKIP_BUILD_LIBDISPATCH}" ]] || PRODUCTS+=(libdispatch)
[[ "${SKIP_BUILD_STATIC_LIBDISPATCH}" ]] || PRODUCTS+=(libdispatch_static)
Expand Down Expand Up @@ -1356,6 +1358,8 @@ function build_directory_bin() {
;;
libicu)
;;
uswift)
;;
*)
echo "error: unknown product: ${product}"
exit 1
Expand Down Expand Up @@ -1759,6 +1763,91 @@ for host in "${ALL_HOSTS[@]}"; do
build_targets=(all)
;;

uswift)
uswift_targets=(
"macos-arm64" "arm64-apple-macosx10.9"
"macos-x86_64" "x86_64-apple-macosx10.9"
"linux-armv7" "armv7-unknown-linux-androideabi"
"windows-x86_64" "x86_64-unknown-windows-msvc"
)
uswift_targets_length=${#uswift_targets[@]}

cmake_options=(
"${cmake_options[@]}"
-D BUILD_SHARED_LIBS=NO
-D CMAKE_Swift_COMPILER_WORKS=YES
-D CMAKE_BUILD_TYPE=Release
-D CMAKE_Swift_COMPILER=$(build_directory ${host} swift)/bin/swiftc
)

# Build uswift for each target.
for (( i=1; i<${uswift_targets_length}+1; i+=2 ));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Why not do:

for target in ${uswift_targets[@]} ; do
done

do
uswift_target_name=${uswift_targets[$i-1]}
uswift_target=${uswift_targets[$i]}
all_cmake_options=(
"${cmake_options[@]}"
-D CMAKE_Swift_COMPILER_TARGET=${uswift_target}
)

if [[ "$uswift_target_name" == "windows-x86_64" ]] ; then
all_cmake_options=(
"${all_cmake_options[@]}"
-D CMAKE_Swift_FLAGS="-use-ld=$(build_directory ${LOCAL_HOST} llvm)/bin/lld-link"
)
else
all_cmake_options=(
"${all_cmake_options[@]}"
-D CMAKE_Swift_FLAGS="-Xfrontend -disable-legacy-type-info"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do this unconditionally?

)
fi

build_dir=$(build_directory ${uswift_target_name} ${product})

generator_output_path=""
if [[ "${CMAKE_GENERATOR}" == "Ninja" ]] ; then
generator_output_path="${build_dir}/build.ninja"
fi

# Configure if necessary.
cmake_cache_path="${build_dir}/CMakeCache.txt"
if [[ "${RECONFIGURE}" || ! -f "${cmake_cache_path}" || \
( ! -z "${generator_output_path}" && ! -f "${generator_output_path}" ) ]] ; then
call mkdir -p "${build_dir}"

# Use `cmake-file-api` in case it is available.
call mkdir -p "${build_dir}/.cmake/api/v1/query"
call touch "${build_dir}/.cmake/api/v1/query/codemodel-v2" "${build_dir}/.cmake/api/v1/query/cache-v2"

if [[ -n "${DISTCC}" ]]; then
EXTRA_DISTCC_OPTIONS=("DISTCC_HOSTS=localhost,lzo,cpp")
fi
with_pushd "${build_dir}" \
call env "${EXTRA_DISTCC_OPTIONS[@]}" "${CMAKE}" "${all_cmake_options[@]}" "${EXTRA_CMAKE_OPTIONS[@]}" "${source_dir}"
fi

# Note: unconditionally build uswift because it is required for running some tests.
if [[ "${CMAKE_GENERATOR}" == "Xcode" ]] ; then
# Xcode generator uses "ALL_BUILD" instead of "all".
# Also, xcodebuild uses -target instead of bare names.
build_targets=("${build_targets[@]/all/ALL_BUILD}")
build_targets=("${build_targets[@]/#/${BUILD_TARGET_FLAG} }")

# Xcode can't restart itself if it turns out we need to reconfigure.
# Do an advance build to handle that.
call "${CMAKE_BUILD[@]}" "${build_dir}" $(cmake_config_opt ${product})
fi

call "${CMAKE_BUILD[@]}" "${build_dir}" $(cmake_config_opt ${product}) -- "${BUILD_ARGS[@]}" ${build_targets[@]}

# Copy over the uswift build.
cp -a $(build_directory ${uswift_target_name} uswift) $(build_directory ${host} swift)
done

# We've already run cmake/build so we can just break out here.
continue
;;

llvm)
if [[ -n "${LLVM_NINJA_TARGETS_FOR_CROSS_COMPILE_HOSTS}" && $(is_cross_tools_host ${host}) ]] ; then
build_targets=("${LLVM_NINJA_TARGETS_FOR_CROSS_COMPILE_HOSTS[@]}")
Expand Down Expand Up @@ -1817,7 +1906,7 @@ for host in "${ALL_HOSTS[@]}"; do
"${llvm_cmake_options[@]}"
)

llvm_enable_projects=("clang")
llvm_enable_projects=("clang" "lld")

if [[ ! "${SKIP_BUILD_COMPILER_RT}" && ! $(is_cross_tools_host ${host}) ]]; then
llvm_enable_projects+=("compiler-rt")
Expand All @@ -1827,18 +1916,6 @@ for host in "${ALL_HOSTS[@]}"; do
llvm_enable_projects+=("clang-tools-extra")
fi

# On non-Darwin platforms, build lld so we can always have a
# linker that is compatible with the swift we are using to
# compile the stdlib.
#
# This makes it easier to build target stdlibs on systems that
# have old toolchains without more modern linker features.
if [[ "$(uname -s)" != "Darwin" ]] ; then
if [[ ! "${SKIP_BUILD_LLD}" ]]; then
llvm_enable_projects+=("lld")
fi
fi

cmake_options+=(
-DLLVM_ENABLE_PROJECTS="$(join ";" ${llvm_enable_projects[@]})"
)
Expand Down Expand Up @@ -1898,7 +1975,6 @@ for host in "${ALL_HOSTS[@]}"; do
;;

swift)

if [[ "${ANDROID_API_LEVEL}" ]]; then
cmake_options=(
"${cmake_options[@]}"
Expand Down Expand Up @@ -2808,6 +2884,9 @@ for host in "${ALL_HOSTS[@]}"; do
libcxx)
continue # We don't test libc++
;;
uswift)
continue # We don't test uswift
;;
swift)
executable_target=
results_targets=
Expand Down Expand Up @@ -3159,6 +3238,9 @@ for host in "${ALL_HOSTS[@]}"; do
fi
INSTALL_TARGETS=install-swift-components
;;
uswift)
continue
;;
llbuild)
if [[ -z "${INSTALL_LLBUILD}" ]] ; then
continue
Expand Down
4 changes: 3 additions & 1 deletion utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def create_argument_parser():
help='enable code coverage analysis in Swift (false, not-merged, '
'merged).')

option('--swift-disable-dead-stripping', toggle_true,
option('--swift-disable-dead-stripping', toggle_true,
help="Turn off Darwin-specific dead stripping for Swift host tools")

option('--build-subdir', store,
Expand Down Expand Up @@ -1252,6 +1252,8 @@ def create_argument_parser():
help='skip building llvm')
option('--skip-build-swift', toggle_false('build_swift'),
help='skip building swift')
option('--skip-build-uswift', toggle_false('build_uswift'),
help='skip building uswift')

# We need to list --skip-test-swift explicitly because otherwise argparse
# will auto-expand arguments like --skip-test-swift to the only known
Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'build_foundation': False,
'build_cmark': True,
'build_swift': True,
'build_uswift': True,
'build_llvm': True,
'build_freebsd': True,
'build_ios': True,
Expand Down Expand Up @@ -597,6 +598,7 @@ class BuildScriptImplOption(_BaseOption):
DisableOption('--skip-build-cmark', dest='build_cmark'),
DisableOption('--skip-build-llvm', dest='build_llvm'),
DisableOption('--skip-build-swift', dest='build_swift'),
DisableOption('--skip-build-uswift', dest='build_uswift'),

DisableOption('--skip-build-android', dest='build_android'),
DisableOption('--skip-build-benchmarks', dest='build_benchmarks'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def convert_to_impl_arguments(self):
(args.build_cmark, "cmark"),
(args.build_llvm, "llvm"),
(args.build_swift, "swift"),
(args.build_uswift, "uswift"),
(args.build_foundation, "foundation"),
(args.build_xctest, "xctest"),
(args.build_lldb, "lldb"),
Expand Down Expand Up @@ -562,6 +563,8 @@ def compute_product_pipelines(self):
is_enabled=self.args.build_libicu)
builder.add_impl_product(products.Swift,
is_enabled=self.args.build_swift)
builder.add_impl_product(products.USwift,
is_enabled=self.args.build_uswift)
builder.add_impl_product(products.LLDB,
is_enabled=self.args.build_lldb)

Expand Down
Loading