libtommath icon indicating copy to clipboard operation
libtommath copied to clipboard

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

Open cntrump opened this issue 3 years ago • 9 comments
trafficstars

for https://github.com/libtom/libtomcrypt/pull/575

cntrump avatar Dec 03 '21 05:12 cntrump

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 ...

sjaeckel avatar Dec 03 '21 10:12 sjaeckel

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

cntrump avatar Dec 03 '21 12:12 cntrump

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 avatar Dec 03 '21 12:12 sjaeckel

Reply to https://github.com/libtom/libtomcrypt/pull/575#discussion_r762003741

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

https://github.com/libtom/libtommath/blob/2cec6addaf4acbd8250611ec4cecadf1f4d655ee/Package.swift#L27

sjaeckel avatar Dec 03 '21 15:12 sjaeckel

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 avatar Dec 03 '21 15:12 cntrump

@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 avatar Dec 04 '21 02:12 cntrump

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 avatar Dec 04 '21 13:12 cntrump

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 https://github.com/apple/swift-package-manager/pull/2555

keeping a close watch on it.

cntrump avatar Dec 19 '21 12:12 cntrump

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

cntrump avatar Dec 26 '21 01:12 cntrump

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 avatar Mar 12 '24 12:03 sjaeckel