SpriteOvO/spdlog-rs

Failed to build for iOS

SpriteOvO opened this issue · 7 comments

Discussed in #35

Originally posted by newbeeAirfeeen September 6, 2023
I have written an ios sdk now. This sdk uses spdlog-rs. But when I build the sdk of the ios general library. The following command was used:
cargo lipo
The compiler told me that there is no corresponding function on IOS。

spdlog-rs-0.3.10/src/record.rs:291:57
    |
291 |     TID.with(|tid| *tid.borrow_mut().get_or_insert_with(get_current_tid_inner))
    |                                                         ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

I downloaded the source code and checked the relevant calls in libc, and found that there seems to be no corresponding function. If I want to build on ios, is it not supported by the current version yet.
Is it possible to change the way of thinking and use other methods to obtain the thread id when building on ios

@newbeeAirfeeen Sorry I'm completely unfamiliar with iOS development. Could you give me the steps to reproduce the error? It's best to only use cli as I'd like to add testing for iOS to CI so we can support it long term.

I have now developed an SDK library for my own use on iOS. Of course, this requires compiling rust into the corresponding ios version. I believe this article explains it more clearly than I did.
https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-06-rust-on-ios.html
To put it simply, compiling into ios is equivalent to compiling rust into a static library, and then using rust FFI to let the outside world interact with the rust library through C language.
Here are the steps I took to execute the command
curl https://sh.rustup.rs -sSf | sh
rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios
cargo install cargo-lipo
cargo lipo --release
Finally, the compiler reported:

spdlog-rs-0.3.10/src/record.rs:291:57
|
291 | TID.with(|tid| *tid.borrow_mut().get_or_insert_with(get_current_tid_inner))
| ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

This is the record.rs code in spdlog. This error is equivalent to telling us that on the iOS platform, libc does not provide a method for obtaining the corresponding thread ID(I'm not sure if libc provides the corresponding method, but at least in spdlog, there is no adaptation similar to #[cfg(target_os="ios")
image
Because on ios, regardless of using the c++11 standard. Or use c with posix threads. You can get the current thread id. Other ways can be considered here.
If your current compilation environment is limited, I can provide some help.

@newbeeAirfeeen Much helped! Seems like we can just run cargo test with --target x86_64-apple-ios, it reproduces the error well, but tests cannot be executed with error dyld[2975]: DYLD_ROOT_PATH not set for simulator program. Launching a simulator (https://github.com/futureware-tech/simulator-action) doesn't solve it, I'm trying to figure out it.

UPDATE: BTW, I'm trying to setup the CI on GitHub Actions macos-latest runner.

I didn't see your submission just now, so I submitted a PR. I just confirmed and verified that pthread_threadid_np can indeed be called on ios. This has been compiled on my example

Fixed in #37. Thanks for your report and help!

New version will be released in a few hours because I'm outside now.

Released in v0.3.11.