Add SwiftPM support #575

Open
cntrump wants to merge 6 commits from cntrump/pr_swiftpm_support into develop
cntrump commented 2021-12-02 23:07:13 -06:00 (Migrated from github.com)

Checklist

  • documentation is added or updated
  • tests are added or updated

Build library with libtommath:

swift build

Run Swift Unit tests:

swift test
### Checklist * [x] documentation is added or updated * [x] tests are added or updated Build library with libtommath: ``` swift build ``` Run Swift Unit tests: ``` swift test ```
cntrump commented 2021-12-02 23:08:21 -06:00 (Migrated from github.com)
Depend on https://github.com/libtom/libtommath/pull/518
sjaeckel (Migrated from github.com) reviewed 2021-12-03 06:18:21 -06:00
@ -0,0 +1,4 @@
module libtomcrypt [extern_c] {
header "../src/headers/tomcrypt.h"
sjaeckel (Migrated from github.com) commented 2021-12-03 06:18:21 -06:00

If libtom/libtommath#518 is really the right way to do stuff, it would also mean that this should be changed to allow using ltc in other modules or not?

If libtom/libtommath#518 is really the right way to do stuff, it would also mean that this should be changed to allow using ltc in other modules or not?
cntrump (Migrated from github.com) reviewed 2021-12-03 06:45:31 -06:00
@ -0,0 +1,4 @@
module libtomcrypt [extern_c] {
header "../src/headers/tomcrypt.h"
cntrump (Migrated from github.com) commented 2021-12-03 06:45:31 -06:00

it would also mean that this should be changed to allow using ltc in other modules or not?

Yes, should be changed. if a C package depend on libtomcrypt. because C use #include <tomcrypt.h> in source.
No, if a Swift/ObjC package depend on libtomcyrpt. swift/objc use import libtomcrypt in source.

> it would also mean that this should be changed to allow using ltc in other modules or not? Yes, should be changed. if a C package depend on libtomcrypt. because C use `#include <tomcrypt.h>` in source. No, if a Swift/ObjC package depend on libtomcyrpt. swift/objc use `import libtomcrypt` in source.
sjaeckel (Migrated from github.com) reviewed 2021-12-03 07:01:53 -06:00
@ -0,0 +1,4 @@
module libtomcrypt [extern_c] {
header "../src/headers/tomcrypt.h"
sjaeckel (Migrated from github.com) commented 2021-12-03 07:01:53 -06:00

but it would make sense to support both (C and Swift/ObjC packages depending on this) or not?

but it would make sense to support both (C and Swift/ObjC packages depending on this) or not?
cntrump (Migrated from github.com) reviewed 2021-12-03 07:09:15 -06:00
@ -0,0 +1,4 @@
module libtomcrypt [extern_c] {
header "../src/headers/tomcrypt.h"
cntrump (Migrated from github.com) commented 2021-12-03 07:09:15 -06:00

but it would make sense to support both (C and Swift/ObjC packages depending on this) or not?

Swift and ObjC can import package as module, module name defined in module.modulemap
But C is not support import module, so use #include <xx> syntax import symbols.

> but it would make sense to support both (C and Swift/ObjC packages depending on this) or not? Swift and ObjC can import package as module, module name defined in `module.modulemap` But C is not support import module, so use `#include <xx>` syntax import symbols.
cntrump (Migrated from github.com) reviewed 2021-12-03 07:29:26 -06:00
@ -0,0 +1,4 @@
module libtomcrypt [extern_c] {
header "../src/headers/tomcrypt.h"
cntrump (Migrated from github.com) commented 2021-12-03 07:29:25 -06:00

Run swift build -v

header search path in log:

-I .build/checkouts/libtommath/modulemap

Open Package.swift in Xcode and build, header search path in log:

-I ~/Library/Developer/Xcode/DerivedData/libtomcrypt-bewymzccinmagxaywggcjblpnfww/SourcePackages/checkouts/libtommath/modulemap
Run `swift build -v` header search path in log: ``` -I .build/checkouts/libtommath/modulemap ``` Open `Package.swift` in Xcode and build, header search path in log: ``` -I ~/Library/Developer/Xcode/DerivedData/libtomcrypt-bewymzccinmagxaywggcjblpnfww/SourcePackages/checkouts/libtommath/modulemap ```
sjaeckel (Migrated from github.com) reviewed 2021-12-03 07:38:20 -06:00
@ -0,0 +1,4 @@
module libtomcrypt [extern_c] {
header "../src/headers/tomcrypt.h"
sjaeckel (Migrated from github.com) commented 2021-12-03 07:38:20 -06:00

github.com/libtom/libtommath@2cec6addaf/Package.swift (L29)

I'm not sure if this is correct or should instead state publicHeadersPath: "."

Like that you would also not need libtom/libtommath#518

https://github.com/libtom/libtommath/blob/2cec6addaf4acbd8250611ec4cecadf1f4d655ee/Package.swift#L29 I'm not sure if this is correct or should instead state `publicHeadersPath: "."` Like that you would also not need libtom/libtommath#518
cntrump (Migrated from github.com) reviewed 2021-12-03 08:54:05 -06:00
@ -0,0 +1,4 @@
module libtomcrypt [extern_c] {
header "../src/headers/tomcrypt.h"
cntrump (Migrated from github.com) commented 2021-12-03 08:54:04 -06:00

I'm not sure if this is correct or should instead state publicHeadersPath: "."

It is challenged.

Set publicHeadersPath: "." path same as sources: ["."] and use -fmodule-map-file=modulemap/module.modulemap.

It is not work:

$ swift test

....
./libtommath/mtest/mpi.h:128:8: error: conflicting types for 'mp_mul'
mp_err mp_mul(mp_int *a, mp_int *b, mp_int *c);
       ^
./libtommath/tommath.h:353:8: note: previous declaration is here
mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
       ^
<unknown>:0: error: too many errors emitted, stopping now
./libtommath/demo/tommath_tests.swift:2:8: error: could not build Objective-C module 'libtommath'
import libtommath
       ^

error: fatalError
> I'm not sure if this is correct or should instead state publicHeadersPath: "." It is challenged. Set `publicHeadersPath: "."` path same as `sources: ["."]` and use `-fmodule-map-file=modulemap/module.modulemap`. It is not work: ``` $ swift test .... ./libtommath/mtest/mpi.h:128:8: error: conflicting types for 'mp_mul' mp_err mp_mul(mp_int *a, mp_int *b, mp_int *c); ^ ./libtommath/tommath.h:353:8: note: previous declaration is here mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; ^ <unknown>:0: error: too many errors emitted, stopping now ./libtommath/demo/tommath_tests.swift:2:8: error: could not build Objective-C module 'libtommath' import libtommath ^ error: fatalError ```
sjaeckel (Migrated from github.com) reviewed 2021-12-03 09:01:00 -06:00
@ -0,0 +1,4 @@
module libtomcrypt [extern_c] {
header "../src/headers/tomcrypt.h"
sjaeckel (Migrated from github.com) commented 2021-12-03 09:01:00 -06:00

OK, but you shouldn't build mtest in the first place ... also let's move this discussion back to libtom/libtommath#518

OK, but you shouldn't build `mtest` in the first place ... also let's move this discussion back to libtom/libtommath#518
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'cntrump/pr_swiftpm_support:cntrump/pr_swiftpm_support'
git switch 'cntrump/pr_swiftpm_support'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'develop'
git merge --no-ff 'cntrump/pr_swiftpm_support'
git switch 'cntrump/pr_swiftpm_support'
git rebase 'develop'
git switch 'develop'
git merge --ff-only 'cntrump/pr_swiftpm_support'
git switch 'cntrump/pr_swiftpm_support'
git rebase 'develop'
git switch 'develop'
git merge --no-ff 'cntrump/pr_swiftpm_support'
git switch 'develop'
git merge --squash 'cntrump/pr_swiftpm_support'
git switch 'develop'
git merge --ff-only 'cntrump/pr_swiftpm_support'
git switch 'develop'
git merge 'cntrump/pr_swiftpm_support'
git push origin 'develop'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libtom/libtomcrypt!575
No description provided.