Skip to contentSkip to conversation

package/swift: add Swift runtime libraries

PATCH In review Alsey Coleman Miller 2 participants 4 messages Mar 28, 2022 – Mar 29, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/swift: add Swift runtime libraries

---
 package/Config.in                             |  11 +
 package/foundation/Config.in                  |  14 ++
 package/foundation/foundation.hash            |   1 +
 package/foundation/foundation.mk              | 102 ++++++++
 package/libdispatch/Config.in                 |  11 +
 package/libdispatch/libdispatch.hash          |   2 +
 package/libdispatch/libdispatch.mk            |  78 ++++++
 package/libswiftdispatch/Config.in            |  12 +
 .../libswiftdispatch/libswiftdispatch.hash    |   2 +
 package/libswiftdispatch/libswiftdispatch.mk  |  86 +++++++
 package/swift-crypto/Config.in                |  10 +
 .../swift-crypto-shared-lib.patch             |  13 +
 package/swift-crypto/swift-crypto.mk          |  36 +++
 package/swift-hello/Config.in                 |  10 +
 package/swift-hello/src/Package.swift         |  22 ++
 .../src/Sources/swift-hello/Hello.swift       |  31 +++
 .../swift-helloTests/swift_helloTests.swift   |  47 ++++
 package/swift-hello/swift-hello.mk            |  33 +++
 package/swift/Config.in                       |  55 +++++
 package/swift/Float16.patch                   |  13 +
 package/swift/RefCount.h.diff                 |  18 ++
 package/swift/swift-5.6-armv5.patch           | 161 ++++++++++++
 package/swift/swift.hash                      |   1 +
 package/swift/swift.mk                        | 232 ++++++++++++++++++
 24 files changed, 1001 insertions(+)
 create mode 100644 package/foundation/Config.in
 create mode 100644 package/foundation/foundation.hash
 create mode 100644 package/foundation/foundation.mk
 create mode 100644 package/libdispatch/Config.in
 create mode 100644 package/libdispatch/libdispatch.hash
 create mode 100644 package/libdispatch/libdispatch.mk
 create mode 100644 package/libswiftdispatch/Config.in
 create mode 100644 package/libswiftdispatch/libswiftdispatch.hash
 create mode 100644 package/libswiftdispatch/libswiftdispatch.mk
 create mode 100644 package/swift-crypto/Config.in
 create mode 100644 package/swift-crypto/swift-crypto-shared-lib.patch
 create mode 100644 package/swift-crypto/swift-crypto.mk
 create mode 100644 package/swift-hello/Config.in
 create mode 100644 package/swift-hello/src/Package.swift
 create mode 100644 package/swift-hello/src/Sources/swift-hello/Hello.swift
 create mode 100644 package/swift-hello/src/Tests/swift-helloTests/swift_helloTests.swift
 create mode 100644 package/swift-hello/swift-hello.mk
 create mode 100644 package/swift/Config.in
 create mode 100644 package/swift/Float16.patch
 create mode 100644 package/swift/RefCount.h.diff
 create mode 100644 package/swift/swift-5.6-armv5.patch
 create mode 100644 package/swift/swift.hash
 create mode 100644 package/swift/swift.mk
package/Config.in +11 -0
index 0d5d763180..b89a49913e 100644
@@ -1422,6 +1422,7 @@ menu "Crypto"
 	source "package/openssl/Config.in"
 	source "package/pkcs11-helper/Config.in"
 	source "package/rhash/Config.in"
+	source "package/swift-crypto/Config.in"
 	source "package/tinydtls/Config.in"
 	source "package/tpm2-pkcs11/Config.in"
 	source "package/tpm2-tss/Config.in"
@@ -1939,6 +1940,7 @@ menu "Other"
 	source "package/flann/Config.in"
 	source "package/flatbuffers/Config.in"
 	source "package/flatcc/Config.in"
+	source "package/foundation/Config.in"
 	source "package/gconf/Config.in"
 	source "package/gflags/Config.in"
 	source "package/gli/Config.in"
@@ -1968,6 +1970,7 @@ menu "Other"
 	source "package/libcrossguid/Config.in"
 	source "package/libcsv/Config.in"
 	source "package/libdaemon/Config.in"
+	source "package/libdispatch/Config.in"
 	source "package/libeastl/Config.in"
 	source "package/libee/Config.in"
 	source "package/libev/Config.in"
@@ -2001,6 +2004,7 @@ menu "Other"
 	source "package/libsigc/Config.in"
 	source "package/libsigsegv/Config.in"
 	source "package/libspatialindex/Config.in"
+	source "package/libswiftdispatch/Config.in"
 	source "package/libtalloc/Config.in"
 	source "package/libtasn1/Config.in"
 	source "package/libtommath/Config.in"
@@ -2021,6 +2025,10 @@ comment "linux-pam plugins"
 endif
 	source "package/liquid-dsp/Config.in"
 	source "package/llvm/Config.in"
+	source "package/swift/Config.in"
+	source "package/libdispatch/Config.in"
+	source "package/libswiftdispatch/Config.in"
+	source "package/foundation/Config.in"
 	source "package/lttng-libust/Config.in"
 	source "package/matio/Config.in"
 	source "package/mpc/Config.in"
@@ -2044,6 +2052,7 @@ endif
 	source "package/skalibs/Config.in"
 	source "package/sphinxbase/Config.in"
 	source "package/startup-notification/Config.in"
+	source "package/swift/Config.in"
 	source "package/tinycbor/Config.in"
 	source "package/tz/Config.in"
 	source "package/tzdata/Config.in"
@@ -2102,6 +2111,7 @@ menu "Mail"
 endmenu
 
 menu "Miscellaneous"
+	source "package/swift-hello/Config.in"
 	source "package/aespipe/Config.in"
 	source "package/bc/Config.in"
 	source "package/bitcoin/Config.in"
@@ -2125,6 +2135,7 @@ menu "Miscellaneous"
 	source "package/rtl_433/Config.in"
 	source "package/shared-mime-info/Config.in"
 	source "package/sunwait/Config.in"
+	source "package/swift-hello/Config.in"
 	source "package/taskd/Config.in"
 	source "package/wine/Config.in"
 	source "package/xmrig/Config.in"
package/foundation/Config.in new file +14 -0
new file mode 100644
index 0000000000..7a9dc8b514
@@ -0,0 +1,14 @@
+if BR2_PACKAGE_SWIFT
+
+config BR2_PACKAGE_FOUNDATION
+	bool "foundation"
+	depends on BR2_PACKAGE_SWIFT
+	select BR2_PACKAGE_LIBSWIFTDISPATCH
+	select BR2_PACKAGE_LIBCURL
+	select BR2_PACKAGE_LIBXML2
+	help
+	  The Foundation framework defines a base layer of functionality that is required for almost all applications. It provides primitive classes and introduces several paradigms that define functionality not provided by either the Objective-C runtime and language or Swift standard library and language.
+
+	  http://swift.org
+
+endif
package/foundation/foundation.hash new file +1 -0
new file mode 100644
index 0000000000..f15edb8420
@@ -0,0 +1 @@
+sha256 3fa96321729ea1e99847320bc3b5eefcbc39ba57eb8750a16700afa0173b6bb0 swift-5.6-RELEASE.tar.gz
package/foundation/foundation.mk new file +102 -0

102 lines not on this page · raw message

package/libdispatch/Config.in new file +11 -0
new file mode 100644
index 0000000000..2f7c115375
@@ -0,0 +1,11 @@
+config BR2_PACKAGE_LIBDISPATCH
+	bool "libdispatch"
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_TOOLCHAIN_USES_GLIBC
+	select BR2_PACKAGE_LIBBSD
+	
+	help
+	  Grand Central Dispatch (GCD or libdispatch) provides comprehensive support for concurrent code execution on multicore hardware.
+
+	  http://swift.org
package/libdispatch/libdispatch.hash new file +2 -0
new file mode 100644
index 0000000000..a89c48c55f
@@ -0,0 +1,2 @@
+sha256 d2bbfb5b98d129caa2c6bd7662c850bf57cb434572d09844b56641c4558906ab swift-5.6-RELEASE.tar.gz
+sha256 c83647dac6a1e36795a62626e3a9c7dab7ed4b46919a757afb5562d5ed49da73 libdispatch-5.5.3-armv5.patch
package/libdispatch/libdispatch.mk new file +78 -0

78 lines not on this page · raw message

package/libswiftdispatch/Config.in new file +12 -0
new file mode 100644
index 0000000000..c16ed3217c
@@ -0,0 +1,12 @@
+config BR2_PACKAGE_LIBSWIFTDISPATCH
+	bool "libswiftdispatch"
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_TOOLCHAIN_USES_GLIBC
+	depends on BR2_PACKAGE_LIBBSD
+	depends on BR2_PACKAGE_SWIFT
+	
+	help
+	  Swift overlay for libdispatch.
+
+	  http://swift.org
package/libswiftdispatch/libswiftdispatch.hash new file +2 -0
new file mode 100644
index 0000000000..a89c48c55f
@@ -0,0 +1,2 @@
+sha256 d2bbfb5b98d129caa2c6bd7662c850bf57cb434572d09844b56641c4558906ab swift-5.6-RELEASE.tar.gz
+sha256 c83647dac6a1e36795a62626e3a9c7dab7ed4b46919a757afb5562d5ed49da73 libdispatch-5.5.3-armv5.patch
package/libswiftdispatch/libswiftdispatch.mk new file +86 -0

86 lines not on this page · raw message

package/swift-crypto/Config.in new file +10 -0
new file mode 100644
index 0000000000..35c42fdc88
@@ -0,0 +1,10 @@
+if BR2_PACKAGE_SWIFT
+
+config BR2_PACKAGE_SWIFT_CRYPTO
+	bool "swift-crypto"
+	depends on BR2_PACKAGE_SWIFT
+	depends on BR2_PACKAGE_FOUNDATION
+	help
+	  Swift Crypto is an open-source implementation of a substantial portion of the API of Apple CryptoKit suitable for use on Linux platforms.
+	  
+endif
package/swift-crypto/swift-crypto-shared-lib.patch new file +13 -0
new file mode 100644
index 0000000000..049a1a37d5
@@ -0,0 +1,13 @@
+diff --git a/Package.swift b/Package.swift
+index 4991568..2cb150f 100644
+--- a/Package.swift
++++ b/Package.swift
+@@ -39,7 +39,7 @@ let package = Package(
+         .tvOS(.v13),
+     ],
+     products: [
+-        .library(name: "Crypto", targets: ["Crypto"]),
++        .library(name: "Crypto", type: .dynamic, targets: ["Crypto"]),
+         .library(name: "_CryptoExtras", targets: ["_CryptoExtras"]),
+         /* This target is used only for symbol mangling. It's added and removed automatically because it emits build warnings. MANGLE_START
+             .library(name: "CCryptoBoringSSL", type: .static, targets: ["CCryptoBoringSSL"]),
package/swift-crypto/swift-crypto.mk new file +36 -0
new file mode 100644
index 0000000000..c0c34f53b3
@@ -0,0 +1,36 @@
+### Swift CryptoKit library
+SWIFT_CRYPTO_VERSION = 2.0.5
+SWIFT_CRYPTO_SOURCE = $(SWIFT_CRYPTO_VERSION).tar.gz
+SWIFT_CRYPTO_SITE = https://github.com/apple/swift-crypto/archive/refs/tags/
+SWIFT_CRYPTO_LICENSE = Apache-2.0
+SWIFT_CRYPTO_LICENSE_FILES = LICENSE.txt
+SWIFT_CRYPTO_INSTALL_STAGING = YES
+SWIFT_CRYPTO_INSTALL_TARGET = YES
+SWIFT_CRYPTO_SUPPORTS_IN_SOURCE_BUILD = YES
+SWIFT_CRYPTO_DEPENDENCIES = swift foundation
+SWIFT_CRYPTO_BUILDDIR = $(SWIFT_CRYPTO_SRCDIR)/.build/$(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release)
+
+define SWIFT_CRYPTO_BUILD_CMDS
+	( \
+	cd $(SWIFT_CRYPTO_SRCDIR) && \
+	rm -rf .build && \
+	PATH=$(BR_PATH):$(SWIFT_NATIVE_PATH) \
+	$(SWIFT_NATIVE_PATH)/swift build -c $(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release) --destination $(SWIFTPM_DESTINATION_FILE) \
+	)
+endef
+
+define SWIFT_CRYPTO_INSTALL_TARGET_CMDS
+	# Copy dynamic libraries
+	cp -rf $(SWIFT_CRYPTO_BUILDDIR)/libCrypto.so $(TARGET_DIR)/usr/lib/
+endef
+
+define SWIFT_CRYPTO_INSTALL_STAGING_CMDS
+	# Copy dynamic libraries
+	cp -rf $(SWIFT_CRYPTO_BUILDDIR)/libCrypto.so $(STAGING_DIR)/usr/lib/swift/linux/
+	# Copy Swift module
+	cp -rf $(SWIFT_CRYPTO_BUILDDIR)/Crypto.swiftdoc ${STAGING_DIR}/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)/
+	cp -rf $(SWIFT_CRYPTO_BUILDDIR)/Crypto.swiftmodule ${STAGING_DIR}/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)/
+	cp -rf $(SWIFT_CRYPTO_BUILDDIR)/Crypto.swiftsourceinfo ${STAGING_DIR}/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)/
+endef
+
+$(eval $(generic-package))
package/swift-hello/Config.in new file +10 -0
new file mode 100644
index 0000000000..cbeed69667
@@ -0,0 +1,10 @@
+if BR2_PACKAGE_SWIFT
+
+config BR2_PACKAGE_SWIFT_HELLO
+	bool "swift-hello"
+	depends on BR2_PACKAGE_SWIFT
+	depends on BR2_PACKAGE_FOUNDATION
+	help
+	  Demo application for Swift.
+	  
+endif
package/swift-hello/src/Package.swift new file +22 -0
new file mode 100644
index 0000000000..d26517480c
@@ -0,0 +1,22 @@
+// swift-tools-version:5.5
+import PackageDescription
+
+let package = Package(
+    name: "swift-hello",
+    dependencies: [
+        // Dependencies declare other packages that this package depends on.
+        // .package(url: /* package url */, from: "1.0.0"),
+    ],
+    targets: [
+        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
+        // Targets can depend on other targets in this package, and on products in packages this package depends on.
+        .executableTarget(
+            name: "swift-hello",
+            dependencies: []
+        ),
+        .testTarget(
+            name: "swift-helloTests",
+            dependencies: ["swift-hello"]
+        ),
+    ]
+)
package/swift-hello/src/Sources/swift-hello/Hello.swift new file +31 -0
new file mode 100644
index 0000000000..d68c3fb1a3
@@ -0,0 +1,31 @@
+import Foundation
+#if canImport(Crypto)
+import Crypto
+#endif
+
+@main
+struct Hello {
+    static func main() async throws {
+        print("Hello, world! 👋")
+        #if canImport(Crypto)
+        print("Swift Crypto installed")
+        #endif
+        let task = Task {
+            var didCatchError = false
+            do { try await errorTest() }
+            catch CocoaError.userCancelled { didCatchError = true }
+            catch { fatalError() }
+            print("Task ran")
+        }
+        for _ in 0 ..< 10 {
+            print(UUID())
+            try await Task.sleep(1_000_000_000)
+        }
+    }
+}
+
+func errorTest() async throws {
+    print("Will throw")
+    throw CocoaError(.userCancelled)
+}
+
package/swift-hello/src/Tests/swift-helloTests/swift_helloTests.swift new file +47 -0

47 lines not on this page · raw message

package/swift-hello/swift-hello.mk new file +33 -0
new file mode 100644
index 0000000000..b3cded3f7c
@@ -0,0 +1,33 @@
+### Swift Demo
+SWIFT_HELLO_VERSION = 0.1.0
+SWIFT_HELLO_SITE = $(SWIFT_HELLO_PKGDIR)/src
+SWIFT_HELLO_SITE_METHOD = local
+SWIFT_HELLO_INSTALL_STAGING = NO
+SWIFT_HELLO_INSTALL_TARGET = YES
+SWIFT_HELLO_SUPPORTS_IN_SOURCE_BUILD = YES
+SWIFT_HELLO_DEPENDENCIES = swift foundation
+SWIFT_HELLO_EXECUTABLES = swift-hello
+SWIFT_HELLO_BUILDDIR = $(SWIFT_HELLO_SRCDIR)/.build/$(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release)
+
+define SWIFT_HELLO_BUILD_CMDS
+	( \
+	cd $(SWIFT_HELLO_SRCDIR) && \
+	rm -rf .build && \
+	PATH=$(BR_PATH):$(SWIFT_NATIVE_PATH) \
+	$(SWIFT_NATIVE_PATH)/swift build -c $(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release) --destination $(SWIFTPM_DESTINATION_FILE) \
+	)
+endef
+
+define SWIFT_HELLO_INSTALL_TARGET_CMDS
+	# Copy dynamic libraries
+	#cp $(SWIFT_HELLO_BUILDDIR)/*.so $(TARGET_DIR)/usr/lib/
+	cp $(SWIFT_HELLO_BUILDDIR)/swift-hello $(TARGET_DIR)/usr/bin/hello
+endef
+
+define SWIFT_HELLO_INSTALL_STAGING_CMDS
+	# Copy dynamic libraries
+	#cp $(SWIFT_HELLO_BUILDDIR)/*.so $(STAGING_DIR)/usr/lib/swift/linux/
+	cp $(SWIFT_HELLO_BUILDDIR)/swift-hello $(STAGING_DIR)/usr/bin/hello
+endef
+
+$(eval $(generic-package))
package/swift/Config.in new file +55 -0

55 lines not on this page · raw message

package/swift/Float16.patch new file +13 -0
new file mode 100644
index 0000000000..2768d0cd20
@@ -0,0 +1,13 @@
+diff --git a/stdlib/public/runtime/Float16Support.cpp b/stdlib/public/runtime/Float16Support.cpp
+index 817739d4cdf..b1896a4e364 100644
+--- a/stdlib/public/runtime/Float16Support.cpp
++++ b/stdlib/public/runtime/Float16Support.cpp
+@@ -29,7 +29,7 @@
+ 
+ // Android NDK <r21 do not provide `__aeabi_d2h` in the compiler runtime,
+ // provide shims in that case.
+-#if (defined(__ANDROID__) && defined(__ARM_ARCH_7A__) && defined(__ARM_EABI__)) || \
++#if ((defined(__ANDROID__) || defined(__linux__)) && defined(__arm__)) || \
+   ((defined(__i386__) || defined(__i686__) || defined(__x86_64__)) && !defined(__APPLE__))
+ 
+ #include "../SwiftShims/Visibility.h"
package/swift/RefCount.h.diff new file +18 -0
new file mode 100644
index 0000000000..332ff549dc
@@ -0,0 +1,18 @@
+diff --git a/stdlib/public/SwiftShims/RefCount.h b/stdlib/public/SwiftShims/RefCount.h
+index 5c8211f5e9f..fe54839aaae 100644
+--- a/stdlib/public/SwiftShims/RefCount.h
++++ b/stdlib/public/SwiftShims/RefCount.h
+@@ -1319,7 +1319,12 @@ class HeapObjectSideTableEntry {
+ 
+   public:
+   HeapObjectSideTableEntry(HeapObject *newObject)
+-    : object(newObject), refCounts()
++    : object(newObject), 
++#if __arm__ // https://bugs.swift.org/browse/SR-5846
++   refCounts(SideTableRefCounts::Initialized)
++#else
++   refCounts()
++#endif
+   { }
+ 
+ #pragma clang diagnostic push
package/swift/swift-5.6-armv5.patch new file +161 -0

161 lines not on this page · raw message

package/swift/swift.hash new file +1 -0
new file mode 100644
index 0000000000..3c1d012f41
@@ -0,0 +1 @@
+sha256 15e3e092ad165c35eef59cf2449e3089a0bb1906272127ba58fa31fc53512af5 swift-5.6-RELEASE.tar.gz
package/swift/swift.mk new file +232 -0

233 lines not on this page · raw message

Signature · 6 lines
2.30.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Hi Alsey,

Thank you for your contribution! I have a number of review comments below.
Please take them into account and send a new patch series. For the time being, I've marked the patch as Changes Requested in patchwork.

Firt of all, the patch should be split up in separate patches: one patch per
package you add. Make sure all of them are posted together and in the correct order. Each patch should have as subject "package/...: new package".

I have a few more comments below, but it's hard to properly review such a big
patch so I will probably have missed some things.

Quoted 3 lines · Alsey Coleman Miller
---
  package/Config.in                             |  11 +

Please add yourself to the DEVELOPERS file [1] for this package. This way,
you'll get an e-mail if the package fails in the autobuilders, or when a new version is released if the package is registered on release-monitoring.org.

[snip]

package/foundation/Config.in line 1

Quoted 7 lines
package/foundation/Config.in new file +1 -0
new file mode 100644
index 0000000000..7a9dc8b514
@@ -0,0 +1,14 @@
+if BR2_PACKAGE_SWIFT

I get that you only want swift-related packages to appear in the menus if
swift itself is selected. It would be even better, then, to sort all of them under the swift main entry. Perhaps even prefix all of them with swift-, like is done for python, perl and lua packages.

package/foundation/Config.in line 10

Quoted 9 lines
package/foundation/Config.in new file +9 -0
+
+config BR2_PACKAGE_FOUNDATION
+	bool "foundation"
+	depends on BR2_PACKAGE_SWIFT
+	select BR2_PACKAGE_LIBSWIFTDISPATCH
+	select BR2_PACKAGE_LIBCURL
+	select BR2_PACKAGE_LIBXML2
+	help
+	  The Foundation framework defines a base layer of functionality that is required for almost all applications. It provides primitive classes and introduces several paradigms that define functionality not provided by either the Objective-C runtime and language or Swift standard library and language.

Please make sure indentation is done correctly, as reported by the
utils/check-package script. In this case, the line length is way too long.

Quoted 17 lines
package/foundation/Config.in new file +4 -0
+
+	  http://swift.org
+
+endif
package/foundation/foundation.hash new file +1 -0
new file mode 100644
index 0000000000..f15edb8420
@@ -0,0 +1 @@
+sha256 3fa96321729ea1e99847320bc3b5eefcbc39ba57eb8750a16700afa0173b6bb0 swift-5.6-RELEASE.tar.gz
package/foundation/foundation.mk new file +0 -0
new file mode 100644
index 0000000000..93c7cedbdd

package/foundation/foundation.mk line 1

Quoted 1 line
package/foundation/foundation.mk new file +1 -0
@@ -0,0 +1,102 @@
+### Foundation

Missin comment header, as reported by check-package (I'm not going to repeat
all the other check-package errors).

package/foundation/foundation.mk line 4

Quoted 3 lines
package/foundation/foundation.mk new file +3 -0
+FOUNDATION_VERSION = $(SWIFT_VERSION)
+FOUNDATION_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+FOUNDATION_SITE = https://github.com/apple/swift-corelibs-foundation/archive/refs/tags

This doesn't look right - shouldn't you be using the github helper?

package/foundation/foundation.mk line 8

Quoted 4 lines
package/foundation/foundation.mk new file +4 -0
+FOUNDATION_LICENSE = Apache-2.0
+FOUNDATION_LICENSE_FILES = LICENSE
+FOUNDATION_INSTALL_STAGING = YES
+FOUNDATION_INSTALL_TARGET = YES

_INSTALL_TARGET = YES is not needed, it's done automatically.

package/foundation/foundation.mk line 14

Quoted 6 lines
package/foundation/foundation.mk new file +6 -0
+FOUNDATION_SUPPORTS_IN_SOURCE_BUILD = NO
+FOUNDATION_DEPENDENCIES = icu libxml2 libcurl swift libswiftdispatch
+
+FOUNDATION_CONF_OPTS += \
+    -DCMAKE_Swift_FLAGS=${SWIFTC_FLAGS} \
+	-DCMAKE_Swift_FLAGS_DEBUG="" \

Please consistently indent with one tab.

package/foundation/foundation.mk line 25

Quoted 11 lines
package/foundation/foundation.mk new file +11 -0
+	-DCMAKE_Swift_FLAGS_RELEASE="" \
+	-DCMAKE_Swift_FLAGS_RELWITHDEBINFO="" \
+    -DCF_DEPLOYMENT_SWIFT=ON \
+    -Ddispatch_DIR="$(LIBSWIFTDISPATCH_BUILDDIR)/cmake/modules" \
+    -DICU_I18N_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libicui18n.so \
+    -DICU_UC_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libicuuc.so \
+    -DICU_I18N_LIBRARY_DEBUG=${STAGING_DIR}/usr/lib/libicui18n.so \
+    -DICU_UC_LIBRARY_DEBUG=${STAGING_DIR}/usr/lib/libicuuc.so \
+    -DICU_INCLUDE_DIR="${STAGING_DIR}/usr/include" \
+
+ifeq ($(BR2_PACKAGE_LIBCURL),y)

Since Config.in selects libcurl, this is always true.

package/foundation/foundation.mk line 26

Quoted 1 line
package/foundation/foundation.mk new file +1 -0
+	FOUNDATION_DEPENDENCIES += libcurl

No indentation within make conditions.

Quoted 9 lines
package/foundation/foundation.mk new file +9 -0
+	FOUNDATION_CONF_OPTS += \
+    	-DCURL_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libcurl.so \
+    	-DCURL_INCLUDE_DIR="${STAGING_DIR}/usr/include" \
+
+endif
+
+ifeq ($(BR2_PACKAGE_LIBXML2),y)
+	FOUNDATION_DEPENDENCIES += libxml2
+	FOUNDATION_CONF_OPTS += \

package/foundation/foundation.mk line 45

Quoted 10 lines
package/foundation/foundation.mk new file +10 -0
+		-DLIBXML2_LIBRARY=${STAGING_DIR}/usr/lib/libxml2.so \
+    	-DLIBXML2_INCLUDE_DIR=${STAGING_DIR}/usr/include/libxml2 \
+	
+endif
+
+ifeq (FOUNDATION_SUPPORTS_IN_SOURCE_BUILD),YES)
+FOUNDATION_BUILDDIR			= $(FOUNDATION_SRCDIR)
+else
+FOUNDATION_BUILDDIR			= $(FOUNDATION_SRCDIR)/build
+endif

