Skip to content

Commit cbf3c58

Browse files
authored
Merge pull request swiftlang#40285 from eeckstein/libswift-build-fixes
cmake: three fixes for the libswift build
2 parents 5a1e042 + dbf74b5 commit cbf3c58

File tree

19 files changed

+128
-52
lines changed

19 files changed

+128
-52
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,9 +1089,6 @@ if(SWIFT_ENABLE_DISPATCH)
10891089
include(Libdispatch)
10901090
endif()
10911091

1092-
add_bootstrapping_target(0)
1093-
add_bootstrapping_target(1)
1094-
10951092
# Add all of the subdirectories, where we actually do work.
10961093

10971094
###############

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,15 @@ function(add_swift_host_tool executable)
974974
INSTALL_RPATH "${RPATH_LIST}")
975975
976976
elseif(SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX" AND ASHT_HAS_LIBSWIFT AND LIBSWIFT_BUILD_MODE)
977+
set(swiftrt "swiftImageRegistrationObject${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}")
977978
if(LIBSWIFT_BUILD_MODE STREQUAL "HOSTTOOLS")
978979
# At build time and and run time, link against the swift libraries in the
979980
# installed host toolchain.
980981
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_LIBSWIFT} DIRECTORY)
981982
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
982983
set(host_lib_dir "${swift_dir}/lib/swift/linux")
983984
985+
target_link_libraries(${executable} PRIVATE ${swiftrt})
984986
target_link_libraries(${executable} PRIVATE "swiftCore")
985987
986988
target_link_directories(${executable} PRIVATE ${host_lib_dir})
@@ -994,6 +996,7 @@ function(add_swift_host_tool executable)
994996
if (NOT "${ASHT_BOOTSTRAPPING}" STREQUAL "0")
995997
get_bootstrapping_swift_lib_dir(bs_lib_dir "${ASHT_BOOTSTRAPPING}")
996998
target_link_directories(${executable} PRIVATE ${bs_lib_dir})
999+
target_link_libraries(${executable} PRIVATE ${swiftrt})
9971000
target_link_libraries(${executable} PRIVATE "swiftCore")
9981001
endif()
9991002

cmake/modules/SwiftUtils.cmake

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,35 +111,6 @@ function(get_bootstrapping_swift_lib_dir bs_lib_dir bootstrapping)
111111
set(bs_lib_dir ${bs_lib_dir} PARENT_SCOPE)
112112
endfunction()
113113

