tazz4843/whisper-rs

Can not build with --target=x86_64-apple-darwin on Mac M1

Closed this issue · 11 comments

Hi,

When I build my rust project with --target=x86_64-apple-darwin.

cargo build --target=x86_64-apple-darwin

Encountered the following error:

  = note: ld: in /Users/farmer/Projects/my-project/rust/target/x86_64-apple-darwin/debug/deps/libwhisper_rs_sys-cb1bd74588817382.rlib(ggml.c.o), archive member 'ggml.c.o' with length 244616 is not mach-o or llvm bitcode file '/Users/farmer/Projects/my-project/rust/target/x86_64-apple-darwin/debug/deps/libwhisper_rs_sys-cb1bd74588817382.rlib'

Cross building might not be supported by upstream, you may have to build on the target host.

@tazz4843 Is there a way to support cross compilation? I am building a flutter application on MacOS. I want the app supporting Intel chip and M1/M2 chip in the same time.

Can you describe in detail the reasons why it cannot be cross-compiled? Maybe I can learn some relevant knowledge so that I can make some contribution.

According to the error message, it is because whisper.cpp does not compile for the target x86_64?

The upstream project, whisper.cpp itself, may not fully support cross compilation. whisper.cpp itself definitely supports x86_64 Macs, as I've seen issues on this repo mentioning x86_64 on MacOS working fine. You'd probably have to pass some flags to CMake to see if it works. From a quick internet search, I found this: https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html but it looks like a huge headache to implement without turning build.rs into a mess.

I did find ggerganov/whisper.cpp#514, but that gives little to no help.

@tazz4843

It looks that adding below command into CMakeLists.txt can output the dylib file supporting both x86_64 and arm64 arch.

set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")

You'd have to make a PR to upstream and wait for it to be released before this can get upgraded.

@farmer00317558 did you ever figure this issue out? Getting the same error when building (M1 Max).

@farmer00317558 did you ever figure this issue out? Getting the same error when building (M1 Max).

I abandoned the library, wrote a C++ file myself that references the whisper.cpp directly, and built a dynamic library for my project.

@farmer00317558 that's really cool– well done. Do you mind sharing the code with me?

Gonna close this due to age, if you've resolved it feel free to let us know.