From 252a3db1c958dc6266312df91ce9c35220f51411 Mon Sep 17 00:00:00 2001 From: "Lvv.me" Date: Fri, 3 Dec 2021 09:28:26 +0800 Subject: [PATCH 1/4] Support use `#include ` for SwiftPM dependencies --- modulemap/module.modulemap | 2 +- modulemap/tommath.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 modulemap/tommath.h diff --git a/modulemap/module.modulemap b/modulemap/module.modulemap index 7280be7e..e5900708 100644 --- a/modulemap/module.modulemap +++ b/modulemap/module.modulemap @@ -1,4 +1,4 @@ module libtommath [extern_c] { - header "../tommath.h" + header "tommath.h" export * } diff --git a/modulemap/tommath.h b/modulemap/tommath.h new file mode 100644 index 00000000..487da053 --- /dev/null +++ b/modulemap/tommath.h @@ -0,0 +1,9 @@ +/* +* It's necessary for targets which come from package dependencies (C libraries). +* an additional header search path argument `-I /path/to/this/directory` +* will automatically added to the include directory. +* +* This allows projects to use #include syntax which are not within the package. +*/ + +#include "../tommath.h" From 500229860d6b20dcaac01363459a0c410b8d9856 Mon Sep 17 00:00:00 2001 From: "Lvv.me" Date: Sat, 4 Dec 2021 14:43:01 +0800 Subject: [PATCH 2/4] SwiftPM module rename to TomMath --- Package.swift | 12 ++++++------ demo/tommath_tests.swift | 4 ++-- modulemap/module.modulemap | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Package.swift b/Package.swift index 54a195b7..1f1270fb 100644 --- a/Package.swift +++ b/Package.swift @@ -4,15 +4,15 @@ import PackageDescription let package = Package( - name: "tommath", + name: "TomMath", platforms: [ .macOS(.v10_10), .iOS(.v9), .tvOS(.v9) ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( - name: "libtommath", - targets: ["libtommath"]) + name: "TomMath", + targets: ["TomMath"]) ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -22,7 +22,7 @@ let package = Package( // 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. .target( - name: "libtommath", + name: "TomMath", path: ".", exclude: ["demo", "doc", "etc", "logs", "mtest"], sources: ["."], @@ -30,8 +30,8 @@ let package = Package( cSettings: [ .unsafeFlags(["-flto=thin"]) // for Dead Code Elimination ]), - .testTarget(name: "TommathTests", - dependencies: ["libtommath"], + .testTarget(name: "TomMathTests", + dependencies: ["TomMath"], path: "demo", sources: ["tommath_tests.swift"]) ], diff --git a/demo/tommath_tests.swift b/demo/tommath_tests.swift index fd254da3..8632650d 100644 --- a/demo/tommath_tests.swift +++ b/demo/tommath_tests.swift @@ -1,5 +1,5 @@ import XCTest -import libtommath +import TomMath /* ---> Basic Manipulations <--- */ @@ -14,7 +14,7 @@ func mp_get_u32(_ a: UnsafePointer) -> UInt32 { return UInt32(bitPattern: mp_get_i32(a)) } -class LibTommathTests: XCTestCase { +class TomMathTests: XCTestCase { override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. diff --git a/modulemap/module.modulemap b/modulemap/module.modulemap index e5900708..a6295d7d 100644 --- a/modulemap/module.modulemap +++ b/modulemap/module.modulemap @@ -1,4 +1,4 @@ -module libtommath [extern_c] { +module TomMath [extern_c] { header "tommath.h" export * } From 4bb49ad2dda453289b4900648055e84bc5cabe49 Mon Sep 17 00:00:00 2001 From: "Lvv.me" Date: Sat, 25 Dec 2021 11:15:38 +0800 Subject: [PATCH 3/4] Using `libtommath` as library name. --- Package.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 1f1270fb..26030c19 100644 --- a/Package.swift +++ b/Package.swift @@ -11,8 +11,8 @@ let package = Package( products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( - name: "TomMath", - targets: ["TomMath"]) + name: "libtommath", + targets: [ "libtommath" ]) ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -22,7 +22,7 @@ let package = Package( // 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. .target( - name: "TomMath", + name: "libtommath", path: ".", exclude: ["demo", "doc", "etc", "logs", "mtest"], sources: ["."], @@ -31,9 +31,9 @@ let package = Package( .unsafeFlags(["-flto=thin"]) // for Dead Code Elimination ]), .testTarget(name: "TomMathTests", - dependencies: ["TomMath"], + dependencies: [ "libtommath" ], path: "demo", - sources: ["tommath_tests.swift"]) + sources: [ "tommath_tests.swift" ]) ], cLanguageStandard: .gnu11, cxxLanguageStandard: .gnucxx14 From 2955d64c152e83d54c824431aac81fc4b3b71d4d Mon Sep 17 00:00:00 2001 From: "Lvv.me" Date: Sat, 25 Dec 2021 22:57:15 +0800 Subject: [PATCH 4/4] Using `libtommath` as module name. --- demo/tommath_tests.swift | 2 +- modulemap/module.modulemap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/tommath_tests.swift b/demo/tommath_tests.swift index 8632650d..3312787b 100644 --- a/demo/tommath_tests.swift +++ b/demo/tommath_tests.swift @@ -1,5 +1,5 @@ import XCTest -import TomMath +import libtommath /* ---> Basic Manipulations <--- */ diff --git a/modulemap/module.modulemap b/modulemap/module.modulemap index a6295d7d..e5900708 100644 --- a/modulemap/module.modulemap +++ b/modulemap/module.modulemap @@ -1,4 +1,4 @@ -module TomMath [extern_c] { +module libtommath [extern_c] { header "tommath.h" export * }