Skip to content

[embedded] Build the _Builtin_float overlay in embedded Swift mode #80951

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
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
55 changes: 53 additions & 2 deletions stdlib/public/ClangOverlays/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
if(NOT DEFINED SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT OR NOT SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT)
set(BUILTIN_FLOAT_SOURCES
linker-support/magic-symbols-for-install-name.c
)

set(BUILTIN_FLOAT_GYB_SOURCES
float.swift.gyb
)

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(BUILTIN_FLOAT_SWIFT_FLAGS -Xfrontend -module-abi-name -Xfrontend Darwin)
else()
Expand All @@ -9,10 +17,10 @@ if(NOT DEFINED SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT OR NOT SWIFT_BUILD_
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
IS_SDK_OVERLAY

linker-support/magic-symbols-for-install-name.c
${BUILTIN_FLOAT_SOURCES}

GYB_SOURCES
float.swift.gyb
${BUILTIN_FLOAT_GYB_SOURCES}

SWIFT_COMPILE_FLAGS
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
Expand All @@ -24,4 +32,47 @@ if(NOT DEFINED SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT OR NOT SWIFT_BUILD_

INSTALL_IN_COMPONENT stdlib
MACCATALYST_BUILD_FLAVOR zippered)

# Embedded clang overlays - embedded libraries are built as .swiftmodule only,
# i.e. there is no .o or .a file produced (no binary code is actually produced)
# and only users of a library are going to actually compile any needed code.
if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
add_custom_target(embedded-builtin_float)
add_dependencies(embedded-libraries embedded-builtin_float)

foreach(entry ${EMBEDDED_STDLIB_TARGET_TRIPLES})
string(REGEX REPLACE "[ \t]+" ";" list "${entry}")
list(GET list 0 arch)
list(GET list 1 mod)
list(GET list 2 triple)

set(SWIFT_SDK_embedded_ARCH_${arch}_MODULE "${mod}")
set(SWIFT_SDK_embedded_LIB_SUBDIR "embedded")
set(SWIFT_SDK_embedded_ARCH_${arch}_TRIPLE "${triple}")
set(SWIFT_SDK_embedded_PATH ${SWIFT_SDK_OSX_PATH})
set(SWIFT_SDK_embedded_ARCH_${arch}_PATH ${SWIFT_SDK_OSX_PATH})
set(SWIFT_SDK_embedded_USE_ISYSROOT TRUE)
add_swift_target_library_single(
embedded-builtin_float-${mod}
swift_Builtin_float
ONLY_SWIFTMODULE
IS_FRAGILE

${BUILTIN_FLOAT_SOURCES}
GYB_SOURCES
${BUILTIN_FLOAT_GYB_SOURCES}

SWIFT_COMPILE_FLAGS
${BUILTIN_FLOAT_SWIFT_FLAGS}
-Xcc -ffreestanding -enable-experimental-feature Embedded

MODULE_DIR "${CMAKE_BINARY_DIR}/lib/swift/embedded"
SDK "embedded"
ARCHITECTURE "${arch}"
DEPENDS embedded-stdlib-${mod}
INSTALL_IN_COMPONENT stdlib
)
add_dependencies(embedded-builtin_float embedded-builtin_float-${mod})
endforeach()
endif()
endif()
2 changes: 1 addition & 1 deletion stdlib/public/ClangOverlays/float.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public let FLT_RADIX = Double.radix

%for type, prefix in [('Float', 'FLT'), ('Double', 'DBL'), ('Float80', 'LDBL')]:
% if type == "Float80":
#if !os(Android) && !os(WASI) && !os(Windows) && (arch(i386) || arch(x86_64))
#if !os(Android) && !os(WASI) && !os(Windows) && !$Embedded && (arch(i386) || arch(x86_64))
% end
// Where does the 1 come from? C counts the usually-implicit leading
// significand bit, but Swift does not. Neither is really right or wrong.
Expand Down