Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support use #include <tommath.h> for SwiftPM dependencies #518

Closed
wants to merge 4 commits into from

Conversation

cntrump
Copy link
Contributor

@cntrump cntrump commented Dec 3, 2021

@sjaeckel
Copy link
Member

sjaeckel commented Dec 3, 2021

How about setting the include path correctly instead? Or is that not possible in this swift package manager thing?

@royjit maybe you can give some hints here how this is done properly!? Adding another header simply doesn't look right to me ...

@cntrump
Copy link
Contributor Author

cntrump commented Dec 3, 2021

How about setting the include path correctly instead? Or is that not possible in this swift package manager thing?

A depend on package B use dependencies: [.package(url:...)] in Package.swift of A
A import B use #include <B.h> in source
SwiftPM find B.h in publicHeadersPath on Package.swift of B

now, SwiftPM can't find tommath.h on path publicHeadersPath: "modulemap" defined in Package.swift of libtommath

0038-swiftpm-c-language-targets.md

@sjaeckel
Copy link
Member

sjaeckel commented Dec 3, 2021

After reading SE-0038 I'm still not entirely sure if that's the correct way to do things.

@ddunbar sorry highlighting you here, but you are the author of said specification and maybe you can shed some light on this? ... please also read through the comments in libtom/libtomcrypt#575 for further context ...

@sjaeckel
Copy link
Member

sjaeckel commented Dec 3, 2021

Reply to libtom/libtomcrypt#575 (comment)

Why is this building mtest if it's on the exclude list?

exclude: ["demo", "doc", "etc", "logs", "mtest"],

@cntrump
Copy link
Contributor Author

cntrump commented Dec 3, 2021

Why is this building mtest if it's on the exclude list?

It seems .unsafeFlags(["-flto=thin", "-fmodule-map-file=modulemap/module.modulemap"]) is ignored.

a new module.modulemap created:

module libtommath {
    umbrella "/a/b/c/libtommath"
    export *
}

umbrella "/a/b/c/libtommath" expose all symbols in *.h

@cntrump
Copy link
Contributor Author

cntrump commented Dec 4, 2021

@sjaeckel

How about build libtomcrypt as objective-c source and add @import TomMath; in math/ltm_desc.c ?

I tried, it works and just math/ltm_desc.c modified.

Package.swift of libtomcrypt

.unsafeFlags(["-xobjective-c"]),

math/ltm_desc.c

#ifdef SWIFT_PACKAGE
@import TomMath;
#else
#include <tommath.h>
#endif

Using Modules
To enable modules, pass the command-line flag -fmodules. This will make any modules-enabled software libraries available as modules as well as introducing any modules-specific syntax.

I can't figure it out yet

@cntrump
Copy link
Contributor Author

cntrump commented Dec 4, 2021

creating-c-language-targets
To allow a Swift target to import a C language target, add a target dependency in the manifest file. Swift Package Manager will automatically generate a modulemap for each C language library target for these 3 cases:

  • If include/Foo/Foo.h exists and Foo is the only directory under the include directory, and the include directory contains no header files, then include/Foo/Foo.h becomes the umbrella header.

  • If include/Foo.h exists and include contains no other subdirectory, then include/Foo.h becomes the umbrella header.

  • Otherwise, the include directory becomes an umbrella directory, which means that all headers under it will be included in the module.

In case of complicated include layouts or headers that are not compatible with modules, a custom module.modulemap can be provided in the include directory.

Keep trying

@cntrump
Copy link
Contributor Author

cntrump commented Dec 19, 2021

Swift 5.2 Issue with headers in same dir as .c/m files
https://forums.swift.org/t/swift-5-2-issue-with-headers-in-same-dir-as-c-m-files/33292

[PackageLoading] Handle header files in TargetSourcesBuilder
swiftlang/swift-package-manager#2555

keeping a close watch on it.

@cntrump
Copy link
Contributor Author

cntrump commented Dec 26, 2021

Why is this building mtest if it's on the exclude list?

I found it, it'is a bug: https://bugs.swift.org/browse/SR-14456

https://forums.swift.org/t/unable-to-exclude-specific-headers-from-a-target/51017

@sjaeckel sjaeckel mentioned this pull request Feb 23, 2022
DavidSouthgate added a commit to DavidSouthgate/TomMathSPM that referenced this pull request Jun 18, 2023
@sjaeckel
Copy link
Member

I'm closing this as there was no action for too long.
Please re-open if you have further questions/comments/improvements and still want this to be merged.

@sjaeckel sjaeckel closed this Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants