Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] CoreHaptics framework is not weakly linked, causing a hard dependency on CoreHaptics #1241

Open
bigfarts opened this issue Aug 1, 2022 · 2 comments

Comments

@bigfarts
Copy link
Contributor

bigfarts commented Aug 1, 2022

On macOS <Catalina, CoreHaptics.framework is not present so running a rust-sdl2 program linked against CoreHaptics doesn't work. It looks like usually CoreHaptics.framework is weakly linked in the C build of SDL, but I don't know how to do this in Rust.

This only occurs with statically linked SDL, I think with dynamic linking it's probably fine.

@VyrCossont
Copy link

I can't even build a program with statically linked SDL since #1219 was merged, let alone run one, even on macOS 13 (Ventura):

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-arch" "x86_64" "-m64" "/var/folders/nx/2bm5r6ld5fs1qx39r9f45_f00000gn/T/rustcvaL55t/symbols.o" [long list of .rlib files] "-framework" "DiskArbitration" "-framework" "IOKit" "-framework" "Foundation" "-framework" "IOKit" "-framework" "CoreFoundation" "-framework" "IOKit" "-framework" "CoreFoundation" "-framework" "AppKit" "-framework" "Foundation" "-framework" "CoreBluetooth" "-framework" "AppKit" "-framework" "QuartzCore" "-framework" "Foundation" "-lobjc" "-framework" "CoreGraphics" "-lSystem" "-framework" "Security" "-framework" "CoreFoundation" "-framework" "Cocoa" "-framework" "IOKit" "-framework" "Carbon" "-framework" "ForceFeedback" "-framework" "GameController" "-framework" "CoreVideo" "-framework" "CoreAudio" "-framework" "AudioToolbox" "-framework" "Metal" "-liconv" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/Users/user/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/user/Projects/Foo/rust/foo/target/release/deps/foo-b3f9e61ac6a009a5" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: Undefined symbols for architecture x86_64:
            "_CHHapticDynamicParameterIDHapticIntensityControl", referenced from:
                -[SDL_RumbleMotor setIntensity:] in libsdl2_sys-fab2ce44955feef8.rlib(SDL_mfijoystick.m.o)
            "_CHHapticEventParameterIDHapticIntensity", referenced from:
                -[SDL_RumbleMotor setIntensity:] in libsdl2_sys-fab2ce44955feef8.rlib(SDL_mfijoystick.m.o)
            "_CHHapticEventTypeHapticContinuous", referenced from:
                -[SDL_RumbleMotor setIntensity:] in libsdl2_sys-fab2ce44955feef8.rlib(SDL_mfijoystick.m.o)
            "_OBJC_CLASS_$_CHHapticDynamicParameter", referenced from:
                objc-class-ref in libsdl2_sys-fab2ce44955feef8.rlib(SDL_mfijoystick.m.o)
            "_OBJC_CLASS_$_CHHapticEvent", referenced from:
                objc-class-ref in libsdl2_sys-fab2ce44955feef8.rlib(SDL_mfijoystick.m.o)
            "_OBJC_CLASS_$_CHHapticEventParameter", referenced from:
                objc-class-ref in libsdl2_sys-fab2ce44955feef8.rlib(SDL_mfijoystick.m.o)
            "_OBJC_CLASS_$_CHHapticPattern", referenced from:
                objc-class-ref in libsdl2_sys-fab2ce44955feef8.rlib(SDL_mfijoystick.m.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `foo` due to previous error

Additionally, Core Haptics isn't even a native macOS API, it's a Catalyst API, and probably won't work outside of Catalyst apps. Is there some way we could make linking against it conditional to the platform (iOS, iPadOS, Catalyst)?

@VyrCossont
Copy link

Weak framework linker flags as in https://users.rust-lang.org/t/how-to-use-weak-linking-on-macos-link-with-weak-framework/50732 don't seem to be supported. Weak linking as a compiler feature is tracked in rust-lang/rust#29603 but probably won't happen any time soon given that it's now apparently marked "perma-unstable"; I'm not sure if it's relevant to this case anyway.

There's a workaround described at https://internals.rust-lang.org/t/support-for-macos-weak-linking/13796/5 using .cargo/config.toml that got my project unblocked, but it isn't usable at the sdl2 library level:

[target.x86_64-apple-darwin]
rustflags = ["-C", "link-args=-weak_framework CoreHaptics"]

VyrCossont added a commit to VyrCossont/Pinput that referenced this issue Dec 5, 2022
tedsteen added a commit to tedsteen/nes-bundler that referenced this issue Apr 12, 2023
tedsteen added a commit to tedsteen/nes-bundler that referenced this issue Apr 12, 2023
tedsteen referenced this issue Apr 12, 2023
This framework is used by the SDL_JOYSTICK module, but it is missing from Darwin builds.
I have confirmed that this fixes my issues on my MacOS build. I have added the directive for the iOS builds, too, but that will need to be double-checked as I don't have a workflow for that.
tedsteen added a commit to tedsteen/nes-bundler that referenced this issue Apr 12, 2023
tedsteen added a commit to tedsteen/nes-bundler that referenced this issue Apr 12, 2023
tedsteen added a commit to tedsteen/nes-bundler that referenced this issue Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants