Skip to content

Commit 2299aab

Browse files
committed
consolidate common variables between CMake and SwiftPM classes
in the interest of DRY, consolidate common variables between CMake and SwiftPM classes, moving per-architecture tune flags into a new class (swift-platform-tune.bbclass)
1 parent e968883 commit 2299aab

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

classes/swift-cmake-base.bbclass

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
inherit cmake
22
inherit swift-common
33

4-
DEPENDS:append = " swift-native libgcc gcc glibc"
5-
6-
SWIFT_TARGET_NAME = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7-unknown-linux-gnueabihf', '${TARGET_ARCH}-unknown-linux-gnu', d)}"
7-
SWIFT_TARGET_ARCH = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7', '${TARGET_ARCH}', d)}"
8-
TARGET_CPU_NAME = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7-a', '${TARGET_ARCH}', d)}"
9-
10-
# Determine SWIFT_GCC_VERSION by examining bitbake's context dictionary key
11-
# RECIPE_MAINTAINER:pn-gcc-source-<version>
124
python () {
5+
# Determine SWIFT_GCC_VERSION by examining bitbake's context dictionary key
6+
# RECIPE_MAINTAINER:pn-gcc-source-<version>
137
import shlex
148

159
gcc_src_maint_pkg = [x for x in d if x.startswith("RECIPE_MAINTAINER:pn-gcc-source-")][0]
@@ -74,8 +68,11 @@ SWIFTC_BIN = "${STAGING_DIR_NATIVE}/usr/bin/swiftc"
7468

7569
EXTRA_OECMAKE:append = " -DCMAKE_Swift_COMPILER=${SWIFTC_BIN}"
7670
EXTRA_OECMAKE:append = " -DCMAKE_SWIFT_COMPILER=${SWIFTC_BIN}"
77-
78-
BUILD_MODE = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}"
71+
EXTRA_OECMAKE:append = ' -DCMAKE_Swift_FLAGS="${SWIFT_FLAGS}"'
72+
EXTRA_OECMAKE:append = " -DSWIFT_USE_LINKER=lld"
73+
EXTRA_OECMAKE:append = " -DLLVM_USE_LINKER=lld"
74+
EXTRA_OECMAKE:append = " -DLLVM_DIR=${HOST_LLVM_PATH}/cmake/llvm"
75+
EXTRA_OECMAKE:append = " -DLLVM_BUILD_LIBRARY_DIR=${HOST_LLVM_PATH}"
7976

8077
# Additional parameters to pass to swiftc
8178
EXTRA_SWIFTC_FLAGS ??= ""
@@ -99,11 +96,3 @@ SWIFT_FLAGS = "-target ${SWIFT_TARGET_NAME} -use-ld=lld \
9996
"
10097

10198
HOST_LLVM_PATH = "${STAGING_DIR_NATIVE}/usr/lib"
102-
103-
EXTRA_OECMAKE:append = ' -DCMAKE_Swift_FLAGS="${SWIFT_FLAGS}"'
104-
EXTRA_OECMAKE:append = " -DSWIFT_USE_LINKER=lld"
105-
EXTRA_OECMAKE:append = " -DLLVM_USE_LINKER=lld"
106-
EXTRA_OECMAKE:append = " -DLLVM_DIR=${HOST_LLVM_PATH}/cmake/llvm"
107-
EXTRA_OECMAKE:append = " -DLLVM_BUILD_LIBRARY_DIR=${HOST_LLVM_PATH}"
108-
109-
EXTRANATIVEPATH:append = " swift-tools"

classes/swift-common.bbclass

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
# avoid conflicts with meta-clang
22
TOOLCHAIN = "gcc"
33

4-
# force disable GLIBC_64BIT_TIME_FLAGS until SwiftNIO and other common packages
5-
# are updated to support 64-bit time_t on 32-bit systems. ABI incompatibility
6-
# may cause your program to crash; you have been warned.
7-
TARGET_CC_ARCH:remove:arm = "${GLIBC_64BIT_TIME_FLAGS}"
4+
DEPENDS:append = " swift-native glibc gcc libgcc"
5+
EXTRANATIVEPATH:append = " swift-tools"
86

9-
# appears to cause segfault
10-
TARGET_CC_ARCH:remove:aarch64 = "-mbranch-protection=standard"
7+
SWIFT_TARGET_NAME = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7-unknown-linux-gnueabihf', '${TARGET_ARCH}-unknown-linux-gnu', d)}"
8+
SWIFT_TARGET_ARCH = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7', '${TARGET_ARCH}', d)}"
9+
TARGET_CPU_NAME = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7-a', '${TARGET_ARCH}', d)}"
1110

12-
# workaround for building on x86_64: SSE appears to cause cyclic header
13-
# dependency when building C++ std module. This needs investigation and an
14-
# upstream fix
15-
TARGET_CC_ARCH:remove:x86-64 = "-march=core2"
16-
TARGET_CC_ARCH:remove:x86-64 = "-mtune=core2"
17-
TARGET_CC_ARCH:remove:x86-64 = "-msse3"
18-
TARGET_CC_ARCH:remove:x86-64 = "-mfpmath=sse"
11+
BUILD_MODE = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}"
12+
13+
inherit swift-target-tune

classes/swift-target-tune.bbclass

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# force disable GLIBC_64BIT_TIME_FLAGS until SwiftNIO and other common packages
2+
# are updated to support 64-bit time_t on 32-bit systems. ABI incompatibility
3+
# may cause your program to crash; you have been warned.
4+
TARGET_CC_ARCH:remove:arm = "${GLIBC_64BIT_TIME_FLAGS}"
5+
6+
# appears to cause segfault
7+
TARGET_CC_ARCH:remove:aarch64 = "-mbranch-protection=standard"
8+
9+
# workaround for building on x86_64: SSE appears to cause cyclic header
10+
# dependency when building C++ std module. This needs investigation and an
11+
# upstream fix
12+
TARGET_CC_ARCH:remove:x86-64 = "-march=core2"
13+
TARGET_CC_ARCH:remove:x86-64 = "-mtune=core2"
14+
TARGET_CC_ARCH:remove:x86-64 = "-msse3"
15+
TARGET_CC_ARCH:remove:x86-64 = "-mfpmath=sse"

classes/swift.bbclass

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ inherit swift-common
22

33
SWIFT_BUILD_TESTS ?= "${DEBUG_BUILD}"
44

5-
DEPENDS:append = " swift-native glibc gcc libgcc swift-stdlib libdispatch swift-foundation"
5+
DEPENDS:append = " swift-stdlib libdispatch swift-foundation"
66
DEPENDS:append = " ${@oe.utils.conditional('SWIFT_BUILD_TESTS', '1', ' swift-xctest swift-testing', '', d)}"
77

88
# Default build directory for SPM is "./.build"
@@ -13,15 +13,11 @@ DEPENDS:append = " ${@oe.utils.conditional('SWIFT_BUILD_TESTS', '1', ' swift-xct
1313
B ?= "${S}/.build"
1414
EXTERNALSRC_BUILD ?= "${EXTERNALSRC}/.build"
1515

16-
BUILD_MODE = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}"
1716
BUILD_DIR = "${B}/${BUILD_MODE}"
1817

1918
# Additional parameters to pass to SPM
2019
EXTRA_OESWIFT ?= ""
2120

22-
SWIFT_TARGET_NAME = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7-unknown-linux-gnueabihf', '${TARGET_ARCH}-unknown-linux-gnu', d)}"
23-
SWIFT_TARGET_ARCH = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7', '${TARGET_ARCH}', d)}"
24-
2521
do_fix_gcc_install_dir() {
2622
# symbolic links do not work, will not be found by Swift clang driver
2723
# this is necessary to make the libstdc++ location heuristic work, necessary for C++ interop
@@ -272,5 +268,3 @@ do_package_update[network] = "1"
272268
addtask do_package_update after do_configure
273269

274270
EXPORT_FUNCTIONS do_configure do_compile do_package_update
275-
276-
EXTRANATIVEPATH += "swift-tools"

0 commit comments

Comments
 (0)