114-
function(add_bootstrapping_target bootstrapping)
115-
if(${LIBSWIFT_BUILD_MODE} MATCHES "BOOTSTRAPPING.*")
116-
117-
set(target "bootstrapping${bootstrapping}-all")
118-
add_custom_target(${target})
119-
120-
if(${LIBSWIFT_BUILD_MODE} STREQUAL "BOOTSTRAPPING")
121-
set(lib_target "bootstrapping${bootstrapping}-corelib")
122-
add_custom_target(${lib_target})
123-
add_dependencies(${target} ${lib_target})
124-
endif()
125-
126-
if(SWIFT_PATH_TO_LIBICU_BUILD)
127-
# Need to symlink the libicu libraries to be able to run
128-
# the bootstrapping compiler with a custom library path.
129-
get_bootstrapping_path(output_dir
130-
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" "${bootstrapping}")
131-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
132-
message("TODO: support for copying ICU libraries on Windows")
133-
endif()
134-
add_custom_command(TARGET "${target}" POST_BUILD
135-
COMMAND
136-
"ln" "-s" "-f" "${SWIFT_PATH_TO_LIBICU_BUILD}/lib/libicu*" "."
137-
WORKING_DIRECTORY "${output_dir}"
138-
COMMENT "symlink ICU libraries for bootstrapping stage ${bootstrapping}")
139-
endif()
140-
endif()
141-
endfunction()
142-
143114
function(is_build_type_optimized build_type result_var_name)
144115
if("${build_type}" STREQUAL "Debug")
145116
set("${result_var_name}" FALSE PARENT_SCOPE)

include/swift/AST/Builtins.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,9 @@ BUILTIN_MISC_OPERATION(InitializeDistributedRemoteActor,
770770
BUILTIN_MISC_OPERATION(ResumeNonThrowingContinuationReturning,
771771
"resumeNonThrowingContinuationReturning", "", Special)
772772

773+
/// targetOSVersionAtLeast has type (Builtin.Int32, Builtin.Int32, Builtin.Int32) -> Builtin.Int32
774+
BUILTIN_MISC_OPERATION(TargetOSVersionAtLeast, "targetOSVersionAtLeast", "n", Special)
775+
773776
/// Resume a throwing continuation normally with the given result.
774777
BUILTIN_MISC_OPERATION(ResumeThrowingContinuationReturning,
775778
"resumeThrowingContinuationReturning", "", Special)

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,16 @@ FUNCTION(TSanInoutAccess, __tsan_external_write, C_CC, AlwaysAvailable,
16911691
ATTRS(NoUnwind),
16921692
EFFECT(NoEffect))
16931693

1694+
// int32 __isPlatformVersionAtLeast(uint32_t platform, uint32_t major,
1695+
// uint32_t minor, uint32_t patch);
1696+
// This a C builtin provided by compiler-rt.
1697+
FUNCTION(PlatformVersionAtLeast, __isPlatformVersionAtLeast,
1698+
C_CC, AlwaysAvailable,
1699+
RETURNS(Int32Ty),
1700+
ARGS(Int32Ty, Int32Ty, Int32Ty, Int32Ty),
1701+
ATTRS(NoUnwind),
1702+
EFFECT(NoEffect))
1703+
16941704
FUNCTION(GetKeyPath, swift_getKeyPath, C_CC, AlwaysAvailable,
16951705
RETURNS(RefCountedPtrTy),
16961706
ARGS(Int8PtrTy, Int8PtrTy),

lib/AST/Builtins.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,12 @@ static ValueDecl *getBuildDefaultActorExecutorRef(ASTContext &ctx,
15781578
_executor);
15791579
}
15801580

1581+
static ValueDecl *getTargetOSVersionAtLeast(ASTContext &Context,
1582+
Identifier Id) {
1583+
auto int32Type = BuiltinIntegerType::get(32, Context);
1584+
return getBuiltinFunction(Id, {int32Type, int32Type, int32Type}, int32Type);
1585+
}
1586+
15811587
static ValueDecl *getBuildOrdinarySerialExecutorRef(ASTContext &ctx,
15821588
Identifier id) {
15831589
return getBuiltinFunction(ctx, id, _thin,
@@ -2825,6 +2831,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
28252831
case BuiltinValueKind::CreateAsyncTaskInGroup:
28262832
return getCreateAsyncTaskInGroup(Context, Id);
28272833

2834+
case BuiltinValueKind::TargetOSVersionAtLeast:
2835+
return getTargetOSVersionAtLeast(Context, Id);
2836+
28282837
case BuiltinValueKind::ConvertTaskToJob:
28292838
return getConvertTaskToJob(Context, Id);
28302839

lib/IRGen/GenBuiltin.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,15 @@ if (Builtin.ID == BuiltinValueKind::id) { \
12231223
return;
12241224
}
12251225

1226+
if (Builtin.ID == BuiltinValueKind::TargetOSVersionAtLeast) {
1227+
auto major = args.claimNext();
1228+
auto minor = args.claimNext();
1229+
auto patch = args.claimNext();
1230+
auto result = IGF.emitTargetOSVersionAtLeastCall(major, minor, patch);
1231+
out.add(result);
1232+
return;
1233+
}
1234+
12261235
if (Builtin.ID == BuiltinValueKind::Swift3ImplicitObjCEntrypoint) {
12271236
llvm::Value *entrypointArgs[7];
12281237
auto argIter = IGF.CurFn->arg_begin();

lib/IRGen/IRGenFunction.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/IR/Function.h"
2323
#include "llvm/Support/CommandLine.h"
2424
#include "llvm/Support/raw_ostream.h"
25+
#include "llvm/BinaryFormat/MachO.h"
2526

2627
#include "Callee.h"
2728
#include "Explosion.h"
@@ -289,6 +290,35 @@ void IRGenFunction::emitTSanInoutAccessCall(llvm::Value *address) {
289290
Builder.CreateCall(fn, {castAddress, callerPC, castTag});
290291
}
291292

293+
// This is shamelessly copied from clang's codegen. We need to get the clang
294+
// functionality into a shared header so that platforms only
295+
// needs to be updated in one place.
296+
static unsigned getBaseMachOPlatformID(const llvm::Triple &TT) {
297+
switch (TT.getOS()) {
298+
case llvm::Triple::Darwin:
299+
case llvm::Triple::MacOSX:
300+
return llvm::MachO::PLATFORM_MACOS;
301+
case llvm::Triple::IOS:
302+
return llvm::MachO::PLATFORM_IOS;
303+
case llvm::Triple::TvOS:
304+
return llvm::MachO::PLATFORM_TVOS;
305+
case llvm::Triple::WatchOS:
306+
return llvm::MachO::PLATFORM_WATCHOS;
307+
default:
308+
return /*Unknown platform*/ 0;
309+
}
310+
}
311+
312+
llvm::Value *
313+
IRGenFunction::emitTargetOSVersionAtLeastCall(llvm::Value *major,
314+
llvm::Value *minor,
315+
llvm::Value *patch) {
316+
auto *fn = cast<llvm::Function>(IGM.getPlatformVersionAtLeastFn());
317+
318+
llvm::Value *platformID =
319+
llvm::ConstantInt::get(IGM.Int32Ty, getBaseMachOPlatformID(IGM.Triple));
320+
return Builder.CreateCall(fn, {platformID, major, minor, patch});
321+
}
292322

293323
/// Initialize a relative indirectable pointer to the given value.
294324
/// This always leaves the value in the direct state; if it's not a

lib/IRGen/IRGenFunction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class IRGenFunction {
295295

296296
void emitTSanInoutAccessCall(llvm::Value *address);
297297

298+
llvm::Value *emitTargetOSVersionAtLeastCall(llvm::Value *major,
299+
llvm::Value *minor,
300+
llvm::Value *patch);
301+
298302
llvm::Value *emitProjectBoxCall(llvm::Value *box, llvm::Value *typeMetadata);
299303

300304
llvm::Value *emitAllocEmptyBoxCall();

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, Swift3ImplicitObjCEntrypoint)
776776
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, PoundAssert)
777777
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, GlobalStringTablePointer)
778778
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, TypePtrAuthDiscriminator)
779+
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, TargetOSVersionAtLeast)
779780
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, IntInstrprofIncrement)
780781
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, Move)
781782
BUILTIN_OPERAND_OWNERSHIP(UnownedInstantaneousUse, Copy)

0 commit comments

Comments
 (0)