Bundle Rust executable in MacOS .app or Windows .exe (with assets folder)


#1

Hi everyone!
So I’m trying to use cargo bundle to create a double-clickable, stand-alone bundled application for Mac OS X and Windows, which cargo bundle purports to do. When I run it (cargo bundle --release), it does successfully create a .app, but when I try to run it, it crashes. A quick investigation of the logs in Console.app suggest that this is because it cannot find the assets, but in the Info.plist the location of the assets folder is all correct. Does anyone have suggestions as to how to distribute Rust standalone applications, or fix cargo bundle?

Thanks!!


#2

I use Xcode (and cargo-xcode) to build Mac executables with Rust code supplied as a static library. This way I get all the Mac-specific bundling for free, done Apple’s way.


#3

I don’t need Mac specific bindings, so would that work for just a plain executable? Also, would that require significant changes to my build process?


#4

The extra work is required only for .app bundles (Cocoa GUI, basically). If you want just a plain command-line executable, then you don’t need any of this.

cargo-xcode does require complete change of the build system - replaces it with Xcode.app/xcodebuild.


#5

I am using SDL for this project, so it does have an interface. I just want to distribute it as something that non-programmers can launch and run like a regular application, which on the Mac is a .app.


#6

Well, i have same issue. I have a few thoughts what can be wrong.
Check if you need to connect any additional macOS libraries. And put it in Cargo.toml (osx_frameworks[])


#7

BTW,

otool -L target/release/<your_executable>

is useful for checking if the executable will work on other people’s computers. When it links /System/* and /usr/lib/* only it’s OK. If it picked some libraries from Homebrew or such, that’s trouble.


#8

Actually really nice tool, didn’t know before. Many thanks.

/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1561.60.100)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)
        /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1454.90.0)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1454.90.0)
        /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

Everything from standard libraries.


#9

I’m getting that kind of errors on others machines. Do you have any ideas how to add this libraries? I used
Cargo bundle —release

command.


#10

Before you build, export:

export MACOSX_DEPLOYMENT_TARGET=10.8

to tell the compiler to support older versions of macOS.


#11

Same result.

You are really experienced. Could you write me in telegram please? @lalabuy


#12

Please note that you need to run cargo clean after change in environmental variables, since Cargo doesn’t understand them.


#13

One more thing that you can do for macOS is to disable jemalloc and use system allocator. That might help linking with other libraries and will reduce executable size.