hid4java icon indicating copy to clipboard operation
hid4java copied to clipboard

Building for MacOS should encourage setting an SDK version

Open tresf opened this issue 3 years ago • 5 comments

HID4Java should be built using an older SDK, such as 10.9.

MacOS x86_64

  • At time of writing this, the 10.9 SDK is the oldest SDK which Apple will allow notarization for.
  • Normally the SDK can be extracted from a XCode 6.2 (apple.com).
  • Alternately the SDK can be obtained as a stand-alone archive from a mirror such as: https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.9.sdk.tar.xz (much smaller file size)

MacOS aarch64

  • At the time of writing this, the 11.0 SDK is the oldest SDK which is capable of building for the Apple Silicon/M1 aarch64 CPU.
  • Normally the SDK can be extracted from a XCode 12.2 (apple.com)
  • Alternately the SDK can be obtained as a stand-alone archive from a mirror such as: https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.0.sdk.tar.xz (much smaller file size)

Configuring the environment must be done in two steps:

  • Specifying the full path to the SDK
    # e.g.
    export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk 
    
  • Specifying the target OS
    # e.g.
    export MACOSX_DEPLOYMENT_TARGET=10.9
    
  • To confirm, you can check the outputted file using otool -l
    # e.g.
    otool -l src/main/resources/darwin-x86-64/libhidapi.dylib
    # or (filter relevant portion for 10.9 or 11.0 binaries)
    otool -l src/main/resources/darwin-x86-64/libhidapi.dylib |grep -E 'LC_VERSION_MIN_MACOSX|LC_BUILD_VERSION' -A4
    

tresf avatar Aug 07 '21 00:08 tresf

Is this still an issue?

gary-rowe avatar Mar 29 '24 18:03 gary-rowe

Is this still an issue?

It was merged here

  • https://github.com/gary-rowe/hid4java/pull/116

... However, I believe it's missing on the develop branch.

tresf avatar Mar 29 '24 19:03 tresf

@gary-rowe which branch is this on? Or did you decide not to add it?

Here's an example of how this was done on another branch, but the code was never merged:

https://github.com/gary-rowe/hid4java/blob/e40bdfe0b71b15b8988f5e0bc22c952a3faa0653/build-hidapi.sh#L330-L334

tresf avatar Apr 15 '24 16:04 tresf

Hi @tresf . Looks like it was missed with all the other changes to the build-hidapi.sh script. I've just pushed some changes to develop which should address the minimum targets on macOS. I've tested the new .dylibs on a couple of macOS machines and they seem OK but if you'd like to check them over I'd appreciate it.

gary-rowe avatar Apr 16 '24 12:04 gary-rowe

@gary-rowe thanks for the attention to detail however I think there may be some overkill items, such as restarting zsh with another architecture.

https://github.com/gary-rowe/hid4java/blob/672f0a7adaeac0ae9ead2cca32548ed0974886c6/build-hidapi.sh#L430

... in my experience, this was just fine by passing the arch flag to the build system.

https://github.com/gary-rowe/hid4java/blob/e40bdfe0b71b15b8988f5e0bc22c952a3faa0653/build-hidapi.sh#L337

I think this approach is cleaner and less confusing.

tresf avatar Apr 16 '24 17:04 tresf