This stuff is done automatically by the infra.

Quoted 12 lines
package/foundation/foundation.mk new file +12 -0
+
+define FOUNDATION_CONFIGURE_CMDS
+	# Workaround Dispatch defined with cmake and module
+	rm -rf ${STAGING_DIR}/usr/lib/swift/dispatch
+	# Clean
+	rm -rf $(FOUNDATION_BUILDDIR)
+	rm -rf $(STAGING_DIR)/usr/lib/swift/CoreFoundation
+	# Configure
+	(mkdir -p $(FOUNDATION_BUILDDIR) && \
+	cd $(FOUNDATION_BUILDDIR) && \
+	rm -f CMakeCache.txt && \
+	PATH=$(BR_PATH):$(SWIFT_NATIVE_PATH) \

package/foundation/foundation.mk line 67

Quoted 10 lines
package/foundation/foundation.mk new file +10 -0
+	$(FOUNDATION_CONF_ENV) $(BR2_CMAKE) -S $(FOUNDATION_SRCDIR) -B $(FOUNDATION_BUILDDIR) -G Ninja \
+		-DCMAKE_INSTALL_PREFIX="/usr" \
+		-DBUILD_SHARED_LIBS=ON \
+		-DCMAKE_BUILD_TYPE=$(if $(BR2_ENABLE_RUNTIME_DEBUG),Debug,Release) \
+    	-DCMAKE_C_COMPILER=$(SWIFT_NATIVE_PATH)/clang \
+    	-DCMAKE_C_FLAGS="-w -fuse-ld=lld -target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR) $(SWIFT_EXTRA_FLAGS) -I$(STAGING_DIR)/usr/include -B$(STAGING_DIR)/usr/lib -B$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION)) -L$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))" \
+    	-DCMAKE_C_LINK_FLAGS="-target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR)" \
+		-DCMAKE_ASM_FLAGS="-target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR)" \
+		$(FOUNDATION_CONF_OPTS) \
+	)

I haven't looked at the details, but not using the cmake infrastructure is not
a good idea.

package/foundation/foundation.mk line 72

Quoted 5 lines
package/foundation/foundation.mk new file +5 -0
+endef
+
+define FOUNDATION_BUILD_CMDS
+	# Compile
+	(cd $(FOUNDATION_BUILDDIR) && ninja)

If the problem is that it only supports the ninja build system: please use [2]
and explain in the cover letter of your series that it depends on that.

