I figured out what the problem was. I was an idiot in many ways :

- the submodule had an invalid detatched head commit hash. Dunno why.
- the package swift file defined a wrong version number for libmaxminddb. Moral of the story : don't be an ass.
- some leftover garbage from automake made me believe I was done
- potato
This commit is contained in:
Adam Rocska 2020-04-27 21:27:28 +02:00
parent 731ac6da87
commit 4fc53d970c
12 changed files with 118 additions and 15 deletions

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[submodule "libmaxminddb"]
path = libmaxminddb
url = https://github.com/maxmind/libmaxminddb
[submodule "Sources/libmaxminddb"]
path = Sources/libmaxminddb
url = https://github.com/maxmind/libmaxminddb

6
.idea/..iml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="." external.linked.project.path="$MODULE_DIR$/./." external.root.project.path="$MODULE_DIR$" external.system.id="SPM" type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -2,6 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/../../.idea/..iml" filepath="$PROJECT_DIR$/../../.idea/..iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/GeoIP2-swift.iml" filepath="$PROJECT_DIR$/.idea/GeoIP2-swift.iml" />
</modules>
</component>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/Sources/libmaxminddb" vcs="Git" />
<mapping directory="$PROJECT_DIR$/Sources/libmaxminddb/t/libtap" vcs="Git" />
<mapping directory="$PROJECT_DIR$/Sources/libmaxminddb/t/maxmind-db" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$/libmaxminddb" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../../Sources/libmaxminddb" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../../Sources/libmaxminddb/t/libtap" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../../Sources/libmaxminddb/t/maxmind-db" vcs="Git" />
</component>
</project>

View File

@ -36,8 +36,16 @@ let package = Package(
),
.target(
name: "libmaxminddb",
name: "libmaxminddb_config",
dependencies: [],
path: "Sources/libmaxminddb_config",
sources: ["./src/"],
publicHeadersPath: "./include/"
),
.target(
name: "libmaxminddb",
dependencies: ["libmaxminddb_config"],
path: "Sources/libmaxminddb",
exclude: [
"./autom4te.cache/",
@ -50,7 +58,7 @@ let package = Package(
],
sources: ["./src/"],
publicHeadersPath: "./include/",
cSettings: [CSetting.define("PACKAGE_VERSION", to: "\"1.4.2\"")]
cSettings: [CSetting.define("PACKAGE_VERSION", to: "\"1.3.2\"")]
),
.testTarget(

View File

@ -8,6 +8,13 @@ Inspiration, and initial state of repository from
[lexrus's](https://github.com/lexrus) [MMDB-Swift](https://github.com/lexrus/MMDB-Swift)
repository.
## Disclaimers
1. I'm no C guru.
2. I'm no Swift guru.
3. I have no idea what I'm doing.
4. For my purposes the lib' works as is, but be super cautious because of items 1-3.
## Version Infos
### 1. [libmaxminddb](https://github.com/maxmind/libmaxminddb) : [1.3.2](https://github.com/maxmind/libmaxminddb/releases/tag/1.3.2)

@ -1 +0,0 @@
Subproject commit 2e2117f98efe3c47038daf072b755198c01bee63

View File

@ -0,0 +1,24 @@
# libmaxminddb_config
## Why this module exists?
[libmaxminddb](https://github.com/maxmind/libmaxminddb) is build using
[automake](https://www.gnu.org/software/automake/).
The tool
[autoreconf](https://www.gnu.org/software/autoconf/manual/autoconf-2.68/html_node/autoreconf-Invocation.html)
ran as `autoreconf -fiv` will generate the
[configure script](https://developer.gnome.org/anjuta-build-tutorial/stable/create-autotools.html.en)
necessary for building libmaxminddb, which will also produce a configuration
header file called `maxminddb_config.h`.
In order for us to keep the library decoupled, as a git submodule, we need a way
to either build the project via Swift Package Manager, either inject a
configuration header file. At the time of writing **Swift Package Manager** is
not able to solve this problem, so we need to opt in to some automated injection.
This is where this clumsy module comes into play.
## Redundant definitions in header & c file
I know.
Sadly there was no way around via Swift Package Manager at the time of writing.

View File

@ -0,0 +1,15 @@
/* include/maxminddb_config.h. Generated from maxminddb_config.h.in by configure. */
#ifndef MAXMINDDB_CONFIG_H
#define MAXMINDDB_CONFIG_H
#ifndef MMDB_UINT128_USING_MODE
/* Define as 1 if we we use unsigned int __atribute__ ((__mode__(TI))) for uint128 values */
#define MMDB_UINT128_USING_MODE 0
#endif
#ifndef MMDB_UINT128_IS_BYTE_ARRAY
/* Define as 1 if we don't have an unsigned __int128 type */
#define MMDB_UINT128_IS_BYTE_ARRAY 0
#endif
#endif /* MAXMINDDB_CONFIG_H */

View File

@ -0,0 +1,45 @@
# libmaxminddb_helper
## Why this module exists?
**There are 2 reasons :**
* maxminddb_typecast.c & h
* maxminddb-compat-util.h
## maxminddb_typecast.c
Since [libmaxminddb](https://github.com/maxmind/libmaxminddb) operates with all
sorts of pointer tricks, it's not too comfortable to acquire results from the C
API in Swift. So we need a simple solution to represent these values in a more
digestible way.
Kudos once again go to [lexrus](https://github.com/lexrus)'s
[MMDB-Swift](https://github.com/lexrus/MMDB-Swift) where this whole repository
started from. Original sources :
* [maxminddb_unions.c](https://github.com/lexrus/MMDB-Swift/blob/639b0d811694a27eab6cc6834a968888f666972d/Sources/libmaxminddb/maxminddb_unions.c)
* [maxminddb_unions.h](https://github.com/lexrus/MMDB-Swift/blob/639b0d811694a27eab6cc6834a968888f666972d/Sources/libmaxminddb/maxminddb_unions.h)
## maxminddb-compat-util.h
Again, another case of "I have no idea what I'm doing 🙂". Sorry.
So, [libmaxminddb](https://github.com/maxmind/libmaxminddb) depends on a few
functions which are included in its source, however Swift Package Manager for
whatever reason couldn't resolve it. I assume it's because the header file is in
the `src` directory, and so far I had the impression, that Swift Package Manager
(quite rightfully) prefers to keep things separated.
Anyho', it's here, and it compiles. There's another catch though. Why do I have
only a header file and in the include dir. Another case of
**I have no idea what I'm doing**. When I separated the definitions from the
source in seperate C and header files, compilation failed with only one function
definition being undefined (which isn't undefined imho...)
```
Undefined symbols for architecture x86_64:
"_mmdb_strndup", referenced from:
_$s6GeoIP2AAC9getString024_01864207E763388F378F6E4G7DD973A2LLySSSpySo22MMDB_entry_data_list_sVGF in GeoIP2.swift.o
ld: symbol(s) not found for architecture x86_64
```
In its current state it helps [libmaxminddb](https://github.com/maxmind/libmaxminddb)
compile.

View File

@ -24,11 +24,12 @@ class GeoIP2Tests: XCTestCase {
XCTAssertEqual(database.lookup("8.8.8.8")?.isoCode, "US")
XCTAssertEqual(database.lookup("8.8.4.4")?.isoCode, "US")
XCTAssertNotNil(database.lookup(IPOfHost("youtube.com")!))
XCTAssertNotNil(database.lookup(IPOfHost("facebook.com")!))
XCTAssertNotNil(database.lookup(IPOfHost("twitter.com")!))
XCTAssertNotNil(database.lookup(IPOfHost("instagram.com")!))
XCTAssertNotNil(database.lookup(IPOfHost("google.com")!))
XCTAssertNotNil(database.lookup("80.99.18.166"))
XCTAssertNotNil(database.lookup("172.217.18.78"))
XCTAssertNotNil(database.lookup("31.13.84.36"))
XCTAssertNotNil(database.lookup("104.244.42.129"))
XCTAssertNotNil(database.lookup("52.86.229.116"))
XCTAssertNotNil(database.lookup("172.217.19.110"))
}
func testCloudFlare() {