Compile rust binary for older versions of Mac OSX

I'm trying to compile a rust binary on Mac OS Catalina (v 10.15) which needs to be compatible with Mac OS versions 10.8 (OSX Mountain lion) and above.

I have set the following flag in the .cargo/config file:

[target.x86_64-apple-darwin]
rustflags=["-C", "link-arg=-mmacosx-version-min=10.8"]

This produces a binary which when inspected with otool -l shows the min version correctly

Load command 9
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.8
      sdk 10.15

However when I run the binary on a lower OS version it gives me the error:

dyld: Symbol not found: ____chkstk_darwin
Expected in: /usr/lib/libSystem.B.dylib

Is there anything I can do to force rust to use a compatibility version of the libSystem ?

These are the dynamic dependencies of my binary

otool -L indexer
indexer:
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1069.11.0)
	/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 59306.41.2)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
	/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 1673.126.0)

I am building using this command:

cargo build --target=x86_64-apple-darwin --release --bins

cc: @alexcrichton maybe you could help or point me in some direction ? I have seen other posts by you regarding linking and compiling binaries on OSX so trying my luck here.

I don't have macOS experience myself, but there's some discussion in the release team about this. In theory, we claim to support as low as 10.7, but we don't have CI to actually test that.

I don't personally recognize the ____chkstk_darwin symbol, so it may be pulled in by C code perhaps? Do you have C/C++ somewhere in the build? If so you'll need to pass a similar compile flag to them.

1 Like

Have you tried

export MACOSX_DEPLOYMENT_TARGET=10.8

?

I suspect some -sys crates may be invoking a C compiler and making objects for the default sdk.

1 Like

Thanks for the responses!

@cuviper this issue was happening on 10.13 which is ~2 years old. I'm guessing there is still CI for that?

@alexcrichton @kornel turns out I do depend on a crate which has a dependency on a sys crate. Setting MACOSX_DEPLOYMENT_TARGET does seem to set the correct LC_VERSION_MIN_MACOSX on the dependent C binary.

Hopefully this should fix the issue.

I will mark this issue as resolved once I have been able to verify this.