Quoted 36 lines
package/foundation/foundation.mk new file +30 -0
+endef
+
+define FOUNDATION_INSTALL_TARGET_CMDS
+	cp $(FOUNDATION_BUILDDIR)/lib/*.so $(TARGET_DIR)/usr/lib/
+endef
+
+define FOUNDATION_INSTALL_STAGING_CMDS
+	# Copy libraries
+	cp $(FOUNDATION_BUILDDIR)/lib/*.so $(STAGING_DIR)/usr/lib/swift/linux/
+	# Copy CoreFoundation module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CoreFoundation
+	cp $(FOUNDATION_BUILDDIR)/CoreFoundation.framework/Headers/*.h ${STAGING_DIR}/usr/lib/swift/CoreFoundation/
+	touch ${STAGING_DIR}/usr/lib/swift/CoreFoundation/module.map
+	echo 'framework module CoreFoundation [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CoreFoundation/CoreFoundation.h" }' > ${STAGING_DIR}/usr/lib/swift/CoreFoundation/module.map
+	# Copy CFXMLInterface module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CFXMLInterface
+	touch ${STAGING_DIR}/usr/lib/swift/CFXMLInterface/module.map
+	echo 'framework module CFXMLInterface [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CFXMLInterface/CFXMLInterface.h" }' > ${STAGING_DIR}/usr/lib/swift/CFXMLInterface/module.map
+	# Copy CFURLSessionInterface module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface
+	touch ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/module.map
+	echo 'framework module CFURLSessionInterface [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/CFURLSessionInterface.h" }' > ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/module.map
+	# Copy Swift modules
+	cp $(FOUNDATION_BUILDDIR)/swift/*  ${STAGING_DIR}/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)/
+	# Restore Dispatch headers
+	$(LIBSWIFTDISPATCH_INSTALL_STAGING_CMDS)
+	
+endef
+
+$(eval $(generic-package))
package/libdispatch/Config.in new file +0 -0
new file mode 100644
index 0000000000..2f7c115375

package/libdispatch/Config.in line 5

Quoted 5 lines
package/libdispatch/Config.in new file +5 -0
@@ -0,0 +1,11 @@
+config BR2_PACKAGE_LIBDISPATCH
+	bool "libdispatch"
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_TOOLCHAIN_USES_GLIBC

When there are toolchain dependencies, there should also be a comment that
tells the user why the package can't be selected. Look at other packages for examples.

Since it's not clear here, you should probably explain in the commit message
why these dependencies are needed.

Quoted 22 lines
package/libdispatch/Config.in new file +6 -0
+	select BR2_PACKAGE_LIBBSD
+	
+	help
+	  Grand Central Dispatch (GCD or libdispatch) provides comprehensive support for concurrent code execution on multicore hardware.
+
+	  http://swift.org
package/libdispatch/libdispatch.hash new file +2 -0
new file mode 100644
index 0000000000..a89c48c55f
@@ -0,0 +1,2 @@
+sha256 d2bbfb5b98d129caa2c6bd7662c850bf57cb434572d09844b56641c4558906ab swift-5.6-RELEASE.tar.gz
+sha256 c83647dac6a1e36795a62626e3a9c7dab7ed4b46919a757afb5562d5ed49da73 libdispatch-5.5.3-armv5.patch
package/libdispatch/libdispatch.mk new file +2 -0
new file mode 100644
index 0000000000..a334c3052d
@@ -0,0 +1,78 @@
+### Grand Central Dispatch (C API)
+LIBDISPATCH_VERSION = $(SWIFT_VERSION)

package/libdispatch/libdispatch.mk line 12

Quoted 10 lines
package/libdispatch/libdispatch.mk new file +10 -0
+LIBDISPATCH_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+LIBDISPATCH_SITE = https://github.com/apple/swift-corelibs-libdispatch/archive/refs/tags
+LIBDISPATCH_LICENSE = Apache-2.0
+LIBDISPATCH_LICENSE_FILES = LICENSE
+LIBDISPATCH_INSTALL_STAGING = YES
+LIBDISPATCH_INSTALL_TARGET = YES
+LIBDISPATCH_SUPPORTS_IN_SOURCE_BUILD = NO
+LIBDISPATCH_DEPENDENCIES = libbsd
+LIBDISPATCH_PATCH = \
+	https://gist.githubusercontent.com/colemancda/e19ec96d8b3caa7f4a3f9ec9a82f356a/raw/a8a62d61856de09f02618d32d14ac637017cc44f/libdispatch-5.5.3-armv5.patch

Downloading a patch from your own gist isn't exactly great for allowing
reviews :-). Please instead include the patch directly in Buildroot. Since upstream is managed in git, please make this a git-formatted patch (generated with git format-patch -N) [1]. Make sure it has a summary and description just like any other commit, and also include your Signed-off-by. The latter is needed to ascertain that the patch may be distributed under the upstream project's license (which may be different from Buildroot's).

[snip]

Quoted 6 lines
package/swift-hello/Config.in new file +0 -0
new file mode 100644
index 0000000000..cbeed69667

package/swift-hello/Config.in line 8

Quoted 8 lines
package/swift-hello/Config.in new file +8 -0
@@ -0,0 +1,10 @@
+if BR2_PACKAGE_SWIFT
+
+config BR2_PACKAGE_SWIFT_HELLO
+	bool "swift-hello"
+	depends on BR2_PACKAGE_SWIFT
+	depends on BR2_PACKAGE_FOUNDATION
+	help
+	  Demo application for Swift.

If I understand correctly, this package serves no purpose other than proving
that it's possibleto biuld a swift application in Buildroot. Nobody is ever going to select it. Instead, it would be better to move it to the runtime test infrastructure (and of course actually runtime test it, which proves that the generated binaries actually work).

[snip]

Quoted 9 lines
package/swift-hello/swift-hello.mk new file +3 -0
new file mode 100644
index 0000000000..b3cded3f7c
@@ -0,0 +1,33 @@
+### Swift Demo
+SWIFT_HELLO_VERSION = 0.1.0
+SWIFT_HELLO_SITE = $(SWIFT_HELLO_PKGDIR)/src

package/swift-hello/swift-hello.mk line 13

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+SWIFT_HELLO_SITE_METHOD = local
+SWIFT_HELLO_INSTALL_STAGING = NO
+SWIFT_HELLO_INSTALL_TARGET = YES
+SWIFT_HELLO_SUPPORTS_IN_SOURCE_BUILD = YES
+SWIFT_HELLO_DEPENDENCIES = swift foundation
+SWIFT_HELLO_EXECUTABLES = swift-hello
+SWIFT_HELLO_BUILDDIR = $(SWIFT_HELLO_SRCDIR)/.build/$(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release)
+
+define SWIFT_HELLO_BUILD_CMDS
+	( \

These parenthesis are actually not needed. They are still used in a lot of
places in Buildroot, but that's legacy stuff.

package/swift-hello/swift-hello.mk line 23

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+	cd $(SWIFT_HELLO_SRCDIR) && \
+	rm -rf .build && \
+	PATH=$(BR_PATH):$(SWIFT_NATIVE_PATH) \
+	$(SWIFT_NATIVE_PATH)/swift build -c $(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release) --destination $(SWIFTPM_DESTINATION_FILE) \
+	)
+endef
+
+define SWIFT_HELLO_INSTALL_TARGET_CMDS
+	# Copy dynamic libraries
+	#cp $(SWIFT_HELLO_BUILDDIR)/*.so $(TARGET_DIR)/usr/lib/

Please don't keep commented-out lines.

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+	cp $(SWIFT_HELLO_BUILDDIR)/swift-hello $(TARGET_DIR)/usr/bin/hello
+endef
+
+define SWIFT_HELLO_INSTALL_STAGING_CMDS
+	# Copy dynamic libraries
+	#cp $(SWIFT_HELLO_BUILDDIR)/*.so $(STAGING_DIR)/usr/lib/swift/linux/
+	cp $(SWIFT_HELLO_BUILDDIR)/swift-hello $(STAGING_DIR)/usr/bin/hello
+endef
+
+$(eval $(generic-package))

[snip]

Quoted 12 lines
package/swift-hello/swift-hello.mk new file +12 -0
+config BR2_PACKAGE_SWIFT
+	bool "swift"
+	depends on BR2_PACKAGE_SWIFT_ARCH_SUPPORTS
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_TOOLCHAIN_USES_GLIBC
+	select BR2_PACKAGE_ICU
+	select BR2_PACKAGE_LIBDISPATCH
+	help
+	  Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns.
+
+	  http://swift.org

package/swift-hello/swift-hello.mk

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+
+if BR2_PACKAGE_SWIFT || BR2_PACKAGE_LIBDISPATCH
+
+config BR2_PACKAGE_SWIFT_NATIVE_TOOLS
+	string "Path to host Swift toolchain"
+	default "/usr/bin"
+
+config BR2_PACKAGE_SWIFT_LLVM_DIR
+	string "Path to host LLVM library path"
+	default "/usr/lib/llvm-12"

I guess swift is built on top of LLVM. Is it possible to use package/llvm, or
is it a patched version?

Quoted 7 lines
package/swift-hello/swift-hello.mk new file +7 -0
+
+endif
+
+comment "swift needs a toolchain w/ Glibc, ICU, wchar, threads, C++, dynamic library"
+	depends on BR2_PACKAGE_SWIFT_ARCH_SUPPORTS
+	depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_TOOLCHAIN_HAS_THREADS || !BR2_INSTALL_LIBSTDCPP \
+		|| BR2_STATIC_LIBS || !BR2_USE_WCHAR

[snip]

Quoted 16 lines
package/swift/swift.mk new file +10 -0
new file mode 100644
index 0000000000..da10aae8fd
@@ -0,0 +1,232 @@
+### Apple's Swift Programming Language
+SWIFT_VERSION = 5.6
+SWIFT_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+SWIFT_SITE = https://github.com/apple/swift/archive/refs/tags
+SWIFT_LICENSE = Apache-2.0
+SWIFT_LICENSE_FILES = LICENSE.txt
+SWIFT_TARGET_ARCH = $(call qstrip,$(BR2_PACKAGE_SWIFT_TARGET_ARCH))
+SWIFT_NATIVE_PATH = $(call qstrip,$(BR2_PACKAGE_SWIFT_NATIVE_TOOLS))
+SWIFT_LLVM_DIR = $(call qstrip,$(BR2_PACKAGE_SWIFT_LLVM_DIR))
+SWIFT_INSTALL_STAGING = YES

package/swift/swift.mk line 20

Quoted 10 lines
package/swift/swift.mk new file +10 -0
+SWIFT_INSTALL_TARGET = YES
+SWIFT_SUPPORTS_IN_SOURCE_BUILD = NO
+SWIFT_DEPENDENCIES = icu libxml2 libbsd libdispatch
+
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
+SWIFT_CONF_ENV += LIBS="-latomic"
+endif
+
+HOST_SWIFT_SUPPORT_DIR = $(HOST_DIR)/usr/share/swift
+SWIFTPM_DESTINATION_FILE = $(HOST_SWIFT_SUPPORT_DIR)/$(SWIFT_TARGET_NAME)-toolchain.json

This should have simply a SWIFT_ prefix, not SWIFTPM.

[snip]

package/swift/swift.mk line 182

Quoted 9 lines
package/swift/swift.mk new file +9 -0
+define SWIFT_INSTALL_STAGING_CMDS
+	mkdir -p $(HOST_SWIFT_SUPPORT_DIR)
+	# Copy runtime libraries and swift interfaces
+	cp -rf $(SWIFT_BUILDDIR)/lib/swift ${STAGING_DIR}/usr/lib/
+	# Generate SwiftPM cross compilation toolchain file
+	rm -f $(SWIFTPM_DESTINATION_FILE)
+	touch $(SWIFTPM_DESTINATION_FILE)
+	echo '{' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "version":1,' >> $(SWIFTPM_DESTINATION_FILE)

We generally prefer to have a template file (called swift-toolchain.json.in)
in the package directory, and use sed to replace @XXXX@ entries. See e.g. how it's done for cmake's toolchainfile.

Quoted 41 lines
package/swift/swift.mk new file +41 -0
+	echo '   "sdk":"$(STAGING_DIR)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "toolchain-bin-dir":"$(SWIFT_NATIVE_PATH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "target":"$(SWIFT_TARGET_NAME)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "dynamic-library-extension":"so",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "extra-cc-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-fPIC"' >> $(SWIFTPM_DESTINATION_FILE)
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "armv5" ]; then\
+		echo '      "-march=armv5te",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	echo '   ],' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "extra-swiftc-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-target", "$(SWIFT_TARGET_NAME)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-use-ld=lld",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-tools-directory", "$(SWIFT_NATIVE_PATH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift/linux",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib/swift/linux",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "--build-id=sha1",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-I$(STAGING_DIR)/usr/include",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-I$(STAGING_DIR)/usr/lib/swift",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-resource-dir", "$(STAGING_DIR)/usr/lib/swift",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-B$(STAGING_DIR)/usr/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-B$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-latomic",' >> $(SWIFTPM_DESTINATION_FILE);\
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "powerpc" ]; then\
+		echo '      "-Xcc", "-mcpu=7400",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "armv5" ]; then\
+		echo '      "-Xcc", "-march=armv5te",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	echo '      "-sdk", "$(STAGING_DIR)"' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   ],' >> $(SWIFTPM_DESTINATION_FILE)

package/swift/swift.mk line 232

Quoted 10 lines
package/swift/swift.mk new file +9 -0
+	echo '   "extra-cpp-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-lstdc++"' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   ]' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '}' >> $(SWIFTPM_DESTINATION_FILE)
+
+endef
+
+$(eval $(generic-package))
+$(eval $(host-generic-package))
\ No newline at end of file

Please make sure there's a newline at the end of the file.

Regards,
Arnout

[1] https://buildroot.org/downloads/manual/manual.html#DEVELOPERS
[2] https://patchwork.ozlabs.org/project/buildroot/list/?series=282194
[3] https://buildroot.org/manual.html#_format_and_licensing_of_the_package_patches
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw

I have submitted new patches for only libdispatch and minimal changes to cmake to support building Apple’s (and Clang based) projects.

Quoted 435 lines · Arnout Vandecappelle

Hi Alsey,

Thank you for your contribution! I have a number of review comments below. Please take them into account and send a new patch series. For the time being, I've marked the patch as Changes Requested in patchwork.

Firt of all, the patch should be split up in separate patches: one patch per package you add. Make sure all of them are posted together and in the correct order. Each patch should have as subject "package/...: new package".

I have a few more comments below, but it's hard to properly review such a big patch so I will probably have missed some things.

Quoted 3 lines · Alsey Coleman Miller
---
 package/Config.in                             |  11 +

Please add yourself to the DEVELOPERS file [1] for this package. This way, you'll get an e-mail if the package fails in the autobuilders, or when a new version is released if the package is registered on release-monitoring.org.

[snip]

package/foundation/Config.in line 1

Quoted 7 lines
package/foundation/Config.in new file +1 -0
new file mode 100644
index 0000000000..7a9dc8b514
@@ -0,0 +1,14 @@
+if BR2_PACKAGE_SWIFT

I get that you only want swift-related packages to appear in the menus if swift itself is selected. It would be even better, then, to sort all of them under the swift main entry. Perhaps even prefix all of them with swift-, like is done for python, perl and lua packages.

package/foundation/Config.in line 10

Quoted 9 lines
package/foundation/Config.in new file +9 -0
+
+config BR2_PACKAGE_FOUNDATION
+	bool "foundation"
+	depends on BR2_PACKAGE_SWIFT
+	select BR2_PACKAGE_LIBSWIFTDISPATCH
+	select BR2_PACKAGE_LIBCURL
+	select BR2_PACKAGE_LIBXML2
+	help
+	  The Foundation framework defines a base layer of functionality that is required for almost all applications. It provides primitive classes and introduces several paradigms that define functionality not provided by either the Objective-C runtime and language or Swift standard library and language.

Please make sure indentation is done correctly, as reported by the utils/check-package script. In this case, the line length is way too long.

Quoted 17 lines
package/foundation/Config.in new file +4 -0
+
+	  http://swift.org
+
+endif
package/foundation/foundation.hash new file +1 -0
new file mode 100644
index 0000000000..f15edb8420
@@ -0,0 +1 @@
+sha256 3fa96321729ea1e99847320bc3b5eefcbc39ba57eb8750a16700afa0173b6bb0 swift-5.6-RELEASE.tar.gz
package/foundation/foundation.mk new file +0 -0
new file mode 100644
index 0000000000..93c7cedbdd

package/foundation/foundation.mk line 1

Quoted 1 line
package/foundation/foundation.mk new file +1 -0
@@ -0,0 +1,102 @@
+### Foundation

Missin comment header, as reported by check-package (I'm not going to repeat all the other check-package errors).

package/foundation/foundation.mk line 4

Quoted 3 lines
package/foundation/foundation.mk new file +3 -0
+FOUNDATION_VERSION = $(SWIFT_VERSION)
+FOUNDATION_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+FOUNDATION_SITE = https://github.com/apple/swift-corelibs-foundation/archive/refs/tags

This doesn't look right - shouldn't you be using the github helper?

package/foundation/foundation.mk line 8

Quoted 4 lines
package/foundation/foundation.mk new file +4 -0
+FOUNDATION_LICENSE = Apache-2.0
+FOUNDATION_LICENSE_FILES = LICENSE
+FOUNDATION_INSTALL_STAGING = YES
+FOUNDATION_INSTALL_TARGET = YES

_INSTALL_TARGET = YES is not needed, it's done automatically.

package/foundation/foundation.mk line 14

Quoted 6 lines
package/foundation/foundation.mk new file +6 -0
+FOUNDATION_SUPPORTS_IN_SOURCE_BUILD = NO
+FOUNDATION_DEPENDENCIES = icu libxml2 libcurl swift libswiftdispatch
+
+FOUNDATION_CONF_OPTS += \
+    -DCMAKE_Swift_FLAGS=${SWIFTC_FLAGS} \
+	-DCMAKE_Swift_FLAGS_DEBUG="" \

Please consistently indent with one tab.

package/foundation/foundation.mk line 25

Quoted 11 lines
package/foundation/foundation.mk new file +11 -0
+	-DCMAKE_Swift_FLAGS_RELEASE="" \
+	-DCMAKE_Swift_FLAGS_RELWITHDEBINFO="" \
+    -DCF_DEPLOYMENT_SWIFT=ON \
+    -Ddispatch_DIR="$(LIBSWIFTDISPATCH_BUILDDIR)/cmake/modules" \
+    -DICU_I18N_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libicui18n.so \
+    -DICU_UC_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libicuuc.so \
+    -DICU_I18N_LIBRARY_DEBUG=${STAGING_DIR}/usr/lib/libicui18n.so \
+    -DICU_UC_LIBRARY_DEBUG=${STAGING_DIR}/usr/lib/libicuuc.so \
+    -DICU_INCLUDE_DIR="${STAGING_DIR}/usr/include" \
+
+ifeq ($(BR2_PACKAGE_LIBCURL),y)

Since Config.in selects libcurl, this is always true.

package/foundation/foundation.mk line 26

Quoted 1 line
package/foundation/foundation.mk new file +1 -0
+	FOUNDATION_DEPENDENCIES += libcurl

No indentation within make conditions.

Quoted 9 lines
package/foundation/foundation.mk new file +9 -0
+	FOUNDATION_CONF_OPTS += \
+    	-DCURL_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libcurl.so \
+    	-DCURL_INCLUDE_DIR="${STAGING_DIR}/usr/include" \
+
+endif
+
+ifeq ($(BR2_PACKAGE_LIBXML2),y)
+	FOUNDATION_DEPENDENCIES += libxml2
+	FOUNDATION_CONF_OPTS += \

package/foundation/foundation.mk line 45

Quoted 10 lines
package/foundation/foundation.mk new file +10 -0
+		-DLIBXML2_LIBRARY=${STAGING_DIR}/usr/lib/libxml2.so \
+    	-DLIBXML2_INCLUDE_DIR=${STAGING_DIR}/usr/include/libxml2 \
+	
+endif
+
+ifeq (FOUNDATION_SUPPORTS_IN_SOURCE_BUILD),YES)
+FOUNDATION_BUILDDIR			= $(FOUNDATION_SRCDIR)
+else
+FOUNDATION_BUILDDIR			= $(FOUNDATION_SRCDIR)/build
+endif

This stuff is done automatically by the infra.

Quoted 12 lines
package/foundation/foundation.mk new file +12 -0
+
+define FOUNDATION_CONFIGURE_CMDS
+	# Workaround Dispatch defined with cmake and module
+	rm -rf ${STAGING_DIR}/usr/lib/swift/dispatch
+	# Clean
+	rm -rf $(FOUNDATION_BUILDDIR)
+	rm -rf $(STAGING_DIR)/usr/lib/swift/CoreFoundation
+	# Configure
+	(mkdir -p $(FOUNDATION_BUILDDIR) && \
+	cd $(FOUNDATION_BUILDDIR) && \
+	rm -f CMakeCache.txt && \
+	PATH=$(BR_PATH):$(SWIFT_NATIVE_PATH) \

package/foundation/foundation.mk line 67

Quoted 10 lines
package/foundation/foundation.mk new file +10 -0
+	$(FOUNDATION_CONF_ENV) $(BR2_CMAKE) -S $(FOUNDATION_SRCDIR) -B $(FOUNDATION_BUILDDIR) -G Ninja \
+		-DCMAKE_INSTALL_PREFIX="/usr" \
+		-DBUILD_SHARED_LIBS=ON \
+		-DCMAKE_BUILD_TYPE=$(if $(BR2_ENABLE_RUNTIME_DEBUG),Debug,Release) \
+    	-DCMAKE_C_COMPILER=$(SWIFT_NATIVE_PATH)/clang \
+    	-DCMAKE_C_FLAGS="-w -fuse-ld=lld -target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR) $(SWIFT_EXTRA_FLAGS) -I$(STAGING_DIR)/usr/include -B$(STAGING_DIR)/usr/lib -B$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION)) -L$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))" \
+    	-DCMAKE_C_LINK_FLAGS="-target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR)" \
+		-DCMAKE_ASM_FLAGS="-target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR)" \
+		$(FOUNDATION_CONF_OPTS) \
+	)

I haven't looked at the details, but not using the cmake infrastructure is not a good idea.

package/foundation/foundation.mk line 72

Quoted 5 lines
package/foundation/foundation.mk new file +5 -0
+endef
+
+define FOUNDATION_BUILD_CMDS
+	# Compile
+	(cd $(FOUNDATION_BUILDDIR) && ninja)

If the problem is that it only supports the ninja build system: please use [2] and explain in the cover letter of your series that it depends on that.

Quoted 36 lines
package/foundation/foundation.mk new file +30 -0
+endef
+
+define FOUNDATION_INSTALL_TARGET_CMDS
+	cp $(FOUNDATION_BUILDDIR)/lib/*.so $(TARGET_DIR)/usr/lib/
+endef
+
+define FOUNDATION_INSTALL_STAGING_CMDS
+	# Copy libraries
+	cp $(FOUNDATION_BUILDDIR)/lib/*.so $(STAGING_DIR)/usr/lib/swift/linux/
+	# Copy CoreFoundation module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CoreFoundation
+	cp $(FOUNDATION_BUILDDIR)/CoreFoundation.framework/Headers/*.h ${STAGING_DIR}/usr/lib/swift/CoreFoundation/
+	touch ${STAGING_DIR}/usr/lib/swift/CoreFoundation/module.map
+	echo 'framework module CoreFoundation [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CoreFoundation/CoreFoundation.h" }' > ${STAGING_DIR}/usr/lib/swift/CoreFoundation/module.map
+	# Copy CFXMLInterface module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CFXMLInterface
+	touch ${STAGING_DIR}/usr/lib/swift/CFXMLInterface/module.map
+	echo 'framework module CFXMLInterface [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CFXMLInterface/CFXMLInterface.h" }' > ${STAGING_DIR}/usr/lib/swift/CFXMLInterface/module.map
+	# Copy CFURLSessionInterface module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface
+	touch ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/module.map
+	echo 'framework module CFURLSessionInterface [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/CFURLSessionInterface.h" }' > ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/module.map
+	# Copy Swift modules
+	cp $(FOUNDATION_BUILDDIR)/swift/*  ${STAGING_DIR}/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)/
+	# Restore Dispatch headers
+	$(LIBSWIFTDISPATCH_INSTALL_STAGING_CMDS)
+	
+endef
+
+$(eval $(generic-package))
package/libdispatch/Config.in new file +0 -0
new file mode 100644
index 0000000000..2f7c115375

package/libdispatch/Config.in line 5

Quoted 5 lines
package/libdispatch/Config.in new file +5 -0
@@ -0,0 +1,11 @@
+config BR2_PACKAGE_LIBDISPATCH
+	bool "libdispatch"
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_TOOLCHAIN_USES_GLIBC

When there are toolchain dependencies, there should also be a comment that tells the user why the package can't be selected. Look at other packages for examples.

Since it's not clear here, you should probably explain in the commit message why these dependencies are needed.

Quoted 22 lines
package/libdispatch/Config.in new file +6 -0
+	select BR2_PACKAGE_LIBBSD
+	
+	help
+	  Grand Central Dispatch (GCD or libdispatch) provides comprehensive support for concurrent code execution on multicore hardware.
+
+	  http://swift.org
package/libdispatch/libdispatch.hash new file +2 -0
new file mode 100644
index 0000000000..a89c48c55f
@@ -0,0 +1,2 @@
+sha256 d2bbfb5b98d129caa2c6bd7662c850bf57cb434572d09844b56641c4558906ab swift-5.6-RELEASE.tar.gz
+sha256 c83647dac6a1e36795a62626e3a9c7dab7ed4b46919a757afb5562d5ed49da73 libdispatch-5.5.3-armv5.patch
package/libdispatch/libdispatch.mk new file +2 -0
new file mode 100644
index 0000000000..a334c3052d
@@ -0,0 +1,78 @@
+### Grand Central Dispatch (C API)
+LIBDISPATCH_VERSION = $(SWIFT_VERSION)

package/libdispatch/libdispatch.mk line 12

Quoted 10 lines
package/libdispatch/libdispatch.mk new file +10 -0
+LIBDISPATCH_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+LIBDISPATCH_SITE = https://github.com/apple/swift-corelibs-libdispatch/archive/refs/tags
+LIBDISPATCH_LICENSE = Apache-2.0
+LIBDISPATCH_LICENSE_FILES = LICENSE
+LIBDISPATCH_INSTALL_STAGING = YES
+LIBDISPATCH_INSTALL_TARGET = YES
+LIBDISPATCH_SUPPORTS_IN_SOURCE_BUILD = NO
+LIBDISPATCH_DEPENDENCIES = libbsd
+LIBDISPATCH_PATCH = \
+	https://gist.githubusercontent.com/colemancda/e19ec96d8b3caa7f4a3f9ec9a82f356a/raw/a8a62d61856de09f02618d32d14ac637017cc44f/libdispatch-5.5.3-armv5.patch

Downloading a patch from your own gist isn't exactly great for allowing reviews :-). Please instead include the patch directly in Buildroot. Since upstream is managed in git, please make this a git-formatted patch (generated with git format-patch -N) [1]. Make sure it has a summary and description just like any other commit, and also include your Signed-off-by. The latter is needed to ascertain that the patch may be distributed under the upstream project's license (which may be different from Buildroot's).

[snip]

Quoted 6 lines
package/swift-hello/Config.in new file +0 -0
new file mode 100644
index 0000000000..cbeed69667

package/swift-hello/Config.in line 8

Quoted 8 lines
package/swift-hello/Config.in new file +8 -0
@@ -0,0 +1,10 @@
+if BR2_PACKAGE_SWIFT
+
+config BR2_PACKAGE_SWIFT_HELLO
+	bool "swift-hello"
+	depends on BR2_PACKAGE_SWIFT
+	depends on BR2_PACKAGE_FOUNDATION
+	help
+	  Demo application for Swift.

If I understand correctly, this package serves no purpose other than proving that it's possibleto biuld a swift application in Buildroot. Nobody is ever going to select it. Instead, it would be better to move it to the runtime test infrastructure (and of course actually runtime test it, which proves that the generated binaries actually work).

[snip]

Quoted 9 lines
package/swift-hello/swift-hello.mk new file +3 -0
new file mode 100644
index 0000000000..b3cded3f7c
@@ -0,0 +1,33 @@
+### Swift Demo
+SWIFT_HELLO_VERSION = 0.1.0
+SWIFT_HELLO_SITE = $(SWIFT_HELLO_PKGDIR)/src

package/swift-hello/swift-hello.mk line 13

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+SWIFT_HELLO_SITE_METHOD = local
+SWIFT_HELLO_INSTALL_STAGING = NO
+SWIFT_HELLO_INSTALL_TARGET = YES
+SWIFT_HELLO_SUPPORTS_IN_SOURCE_BUILD = YES
+SWIFT_HELLO_DEPENDENCIES = swift foundation
+SWIFT_HELLO_EXECUTABLES = swift-hello
+SWIFT_HELLO_BUILDDIR = $(SWIFT_HELLO_SRCDIR)/.build/$(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release)
+
+define SWIFT_HELLO_BUILD_CMDS
+	( \

These parenthesis are actually not needed. They are still used in a lot of places in Buildroot, but that's legacy stuff.

package/swift-hello/swift-hello.mk line 23

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+	cd $(SWIFT_HELLO_SRCDIR) && \
+	rm -rf .build && \
+	PATH=$(BR_PATH):$(SWIFT_NATIVE_PATH) \
+	$(SWIFT_NATIVE_PATH)/swift build -c $(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release) --destination $(SWIFTPM_DESTINATION_FILE) \
+	)
+endef
+
+define SWIFT_HELLO_INSTALL_TARGET_CMDS
+	# Copy dynamic libraries
+	#cp $(SWIFT_HELLO_BUILDDIR)/*.so $(TARGET_DIR)/usr/lib/

Please don't keep commented-out lines.

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+	cp $(SWIFT_HELLO_BUILDDIR)/swift-hello $(TARGET_DIR)/usr/bin/hello
+endef
+
+define SWIFT_HELLO_INSTALL_STAGING_CMDS
+	# Copy dynamic libraries
+	#cp $(SWIFT_HELLO_BUILDDIR)/*.so $(STAGING_DIR)/usr/lib/swift/linux/
+	cp $(SWIFT_HELLO_BUILDDIR)/swift-hello $(STAGING_DIR)/usr/bin/hello
+endef
+
+$(eval $(generic-package))

[snip]

Quoted 12 lines
package/swift-hello/swift-hello.mk new file +12 -0
+config BR2_PACKAGE_SWIFT
+	bool "swift"
+	depends on BR2_PACKAGE_SWIFT_ARCH_SUPPORTS
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_TOOLCHAIN_USES_GLIBC
+	select BR2_PACKAGE_ICU
+	select BR2_PACKAGE_LIBDISPATCH
+	help
+	  Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns.
+
+	  http://swift.org

package/swift-hello/swift-hello.mk

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+
+if BR2_PACKAGE_SWIFT || BR2_PACKAGE_LIBDISPATCH
+
+config BR2_PACKAGE_SWIFT_NATIVE_TOOLS
+	string "Path to host Swift toolchain"
+	default "/usr/bin"
+
+config BR2_PACKAGE_SWIFT_LLVM_DIR
+	string "Path to host LLVM library path"
+	default "/usr/lib/llvm-12"

I guess swift is built on top of LLVM. Is it possible to use package/llvm, or is it a patched version?

Quoted 7 lines
package/swift-hello/swift-hello.mk new file +7 -0
+
+endif
+
+comment "swift needs a toolchain w/ Glibc, ICU, wchar, threads, C++, dynamic library"
+	depends on BR2_PACKAGE_SWIFT_ARCH_SUPPORTS
+	depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_TOOLCHAIN_HAS_THREADS || !BR2_INSTALL_LIBSTDCPP \
+		|| BR2_STATIC_LIBS || !BR2_USE_WCHAR

[snip]

Quoted 16 lines
package/swift/swift.mk new file +10 -0
new file mode 100644
index 0000000000..da10aae8fd
@@ -0,0 +1,232 @@
+### Apple's Swift Programming Language
+SWIFT_VERSION = 5.6
+SWIFT_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+SWIFT_SITE = https://github.com/apple/swift/archive/refs/tags
+SWIFT_LICENSE = Apache-2.0
+SWIFT_LICENSE_FILES = LICENSE.txt
+SWIFT_TARGET_ARCH = $(call qstrip,$(BR2_PACKAGE_SWIFT_TARGET_ARCH))
+SWIFT_NATIVE_PATH = $(call qstrip,$(BR2_PACKAGE_SWIFT_NATIVE_TOOLS))
+SWIFT_LLVM_DIR = $(call qstrip,$(BR2_PACKAGE_SWIFT_LLVM_DIR))
+SWIFT_INSTALL_STAGING = YES

package/swift/swift.mk line 20

Quoted 10 lines
package/swift/swift.mk new file +10 -0
+SWIFT_INSTALL_TARGET = YES
+SWIFT_SUPPORTS_IN_SOURCE_BUILD = NO
+SWIFT_DEPENDENCIES = icu libxml2 libbsd libdispatch
+
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
+SWIFT_CONF_ENV += LIBS="-latomic"
+endif
+
+HOST_SWIFT_SUPPORT_DIR = $(HOST_DIR)/usr/share/swift
+SWIFTPM_DESTINATION_FILE = $(HOST_SWIFT_SUPPORT_DIR)/$(SWIFT_TARGET_NAME)-toolchain.json

This should have simply a SWIFT_ prefix, not SWIFTPM.

[snip]

package/swift/swift.mk line 182

Quoted 9 lines
package/swift/swift.mk new file +9 -0
+define SWIFT_INSTALL_STAGING_CMDS
+	mkdir -p $(HOST_SWIFT_SUPPORT_DIR)
+	# Copy runtime libraries and swift interfaces
+	cp -rf $(SWIFT_BUILDDIR)/lib/swift ${STAGING_DIR}/usr/lib/
+	# Generate SwiftPM cross compilation toolchain file
+	rm -f $(SWIFTPM_DESTINATION_FILE)
+	touch $(SWIFTPM_DESTINATION_FILE)
+	echo '{' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "version":1,' >> $(SWIFTPM_DESTINATION_FILE)

We generally prefer to have a template file (called swift-toolchain.json.in) in the package directory, and use sed to replace @XXXX@ entries. See e.g. how it's done for cmake's toolchainfile.

Quoted 41 lines
package/swift/swift.mk new file +41 -0
+	echo '   "sdk":"$(STAGING_DIR)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "toolchain-bin-dir":"$(SWIFT_NATIVE_PATH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "target":"$(SWIFT_TARGET_NAME)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "dynamic-library-extension":"so",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "extra-cc-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-fPIC"' >> $(SWIFTPM_DESTINATION_FILE)
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "armv5" ]; then\
+		echo '      "-march=armv5te",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	echo '   ],' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "extra-swiftc-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-target", "$(SWIFT_TARGET_NAME)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-use-ld=lld",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-tools-directory", "$(SWIFT_NATIVE_PATH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift/linux",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib/swift/linux",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "--build-id=sha1",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-I$(STAGING_DIR)/usr/include",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-I$(STAGING_DIR)/usr/lib/swift",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-resource-dir", "$(STAGING_DIR)/usr/lib/swift",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-B$(STAGING_DIR)/usr/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-B$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-latomic",' >> $(SWIFTPM_DESTINATION_FILE);\
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "powerpc" ]; then\
+		echo '      "-Xcc", "-mcpu=7400",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "armv5" ]; then\
+		echo '      "-Xcc", "-march=armv5te",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	echo '      "-sdk", "$(STAGING_DIR)"' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   ],' >> $(SWIFTPM_DESTINATION_FILE)

package/swift/swift.mk line 232

Quoted 10 lines
package/swift/swift.mk new file +9 -0
+	echo '   "extra-cpp-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-lstdc++"' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   ]' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '}' >> $(SWIFTPM_DESTINATION_FILE)
+
+endef
+
+$(eval $(generic-package))
+$(eval $(host-generic-package))
\ No newline at end of file

Please make sure there's a newline at the end of the file.

Quoted 6 lines

Regards,
Arnout

[1] https://buildroot.org/downloads/manual/manual.html#DEVELOPERS
[2] https://patchwork.ozlabs.org/project/buildroot/list/?series=282194
[3] https://buildroot.org/manual.html#_format_and_licensing_of_the_package_patches

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw
In reply to Arnout Vandecappelle

I’ve submitted a new patch that deals only with libdispatch. Once that is merged I will submit smaller patches for each individual package.

Quoted 435 lines · Arnout Vandecappelle

Hi Alsey,

Thank you for your contribution! I have a number of review comments below. Please take them into account and send a new patch series. For the time being, I've marked the patch as Changes Requested in patchwork.

Firt of all, the patch should be split up in separate patches: one patch per package you add. Make sure all of them are posted together and in the correct order. Each patch should have as subject "package/...: new package".

I have a few more comments below, but it's hard to properly review such a big patch so I will probably have missed some things.

Quoted 3 lines · Alsey Coleman Miller
---
 package/Config.in                             |  11 +

Please add yourself to the DEVELOPERS file [1] for this package. This way, you'll get an e-mail if the package fails in the autobuilders, or when a new version is released if the package is registered on release-monitoring.org.

[snip]

package/foundation/Config.in line 1

Quoted 7 lines
package/foundation/Config.in new file +1 -0
new file mode 100644
index 0000000000..7a9dc8b514
@@ -0,0 +1,14 @@
+if BR2_PACKAGE_SWIFT

I get that you only want swift-related packages to appear in the menus if swift itself is selected. It would be even better, then, to sort all of them under the swift main entry. Perhaps even prefix all of them with swift-, like is done for python, perl and lua packages.

package/foundation/Config.in line 10

Quoted 9 lines
package/foundation/Config.in new file +9 -0
+
+config BR2_PACKAGE_FOUNDATION
+	bool "foundation"
+	depends on BR2_PACKAGE_SWIFT
+	select BR2_PACKAGE_LIBSWIFTDISPATCH
+	select BR2_PACKAGE_LIBCURL
+	select BR2_PACKAGE_LIBXML2
+	help
+	  The Foundation framework defines a base layer of functionality that is required for almost all applications. It provides primitive classes and introduces several paradigms that define functionality not provided by either the Objective-C runtime and language or Swift standard library and language.

Please make sure indentation is done correctly, as reported by the utils/check-package script. In this case, the line length is way too long.

Quoted 17 lines
package/foundation/Config.in new file +4 -0
+
+	  http://swift.org
+
+endif
package/foundation/foundation.hash new file +1 -0
new file mode 100644
index 0000000000..f15edb8420
@@ -0,0 +1 @@
+sha256 3fa96321729ea1e99847320bc3b5eefcbc39ba57eb8750a16700afa0173b6bb0 swift-5.6-RELEASE.tar.gz
package/foundation/foundation.mk new file +0 -0
new file mode 100644
index 0000000000..93c7cedbdd

package/foundation/foundation.mk line 1

Quoted 1 line
package/foundation/foundation.mk new file +1 -0
@@ -0,0 +1,102 @@
+### Foundation

Missin comment header, as reported by check-package (I'm not going to repeat all the other check-package errors).

package/foundation/foundation.mk line 4

Quoted 3 lines
package/foundation/foundation.mk new file +3 -0
+FOUNDATION_VERSION = $(SWIFT_VERSION)
+FOUNDATION_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+FOUNDATION_SITE = https://github.com/apple/swift-corelibs-foundation/archive/refs/tags

This doesn't look right - shouldn't you be using the github helper?

package/foundation/foundation.mk line 8

Quoted 4 lines
package/foundation/foundation.mk new file +4 -0
+FOUNDATION_LICENSE = Apache-2.0
+FOUNDATION_LICENSE_FILES = LICENSE
+FOUNDATION_INSTALL_STAGING = YES
+FOUNDATION_INSTALL_TARGET = YES

_INSTALL_TARGET = YES is not needed, it's done automatically.

package/foundation/foundation.mk line 14

Quoted 6 lines
package/foundation/foundation.mk new file +6 -0
+FOUNDATION_SUPPORTS_IN_SOURCE_BUILD = NO
+FOUNDATION_DEPENDENCIES = icu libxml2 libcurl swift libswiftdispatch
+
+FOUNDATION_CONF_OPTS += \
+    -DCMAKE_Swift_FLAGS=${SWIFTC_FLAGS} \
+	-DCMAKE_Swift_FLAGS_DEBUG="" \

Please consistently indent with one tab.

package/foundation/foundation.mk line 25

Quoted 11 lines
package/foundation/foundation.mk new file +11 -0
+	-DCMAKE_Swift_FLAGS_RELEASE="" \
+	-DCMAKE_Swift_FLAGS_RELWITHDEBINFO="" \
+    -DCF_DEPLOYMENT_SWIFT=ON \
+    -Ddispatch_DIR="$(LIBSWIFTDISPATCH_BUILDDIR)/cmake/modules" \
+    -DICU_I18N_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libicui18n.so \
+    -DICU_UC_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libicuuc.so \
+    -DICU_I18N_LIBRARY_DEBUG=${STAGING_DIR}/usr/lib/libicui18n.so \
+    -DICU_UC_LIBRARY_DEBUG=${STAGING_DIR}/usr/lib/libicuuc.so \
+    -DICU_INCLUDE_DIR="${STAGING_DIR}/usr/include" \
+
+ifeq ($(BR2_PACKAGE_LIBCURL),y)

Since Config.in selects libcurl, this is always true.

package/foundation/foundation.mk line 26

Quoted 1 line
package/foundation/foundation.mk new file +1 -0
+	FOUNDATION_DEPENDENCIES += libcurl

No indentation within make conditions.

Quoted 9 lines
package/foundation/foundation.mk new file +9 -0
+	FOUNDATION_CONF_OPTS += \
+    	-DCURL_LIBRARY_RELEASE=${STAGING_DIR}/usr/lib/libcurl.so \
+    	-DCURL_INCLUDE_DIR="${STAGING_DIR}/usr/include" \
+
+endif
+
+ifeq ($(BR2_PACKAGE_LIBXML2),y)
+	FOUNDATION_DEPENDENCIES += libxml2
+	FOUNDATION_CONF_OPTS += \

package/foundation/foundation.mk line 45

Quoted 10 lines
package/foundation/foundation.mk new file +10 -0
+		-DLIBXML2_LIBRARY=${STAGING_DIR}/usr/lib/libxml2.so \
+    	-DLIBXML2_INCLUDE_DIR=${STAGING_DIR}/usr/include/libxml2 \
+	
+endif
+
+ifeq (FOUNDATION_SUPPORTS_IN_SOURCE_BUILD),YES)
+FOUNDATION_BUILDDIR			= $(FOUNDATION_SRCDIR)
+else
+FOUNDATION_BUILDDIR			= $(FOUNDATION_SRCDIR)/build
+endif

This stuff is done automatically by the infra.

Quoted 12 lines
package/foundation/foundation.mk new file +12 -0
+
+define FOUNDATION_CONFIGURE_CMDS
+	# Workaround Dispatch defined with cmake and module
+	rm -rf ${STAGING_DIR}/usr/lib/swift/dispatch
+	# Clean
+	rm -rf $(FOUNDATION_BUILDDIR)
+	rm -rf $(STAGING_DIR)/usr/lib/swift/CoreFoundation
+	# Configure
+	(mkdir -p $(FOUNDATION_BUILDDIR) && \
+	cd $(FOUNDATION_BUILDDIR) && \
+	rm -f CMakeCache.txt && \
+	PATH=$(BR_PATH):$(SWIFT_NATIVE_PATH) \

package/foundation/foundation.mk line 67

Quoted 10 lines
package/foundation/foundation.mk new file +10 -0
+	$(FOUNDATION_CONF_ENV) $(BR2_CMAKE) -S $(FOUNDATION_SRCDIR) -B $(FOUNDATION_BUILDDIR) -G Ninja \
+		-DCMAKE_INSTALL_PREFIX="/usr" \
+		-DBUILD_SHARED_LIBS=ON \
+		-DCMAKE_BUILD_TYPE=$(if $(BR2_ENABLE_RUNTIME_DEBUG),Debug,Release) \
+    	-DCMAKE_C_COMPILER=$(SWIFT_NATIVE_PATH)/clang \
+    	-DCMAKE_C_FLAGS="-w -fuse-ld=lld -target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR) $(SWIFT_EXTRA_FLAGS) -I$(STAGING_DIR)/usr/include -B$(STAGING_DIR)/usr/lib -B$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION)) -L$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))" \
+    	-DCMAKE_C_LINK_FLAGS="-target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR)" \
+		-DCMAKE_ASM_FLAGS="-target $(SWIFT_TARGET_NAME) --sysroot=$(STAGING_DIR)" \
+		$(FOUNDATION_CONF_OPTS) \
+	)

I haven't looked at the details, but not using the cmake infrastructure is not a good idea.

package/foundation/foundation.mk line 72

Quoted 5 lines
package/foundation/foundation.mk new file +5 -0
+endef
+
+define FOUNDATION_BUILD_CMDS
+	# Compile
+	(cd $(FOUNDATION_BUILDDIR) && ninja)

If the problem is that it only supports the ninja build system: please use [2] and explain in the cover letter of your series that it depends on that.

Quoted 36 lines
package/foundation/foundation.mk new file +30 -0
+endef
+
+define FOUNDATION_INSTALL_TARGET_CMDS
+	cp $(FOUNDATION_BUILDDIR)/lib/*.so $(TARGET_DIR)/usr/lib/
+endef
+
+define FOUNDATION_INSTALL_STAGING_CMDS
+	# Copy libraries
+	cp $(FOUNDATION_BUILDDIR)/lib/*.so $(STAGING_DIR)/usr/lib/swift/linux/
+	# Copy CoreFoundation module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CoreFoundation
+	cp $(FOUNDATION_BUILDDIR)/CoreFoundation.framework/Headers/*.h ${STAGING_DIR}/usr/lib/swift/CoreFoundation/
+	touch ${STAGING_DIR}/usr/lib/swift/CoreFoundation/module.map
+	echo 'framework module CoreFoundation [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CoreFoundation/CoreFoundation.h" }' > ${STAGING_DIR}/usr/lib/swift/CoreFoundation/module.map
+	# Copy CFXMLInterface module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CFXMLInterface
+	touch ${STAGING_DIR}/usr/lib/swift/CFXMLInterface/module.map
+	echo 'framework module CFXMLInterface [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CFXMLInterface/CFXMLInterface.h" }' > ${STAGING_DIR}/usr/lib/swift/CFXMLInterface/module.map
+	# Copy CFURLSessionInterface module
+	mkdir -p ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface
+	touch ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/module.map
+	echo 'framework module CFURLSessionInterface [extern_c] [system] { umbrella header "${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/CFURLSessionInterface.h" }' > ${STAGING_DIR}/usr/lib/swift/CFURLSessionInterface/module.map
+	# Copy Swift modules
+	cp $(FOUNDATION_BUILDDIR)/swift/*  ${STAGING_DIR}/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)/
+	# Restore Dispatch headers
+	$(LIBSWIFTDISPATCH_INSTALL_STAGING_CMDS)
+	
+endef
+
+$(eval $(generic-package))
package/libdispatch/Config.in new file +0 -0
new file mode 100644
index 0000000000..2f7c115375

package/libdispatch/Config.in line 5

Quoted 5 lines
package/libdispatch/Config.in new file +5 -0
@@ -0,0 +1,11 @@
+config BR2_PACKAGE_LIBDISPATCH
+	bool "libdispatch"
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_TOOLCHAIN_USES_GLIBC

When there are toolchain dependencies, there should also be a comment that tells the user why the package can't be selected. Look at other packages for examples.

Since it's not clear here, you should probably explain in the commit message why these dependencies are needed.

Quoted 22 lines
package/libdispatch/Config.in new file +6 -0
+	select BR2_PACKAGE_LIBBSD
+	
+	help
+	  Grand Central Dispatch (GCD or libdispatch) provides comprehensive support for concurrent code execution on multicore hardware.
+
+	  http://swift.org
package/libdispatch/libdispatch.hash new file +2 -0
new file mode 100644
index 0000000000..a89c48c55f
@@ -0,0 +1,2 @@
+sha256 d2bbfb5b98d129caa2c6bd7662c850bf57cb434572d09844b56641c4558906ab swift-5.6-RELEASE.tar.gz
+sha256 c83647dac6a1e36795a62626e3a9c7dab7ed4b46919a757afb5562d5ed49da73 libdispatch-5.5.3-armv5.patch
package/libdispatch/libdispatch.mk new file +2 -0
new file mode 100644
index 0000000000..a334c3052d
@@ -0,0 +1,78 @@
+### Grand Central Dispatch (C API)
+LIBDISPATCH_VERSION = $(SWIFT_VERSION)

package/libdispatch/libdispatch.mk line 12

Quoted 10 lines
package/libdispatch/libdispatch.mk new file +10 -0
+LIBDISPATCH_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+LIBDISPATCH_SITE = https://github.com/apple/swift-corelibs-libdispatch/archive/refs/tags
+LIBDISPATCH_LICENSE = Apache-2.0
+LIBDISPATCH_LICENSE_FILES = LICENSE
+LIBDISPATCH_INSTALL_STAGING = YES
+LIBDISPATCH_INSTALL_TARGET = YES
+LIBDISPATCH_SUPPORTS_IN_SOURCE_BUILD = NO
+LIBDISPATCH_DEPENDENCIES = libbsd
+LIBDISPATCH_PATCH = \
+	https://gist.githubusercontent.com/colemancda/e19ec96d8b3caa7f4a3f9ec9a82f356a/raw/a8a62d61856de09f02618d32d14ac637017cc44f/libdispatch-5.5.3-armv5.patch

Downloading a patch from your own gist isn't exactly great for allowing reviews :-). Please instead include the patch directly in Buildroot. Since upstream is managed in git, please make this a git-formatted patch (generated with git format-patch -N) [1]. Make sure it has a summary and description just like any other commit, and also include your Signed-off-by. The latter is needed to ascertain that the patch may be distributed under the upstream project's license (which may be different from Buildroot's).

[snip]

Quoted 6 lines
package/swift-hello/Config.in new file +0 -0
new file mode 100644
index 0000000000..cbeed69667

package/swift-hello/Config.in line 8

Quoted 8 lines
package/swift-hello/Config.in new file +8 -0
@@ -0,0 +1,10 @@
+if BR2_PACKAGE_SWIFT
+
+config BR2_PACKAGE_SWIFT_HELLO
+	bool "swift-hello"
+	depends on BR2_PACKAGE_SWIFT
+	depends on BR2_PACKAGE_FOUNDATION
+	help
+	  Demo application for Swift.

If I understand correctly, this package serves no purpose other than proving that it's possibleto biuld a swift application in Buildroot. Nobody is ever going to select it. Instead, it would be better to move it to the runtime test infrastructure (and of course actually runtime test it, which proves that the generated binaries actually work).

[snip]

Quoted 9 lines
package/swift-hello/swift-hello.mk new file +3 -0
new file mode 100644
index 0000000000..b3cded3f7c
@@ -0,0 +1,33 @@
+### Swift Demo
+SWIFT_HELLO_VERSION = 0.1.0
+SWIFT_HELLO_SITE = $(SWIFT_HELLO_PKGDIR)/src

package/swift-hello/swift-hello.mk line 13

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+SWIFT_HELLO_SITE_METHOD = local
+SWIFT_HELLO_INSTALL_STAGING = NO
+SWIFT_HELLO_INSTALL_TARGET = YES
+SWIFT_HELLO_SUPPORTS_IN_SOURCE_BUILD = YES
+SWIFT_HELLO_DEPENDENCIES = swift foundation
+SWIFT_HELLO_EXECUTABLES = swift-hello
+SWIFT_HELLO_BUILDDIR = $(SWIFT_HELLO_SRCDIR)/.build/$(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release)
+
+define SWIFT_HELLO_BUILD_CMDS
+	( \

These parenthesis are actually not needed. They are still used in a lot of places in Buildroot, but that's legacy stuff.

package/swift-hello/swift-hello.mk line 23

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+	cd $(SWIFT_HELLO_SRCDIR) && \
+	rm -rf .build && \
+	PATH=$(BR_PATH):$(SWIFT_NATIVE_PATH) \
+	$(SWIFT_NATIVE_PATH)/swift build -c $(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release) --destination $(SWIFTPM_DESTINATION_FILE) \
+	)
+endef
+
+define SWIFT_HELLO_INSTALL_TARGET_CMDS
+	# Copy dynamic libraries
+	#cp $(SWIFT_HELLO_BUILDDIR)/*.so $(TARGET_DIR)/usr/lib/

Please don't keep commented-out lines.

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+	cp $(SWIFT_HELLO_BUILDDIR)/swift-hello $(TARGET_DIR)/usr/bin/hello
+endef
+
+define SWIFT_HELLO_INSTALL_STAGING_CMDS
+	# Copy dynamic libraries
+	#cp $(SWIFT_HELLO_BUILDDIR)/*.so $(STAGING_DIR)/usr/lib/swift/linux/
+	cp $(SWIFT_HELLO_BUILDDIR)/swift-hello $(STAGING_DIR)/usr/bin/hello
+endef
+
+$(eval $(generic-package))

[snip]

Quoted 12 lines
package/swift-hello/swift-hello.mk new file +12 -0
+config BR2_PACKAGE_SWIFT
+	bool "swift"
+	depends on BR2_PACKAGE_SWIFT_ARCH_SUPPORTS
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_TOOLCHAIN_USES_GLIBC
+	select BR2_PACKAGE_ICU
+	select BR2_PACKAGE_LIBDISPATCH
+	help
+	  Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns.
+
+	  http://swift.org

package/swift-hello/swift-hello.mk

Quoted 10 lines
package/swift-hello/swift-hello.mk new file +10 -0
+
+if BR2_PACKAGE_SWIFT || BR2_PACKAGE_LIBDISPATCH
+
+config BR2_PACKAGE_SWIFT_NATIVE_TOOLS
+	string "Path to host Swift toolchain"
+	default "/usr/bin"
+
+config BR2_PACKAGE_SWIFT_LLVM_DIR
+	string "Path to host LLVM library path"
+	default "/usr/lib/llvm-12"

I guess swift is built on top of LLVM. Is it possible to use package/llvm, or is it a patched version?

Quoted 7 lines
package/swift-hello/swift-hello.mk new file +7 -0
+
+endif
+
+comment "swift needs a toolchain w/ Glibc, ICU, wchar, threads, C++, dynamic library"
+	depends on BR2_PACKAGE_SWIFT_ARCH_SUPPORTS
+	depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_TOOLCHAIN_HAS_THREADS || !BR2_INSTALL_LIBSTDCPP \
+		|| BR2_STATIC_LIBS || !BR2_USE_WCHAR

[snip]

Quoted 16 lines
package/swift/swift.mk new file +10 -0
new file mode 100644
index 0000000000..da10aae8fd
@@ -0,0 +1,232 @@
+### Apple's Swift Programming Language
+SWIFT_VERSION = 5.6
+SWIFT_SOURCE = swift-$(SWIFT_VERSION)-RELEASE.tar.gz
+SWIFT_SITE = https://github.com/apple/swift/archive/refs/tags
+SWIFT_LICENSE = Apache-2.0
+SWIFT_LICENSE_FILES = LICENSE.txt
+SWIFT_TARGET_ARCH = $(call qstrip,$(BR2_PACKAGE_SWIFT_TARGET_ARCH))
+SWIFT_NATIVE_PATH = $(call qstrip,$(BR2_PACKAGE_SWIFT_NATIVE_TOOLS))
+SWIFT_LLVM_DIR = $(call qstrip,$(BR2_PACKAGE_SWIFT_LLVM_DIR))
+SWIFT_INSTALL_STAGING = YES

package/swift/swift.mk line 20

Quoted 10 lines
package/swift/swift.mk new file +10 -0
+SWIFT_INSTALL_TARGET = YES
+SWIFT_SUPPORTS_IN_SOURCE_BUILD = NO
+SWIFT_DEPENDENCIES = icu libxml2 libbsd libdispatch
+
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
+SWIFT_CONF_ENV += LIBS="-latomic"
+endif
+
+HOST_SWIFT_SUPPORT_DIR = $(HOST_DIR)/usr/share/swift
+SWIFTPM_DESTINATION_FILE = $(HOST_SWIFT_SUPPORT_DIR)/$(SWIFT_TARGET_NAME)-toolchain.json

This should have simply a SWIFT_ prefix, not SWIFTPM.

[snip]

package/swift/swift.mk line 182

Quoted 9 lines
package/swift/swift.mk new file +9 -0
+define SWIFT_INSTALL_STAGING_CMDS
+	mkdir -p $(HOST_SWIFT_SUPPORT_DIR)
+	# Copy runtime libraries and swift interfaces
+	cp -rf $(SWIFT_BUILDDIR)/lib/swift ${STAGING_DIR}/usr/lib/
+	# Generate SwiftPM cross compilation toolchain file
+	rm -f $(SWIFTPM_DESTINATION_FILE)
+	touch $(SWIFTPM_DESTINATION_FILE)
+	echo '{' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "version":1,' >> $(SWIFTPM_DESTINATION_FILE)

We generally prefer to have a template file (called swift-toolchain.json.in) in the package directory, and use sed to replace @XXXX@ entries. See e.g. how it's done for cmake's toolchainfile.

Quoted 41 lines
package/swift/swift.mk new file +41 -0
+	echo '   "sdk":"$(STAGING_DIR)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "toolchain-bin-dir":"$(SWIFT_NATIVE_PATH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "target":"$(SWIFT_TARGET_NAME)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "dynamic-library-extension":"so",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "extra-cc-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-fPIC"' >> $(SWIFTPM_DESTINATION_FILE)
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "armv5" ]; then\
+		echo '      "-march=armv5te",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	echo '   ],' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   "extra-swiftc-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-target", "$(SWIFT_TARGET_NAME)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-use-ld=lld",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-tools-directory", "$(SWIFT_NATIVE_PATH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift/linux",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib/swift/linux",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(STAGING_DIR)/usr/lib/swift/linux/$(SWIFT_TARGET_ARCH)",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "-L$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xlinker", "--build-id=sha1",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-I$(STAGING_DIR)/usr/include",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-I$(STAGING_DIR)/usr/lib/swift",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-resource-dir", "$(STAGING_DIR)/usr/lib/swift",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-B$(STAGING_DIR)/usr/lib",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-B$(HOST_DIR)/lib/gcc/$(GNU_TARGET_NAME)/$(call qstrip,$(BR2_GCC_VERSION))",' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-Xclang-linker", "-latomic",' >> $(SWIFTPM_DESTINATION_FILE);\
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "powerpc" ]; then\
+		echo '      "-Xcc", "-mcpu=7400",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	@if [ "$(SWIFT_TARGET_ARCH)" = "armv5" ]; then\
+		echo '      "-Xcc", "-march=armv5te",' >> $(SWIFTPM_DESTINATION_FILE);\
+    fi
+
+	echo '      "-sdk", "$(STAGING_DIR)"' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   ],' >> $(SWIFTPM_DESTINATION_FILE)

package/swift/swift.mk line 232

Quoted 10 lines
package/swift/swift.mk new file +9 -0
+	echo '   "extra-cpp-flags":[' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '      "-lstdc++"' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '   ]' >> $(SWIFTPM_DESTINATION_FILE)
+	echo '}' >> $(SWIFTPM_DESTINATION_FILE)
+
+endef
+
+$(eval $(generic-package))
+$(eval $(host-generic-package))
\ No newline at end of file

Please make sure there's a newline at the end of the file.

Quoted 6 lines

Regards,
Arnout

[1] https://buildroot.org/downloads/manual/manual.html#DEVELOPERS
[2] https://patchwork.ozlabs.org/project/buildroot/list/?series=282194
[3] https://buildroot.org/manual.html#_format_and_licensing_of_the_package_patches

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot