Skip to content

Revert reverting the 5.6 backdeploy #60711

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

Merged
merged 2 commits into from
Sep 6, 2022
Merged
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
4 changes: 4 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
# Add the SDK directory for the host platform.
target_link_directories(${target} PRIVATE "${sdk_dir}")

# A backup in case the toolchain doesn't have one of the compatibility libraries.
target_link_directories(${target} PRIVATE
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")

# Include the abi stable system stdlib in our rpath.
set(swift_runtime_rpath "/usr/lib/swift")

Expand Down
1 change: 1 addition & 0 deletions include/swift/Frontend/BackDeploymentLibs.def
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50")
BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51")
BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements")
BACK_DEPLOYMENT_LIB((5, 4), all, "swiftCompatibilityConcurrency")
BACK_DEPLOYMENT_LIB((5, 6), all, "swiftCompatibility56")

#undef BACK_DEPLOYMENT_LIB
2 changes: 2 additions & 0 deletions lib/Driver/DarwinToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments,
runtimeCompatibilityVersion = llvm::VersionTuple(5, 1);
} else if (value.equals("5.5")) {
runtimeCompatibilityVersion = llvm::VersionTuple(5, 5);
} else if (value.equals("5.6")) {
runtimeCompatibilityVersion = llvm::VersionTuple(5, 6);
} else if (value.equals("none")) {
runtimeCompatibilityVersion = None;
} else {
Expand Down
2 changes: 2 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
runtimeCompatibilityVersion = llvm::VersionTuple(5, 1);
} else if (version.equals("5.5")) {
runtimeCompatibilityVersion = llvm::VersionTuple(5, 5);
} else if (version.equals("5.6")) {
runtimeCompatibilityVersion = llvm::VersionTuple(5, 6);
} else {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
versionArg->getAsString(Args), version);
Expand Down
2 changes: 2 additions & 0 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ include(StdlibOptions)
# End of user-configurable options.
#

set(SWIFT_STDLIB_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

# Remove llvm-project/llvm/include directory from -I search part when building
# the stdlib. We have our own fork of LLVM includes (Support, ADT) in
# stdlib/include/llvm and we don't want to silently use headers from LLVM.
Expand Down
4 changes: 3 additions & 1 deletion stdlib/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
add_subdirectory(legacy_layouts)
add_subdirectory(Compatibility50)
add_subdirectory(Compatibility51)
add_subdirectory(Compatibility56)
add_subdirectory(CompatibilityDynamicReplacements)
add_subdirectory(CompatibilityConcurrency)
add_subdirectory(CompatibilityThreading)
Expand All @@ -63,6 +64,7 @@ if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
swiftCompatibilityConcurrency${vsuffix}
swiftCompatibilityDynamicReplacements${vsuffix}
swiftCompatibility50${vsuffix}
swiftCompatibility51${vsuffix})
swiftCompatibility51${vsuffix}
swiftCompatibility56${vsuffix})
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS HostCompatibilityLibs)
endif()
39 changes: 39 additions & 0 deletions stdlib/toolchain/Compatibility56/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
set(library_name "swiftCompatibility56")

include_directories("include/" "${SWIFT_STDLIB_SOURCE_DIR}")

add_swift_target_library("${library_name}" STATIC
Overrides.cpp
Concurrency/Task.cpp
Concurrency/Error.cpp
Concurrency/Actor.cpp
Concurrency/AsyncLet.cpp

TARGET_SDKS ${SWIFT_DARWIN_PLATFORMS}

C_COMPILE_FLAGS ${CXX_COMPILE_FLAGS}
LINK_FLAGS ${CXX_LINK_FLAGS}
INCORPORATE_OBJECT_LIBRARIES swiftThreading
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
DEPLOYMENT_VERSION_OSX ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX}
DEPLOYMENT_VERSION_IOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS}
DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS}
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS}

INSTALL_IN_COMPONENT compiler
INSTALL_WITH_SHARED)


# FIXME: We need a more flexible mechanism to add lipo targets generated by
# add_swift_target_library to the ALL target. Until then this hack is necessary
# to ensure these libraries build.
foreach(sdk ${SWIFT_SDKS})
set(target_name "${library_name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
if(NOT TARGET "${target_name}")
continue()
endif()

set_target_properties("${target_name}"
PROPERTIES
EXCLUDE_FROM_ALL FALSE)
endforeach()
137 changes: 137 additions & 0 deletions stdlib/toolchain/Compatibility56/CompatibilityOverride.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//===--- CompatibiltyOverride.h - Back-deploying compatibility fixes --*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Support back-deploying compatibility fixes for newer apps running on older runtimes.
//
//===----------------------------------------------------------------------===//

#ifndef COMPATIBILITY_OVERRIDE_H
#define COMPATIBILITY_OVERRIDE_H

#include "public/runtime/Private.h"

#include "Runtime/Concurrency.h"
#include "swift/Runtime/Metadata.h"
#include "swift/Runtime/Once.h"
#include <type_traits>

namespace swift {

// Macro utilities.
#define COMPATIBILITY_UNPAREN(...) __VA_ARGS__
#define COMPATIBILITY_CONCAT2(x, y) x##y
#define COMPATIBILITY_CONCAT(x, y) COMPATIBILITY_CONCAT2(x, y)

// This ridiculous construct will remove the parentheses from the argument and
// add a trailing comma, or will produce nothing when passed no argument. For
// example:
// COMPATIBILITY_UNPAREN_WITH_COMMA((1, 2, 3)) -> 1, 2, 3,
// COMPATIBILITY_UNPAREN_WITH_COMMA((4)) -> 4,
// COMPATIBILITY_UNPAREN_WITH_COMMA() ->
#define COMPATIBILITY_UNPAREN_WITH_COMMA(x) \
COMPATIBILITY_CONCAT(COMPATIBILITY_UNPAREN_ADD_TRAILING_COMMA_, \
COMPATIBILITY_UNPAREN_WITH_COMMA2 x)
#define COMPATIBILITY_UNPAREN_WITH_COMMA2(...) PARAMS(__VA_ARGS__)
#define COMPATIBILITY_UNPAREN_ADD_TRAILING_COMMA_PARAMS(...) __VA_ARGS__,
#define COMPATIBILITY_UNPAREN_ADD_TRAILING_COMMA_COMPATIBILITY_UNPAREN_WITH_COMMA2

// This ridiculous construct will preserve the parentheses around the argument,
// or will produce an empty pair of parentheses when passed no argument. For
// example:
// COMPATIBILITY_PAREN((1, 2, 3)) -> (1, 2, 3)
// COMPATIBILITY_PAREN((4)) -> (4)
// COMPATIBILITY_PAREN() -> ()
#define COMPATIBILITY_PAREN(x) \
COMPATIBILITY_CONCAT(COMPATIBILITY_PAREN_, COMPATIBILITY_PAREN2 x)
#define COMPATIBILITY_PAREN2(...) PARAMS(__VA_ARGS__)
#define COMPATIBILITY_PAREN_PARAMS(...) (__VA_ARGS__)
#define COMPATIBILITY_PAREN_COMPATIBILITY_PAREN2 ()

// Include path computation. Code that includes this file can write
// `#include COMPATIBILITY_OVERRIDE_INCLUDE_PATH` to include the appropriate
// .def file for the current library.
#define COMPATIBILITY_OVERRIDE_INCLUDE_PATH_swiftRuntime \
"CompatibilityOverrideRuntime.def"
#define COMPATIBILITY_OVERRIDE_INCLUDE_PATH_swift_Concurrency \
"CompatibilityOverrideConcurrency.def"

#define COMPATIBILITY_OVERRIDE_INCLUDE_PATH \
COMPATIBILITY_CONCAT(COMPATIBILITY_OVERRIDE_INCLUDE_PATH_, \
SWIFT_TARGET_LIBRARY_NAME)

// Compatibility overrides are only supported on Darwin.
#ifndef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES
#if !(defined(__APPLE__) && defined(__MACH__))
#define SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES
#endif
#endif

#ifdef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES

# error Back-deployment library must always be built with compatibilty overrides

#else // #ifdef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES

// Override section name computation. `COMPATIBILITY_OVERRIDE_SECTION_NAME` will
// resolve to string literal containing the appropriate section name for the
// current library.
#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swift_Concurrency "__s_async_hook"

#define COMPATIBILITY_OVERRIDE_SECTION_NAME \
COMPATIBILITY_CONCAT(COMPATIBILITY_OVERRIDE_SECTION_NAME_, \
SWIFT_TARGET_LIBRARY_NAME)

// Create typedefs for function pointers to call the original implementation.
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
ccAttrs typedef ret(*Original_##name) COMPATIBILITY_PAREN(typedArgs);
#include "CompatibilityOverrideRuntime.def"
#include "CompatibilityOverrideConcurrency.def"
#undef OVERRIDE


// Create typedefs for override function pointers.
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
ccAttrs typedef ret (*Override_##name)(COMPATIBILITY_UNPAREN_WITH_COMMA( \
typedArgs) Original_##name originalImpl);
#include "CompatibilityOverrideRuntime.def"
#include "CompatibilityOverrideConcurrency.def"
#undef OVERRIDE

// Create declarations for getOverride functions.
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
Override_ ## name getOverride_ ## name();
#include "CompatibilityOverrideRuntime.def"
#include "CompatibilityOverrideConcurrency.def"
#undef OVERRIDE

/// Used to define an override point. The override point #defines the appropriate
/// OVERRIDE macro from CompatibilityOverride.def to this macro, then includes
/// the file to generate the override points. The original implementation of the
/// functionality must be available as swift_funcNameHereImpl.
#define COMPATIBILITY_OVERRIDE(name, ret, attrs, ccAttrs, namespace, \
typedArgs, namedArgs) \
attrs ccAttrs ret namespace swift_##name COMPATIBILITY_PAREN(typedArgs) { \
static Override_##name Override; \
static swift_once_t Predicate; \
swift_once( \
&Predicate, [](void *) { Override = getOverride_##name(); }, nullptr); \
if (Override != nullptr) \
return Override(COMPATIBILITY_UNPAREN_WITH_COMMA(namedArgs) \
swift_##name##Impl); \
return swift_##name##Impl COMPATIBILITY_PAREN(namedArgs); \
}

#endif // #else SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES

} /* end namespace swift */

#endif /* COMPATIBILITY_OVERRIDE_H */
Loading