Skip to content

Commit e22aedb

Browse files
committed
[embedded] Implicitly define __APPLE__ and __MACH__ when on -apple-none triples
1 parent 643fa6c commit e22aedb

File tree

12 files changed

+32
-21
lines changed

12 files changed

+32
-21
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,17 @@ importer::getNormalInvocationArguments(
631631
});
632632
}
633633

634+
// To support -apple-none triples, which are non-Darwin, we need to #define
635+
// a few things that the Apple SDKs expect.
636+
if (triple.getVendor() == llvm::Triple::VendorType::Apple) {
637+
invocationArgStrs.insert(invocationArgStrs.end(),
638+
{"-D__APPLE__", "-D__MACH__"});
639+
}
640+
641+
if (triple.isOSBinFormatWasm()) {
642+
invocationArgStrs.insert(invocationArgStrs.end(), {"-D__wasi__"});
643+
}
644+
634645
if (triple.isOSWindows()) {
635646
switch (triple.getArch()) {
636647
default: llvm_unreachable("unsupported Windows architecture");

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
218218
if(NOT "${mod}" MATCHES "-macos$")
219219
continue()
220220
endif()
221-
set(extra_c_compile_flags -D__MACH__ -D__APPLE__ -ffreestanding)
222-
set(extra_swift_compile_flags -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding)
221+
set(extra_c_compile_flags -ffreestanding)
222+
set(extra_swift_compile_flags -Xcc -ffreestanding)
223223
endif()
224224

225225
set(SWIFT_SDK_embedded_ARCH_${mod}_MODULE "${mod}")

stdlib/public/Platform/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
113113
Darwin.swift.gyb
114114

115115
SWIFT_COMPILE_FLAGS
116-
-Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding -enable-experimental-feature Embedded
116+
-Xcc -ffreestanding -enable-experimental-feature Embedded
117117
C_COMPILE_FLAGS
118-
-D__MACH__ -D__APPLE__ -ffreestanding
118+
-ffreestanding
119119
MODULE_DIR "${CMAKE_BINARY_DIR}/lib/swift/embedded"
120120
SDK "embedded"
121121
ARCHITECTURE "${arch}"

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
422422
${SWIFTLIB_EMBEDDED_SOURCES}
423423
GYB_SOURCES ${SWIFTLIB_EMBEDDED_GYB_SOURCES}
424424
SWIFT_COMPILE_FLAGS
425-
${swift_stdlib_compile_flags} -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding -enable-experimental-feature Embedded
425+
${swift_stdlib_compile_flags} -Xcc -ffreestanding -enable-experimental-feature Embedded
426426
-Xfrontend -enable-ossa-modules
427427
MODULE_DIR "${CMAKE_BINARY_DIR}/lib/swift/embedded"
428428
SDK "embedded"

test/embedded/fragile-reference.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2-
// RUN: %target-swift-frontend -target arm64-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
1+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2+
// RUN: %target-swift-frontend -target arm64-apple-none-macho -module-name main -parse-as-library -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
33
// REQUIRES: swift_in_compiler
44
// REQUIRES: OS=macosx || OS=linux-gnu
55
// REQUIRES: CODEGENERATOR=ARM

test/embedded/ouroboros-bug.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// code, but in the embedded Swift's runtime that's somewhat reasonable thing
44
// to do (but is to be avoided because of this).
55

6-
// RUN: %target-swift-frontend -target armv7-apple-none-macho -assert-config Debug -Osize -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
7-
// RUN: %target-swift-frontend -target arm64-apple-none-macho -assert-config Debug -Osize -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
6+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -assert-config Debug -Osize -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
7+
// RUN: %target-swift-frontend -target arm64-apple-none-macho -assert-config Debug -Osize -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
88

99
// REQUIRES: swift_in_compiler
1010
// REQUIRES: optimized_stdlib

test/embedded/stdlib-array.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -target armv7-apple-none-macho -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2-
// RUN: %target-swift-frontend -target arm64-apple-none-macho -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
1+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2+
// RUN: %target-swift-frontend -target arm64-apple-none-macho -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
33

44
// REQUIRES: swift_in_compiler
55
// REQUIRES: optimized_stdlib

test/embedded/stdlib-basic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -target armv7-apple-none-macho -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2-
// RUN: %target-swift-frontend -target arm64-apple-none-macho -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
1+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2+
// RUN: %target-swift-frontend -target arm64-apple-none-macho -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
33

44
// REQUIRES: swift_in_compiler
55
// REQUIRES: CODEGENERATOR=ARM

test/embedded/stdlib-dictionary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -target armv7-apple-none-macho -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2-
// RUN: %target-swift-frontend -target arm64-apple-none-macho -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
1+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2+
// RUN: %target-swift-frontend -target arm64-apple-none-macho -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
33

44
// REQUIRES: swift_in_compiler
55
// REQUIRES: optimized_stdlib

test/embedded/stdlib-random.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -target armv7-apple-none-macho -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2-
// RUN: %target-swift-frontend -target arm64-apple-none-macho -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
1+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2+
// RUN: %target-swift-frontend -target arm64-apple-none-macho -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
33

44
// REQUIRES: swift_in_compiler
55
// REQUIRES: optimized_stdlib

0 commit comments

Comments
 (0)