05nelsonm / kmp-tor-binary

Apache License 2.0
5 stars 2 forks source link

Add native darwin support #120

Closed 05nelsonm closed 10 months ago

05nelsonm commented 11 months ago

Add macOS, iOS, tvOS, watchOS support.

Tor will need to be compiled, codesigned, and packaged so it can be extracted to the appropriate destination (just like Jvm/Js).

A new packaging tool and runtime library will be needed as there currently exists no way to add resources to a .klib.

The simplest way it seems to package things is to base64 encode each resource and add as .kt files with some sort of header.

// resource_geoip.kt

// AUTO-GENERATED FILE
// DO NOT MODIFY

internal object resource_geoip: NativeResource(
    version = 1,
    filename = "geoip",
    rawSize = 1_039_091L,
    chunkSize = 4096,
    sha256 = "...",
    compression = NativeResource.Compression.GZIP,
    // ...
    chunks = Array<String>(254).apply {
        val a = this
        a[  0] = geoip_000; a[  1] = geoip_001
        // ...
        a[156] = geoip_156; a[157] = geoip_157
    },
)

// TODO: Maybe not a constant???
private const val geoip_000: String = """
......
4096 bytes of base64 encoded text
"""

private const val geoip_001: String = """
......
4096 bytes of base64 encoded text
"""

Will have to see if gzipping is possible before encoding. Also, this is a perfect use case for EncoderDecoder.Feed https://github.com/05nelsonm/encoding

05nelsonm commented 11 months ago

I think that for the tool and it's use case, it'd work best as a gradle plugin. The whole process will go something like this

A runtime library will be needed to provide the NativeResource abstraction (maybe rename to KmpResource in case future support for other platforms than just darwin targets???) which has the extraction logic and will simply provide a stream.

05nelsonm commented 11 months ago

Split this issue up by creating #134 for implementing NativeResource

Adding the blocked label until that is completed.

05nelsonm commented 11 months ago

Finally ready to start working on task.sh build script for darwin targets after #155

05nelsonm commented 11 months ago

will need to use the lipo tool for darwin to make a multi-arch binary so they can be written to iosMain, macosMain, tvosMain, and watchosMain and not individually for each architecture. Will significantly reduce the size.

05nelsonm commented 10 months ago

will need to use the lipo tool for darwin to make a multi-arch binary so they can be written to iosMain, macosMain, tvosMain, and watchosMain and not individually for each architecture. Will significantly reduce the size.

Unsure how the simulators will work with this because there'll be multiple arm64 architectures. May need to configure source sets separately.

e.g.

darwinMain
    |--- iosMain
    |        |--- iosArm64
    |        '--- iosX64
    |--- iosSimulatorArm64
    ...
05nelsonm commented 10 months ago

So compiling on macOS machine using Xcode.app is simply not going to work. Output is not reproducible. Working on another docker container for iPhoneOS and iPhoneSimulator SDKs.

05nelsonm commented 10 months ago

ios/ios-simulator docker files will live in kmp-tor-binary until things are ready for release. #168 has been created so I do not forget about it :smirk_cat:

05nelsonm commented 10 months ago

Native support for macOS was implemented in #171

Remaining targets will be rolled out separately (tons of work getting things compiling via docker using cctools-port). Closing this as "completed" and delegating the remaining items to the following issue tickets: