libevent / libevent

Event notification library
https://libevent.org
Other
10.78k stars 3.34k forks source link

libevent for iOS #1627

Closed palfonsoilluscio closed 1 week ago

palfonsoilluscio commented 2 weeks ago

Hi libevent team:

We were wondering if there's a way to have a static libevent library so it can compile for iOS and hopefully for visionOS as well.

If possible, kindly let us know.

Cheers.

widgetii commented 2 weeks ago

Hi, what's the difference between iOS and other platforms static libraries?

palfonsoilluscio commented 2 weeks ago

iOS and macOS for instance, have different SDK versions, which may result in differences in available APIs and features. But in general, while iOS and macOS static libraries share many similarities, differences in architecture, SDK versions, deployment targets, and app distribution requirements may need some adjustments when developing and using static libraries for each platform.

We can probably implement this for at least iOS by using:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios17.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.4.sdk -fembed-bitcode-marker -c -I /path/to/headers src/file_to_compile.c -o output_dir/compiled_file.o

But, if you have a better way to do so, happy to implement it...

Thanks in advance.

palfonsoilluscio commented 2 weeks ago

This is the initial error we are having, before doing anything:

ld: building for 'iOS', but linking in object file (/Users/xxx/Documents/Workspace/xxx/xxx/Frameworks/libevent.a[8](event.o)) built for 'macOS'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
palfonsoilluscio commented 2 weeks ago

If you have maybe a CI script that we can check and help us to build for iOS, that would be great...

Thanks in advance.

azat commented 2 weeks ago

ld: building for 'iOS', but linking in object file (/Users/xxx/Documents/Workspace/xxx/xxx/Frameworks/libevent.a8) built for 'macOS'

Looks like some issue in your cross compilation

If you have maybe a CI script that we can check and help us to build for iOS, that would be great...

We only have CI for MacOS - https://github.com/libevent/libevent/blob/a9426941555ec52b25c3641ebb8af72d7d91ebf8/.github/workflows/build.yml#L527-L619

pedroalfonsoo commented 2 weeks ago

Looks like some issue in your cross compilation ----> Correct, that's exactly what is happening because we are not able to get a libevent build for iOS.

We hoped we could get that from your team, is that possible or we just need look for another options?

Sorry just trying to understand the next steps.

Coeur commented 2 weeks ago

I was able to build it for iOS and visionOS easily.

  1. Make for Xcode without OpenSSL: cmake -B build -G Xcode -DEVENT__DISABLE_OPENSSL=ON
  2. Open the resulting xcodeproj: open build/libevent.xcodeproj
  3. Change Project's SDKROOT to iOS or visionOS
  4. Build the "event_static" scheme for "Any iOS Device" or "Any visionOS Device"
Coeur commented 2 weeks ago

Oh, even simpler:

For iOS

cmake -B build -G Xcode -D CMAKE_OSX_SYSROOT=iphoneos
cmake --build build -t event_static

For visionOS

cmake -B build -G Xcode -D CMAKE_OSX_SYSROOT=xros
cmake --build build -t event_static

That's all. No need to disable openssl explicitly, no need to open Xcode : all is automatic and from command-line. Product will be in built in build/lib/Debug/libevent.a.