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

iOS/Android support #1384

Closed
ospfranco opened this issue May 12, 2024 · 6 comments
Closed

iOS/Android support #1384

ospfranco opened this issue May 12, 2024 · 6 comments

Comments

@ospfranco
Copy link
Contributor

ospfranco commented May 12, 2024

I'm trying to build static library (.a) that I can use on iOS and Android. I'm trying to compile the C experimental bindings, doing cargo build --target [TARGET] --release works and compiles the library correctly.

The problem however lies when I try to create all three iOS archs (x86_64-apple-ios, aarch64-apple-ios, aarch64-apple-ios-sim) and then generate a single fat binary for x86_64-apple-ios and aarch64-apple-ios-sim, which is needed to package all of them in a single .xcframework

I get the following error:

lipo -create ../../target/x86_64-apple-ios/release/libsql_experimental.a ../../target/aarch64-apple-ios-sim/release/libsql_experimental.a -output generated/simulator_fat/libsql_experimental.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: archive member ../../target/x86_64-apple-ios/release/libsql_experimental.a(sqlite3mc.c.o) cputype (16777228) and cpusubtype (0) does not match previous archive members cputype (16777223) and cpusubtype (3) (all members must match)
make: *** [libsql.xcframework] Error 1

Which seems to indicate the sqlite3mc.c object file has not been compiled for the correct architecture.

Are there some instructions to compile the library to iOS/Android? I've seen at least one person that has managed to compile it for Android.

@haaawk
Copy link
Contributor

haaawk commented May 12, 2024

I successfully ran libsql on Android. I don't think I had to do anything special. What I do though is having a new Rust lib project that depends on libsql.

@ospfranco
Copy link
Contributor Author

ospfranco commented May 12, 2024

Running lipo on the generated .a for x86_64 allowed me to pin point the problem:

lipo -info ../../target/x86_64-apple-ios/release/libsql_experimental.a                                                                                   
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: archive member ../../target/x86_64-apple-ios/release/libsql_experimental.a(sqlite3mc.c.o) cputype (16777228) and cpusubtype (0) does not match previous archive members cputype (16777223) and cpusubtype (3) (all members must match)

Indeed it seems the cargo build is targeting apple ios x86_64 but the generated sqlite object file has been compiled for another arch. Looking at the build script I find nothing weird. The cc crate is used for compiling the sqlite source file which should handle cross compilation gracefully. So it seems this path with a cmake build is happening (maybe due the encryption feature being turned on?).

I've added the following to try to make cross compilation work, but it doesn't seem to be doing anything:

if target.contains("x86_64-apple-ios") {
    cmake_opts.push(&cmake_toolchain_opt);
    writeln!(toolchain_file, "set(CMAKE_SYSTEM_NAME \"iOS\")").unwrap();
    writeln!(toolchain_file, "set(CMAKE_SYSTEM_PROCESSOR \"x86_64\")").unwrap();
}

Edit: turning off the encryption feature does indeed allow the crate to compile successfully. Seems indeed the cmake compilation is off for non-host architectures.

@psarna
Copy link
Collaborator

psarna commented Jun 1, 2024

@ospfranco yep, encryption library build system has a complicated cmake<->cargo relationship, and it's not adjusted for cross compiling, it would require a few changes or manual steps. If you don't need encryption at rest, best just to skip it

@ospfranco
Copy link
Contributor Author

Yeah, I ended up removing the encryption feature and it is working. I have another issue. The openRemote function is working for iOS but on android there is a certificate error. I'm guessing it is missing openSSL, do you know if I can fix this easily or I need to change the build process to somehow include openSSL

@psarna
Copy link
Collaborator

psarna commented Jun 1, 2024

Sounds like an issue with lack of local certs in Android, maybe? I remember reading about https://crates.io/crates/rustls-platform-verifier once as a workaround, but never went further than research

@ospfranco
Copy link
Contributor Author

Created a new ticket for that issue:

#1432

Closing this one as sqlcipher support is not planned at least for now :)

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

No branches or pull requests

3 participants