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

Adding MacOS M1 support. #89

Merged
merged 1 commit into from
Mar 14, 2024
Merged

Conversation

metasim
Copy link
Contributor

@metasim metasim commented Mar 14, 2024

This adds building libpdaljni.dylib for arm64 architectures.

I have successfully tested this up to the publish workflow:

https://github.com/s22s/PDAL-Java/actions/runs/8282743168

...but I need advice on how to test that stage.

Closes #61

@pomadchin
Copy link
Collaborator

Yo Sim! Btw trying it in your fork is the ez way; But I'll click buttons here to assist you as well haha.

@pomadchin
Copy link
Collaborator

That's sick! Thanks 🎉

@pomadchin
Copy link
Collaborator

I'm going to merge it, and its gonna trigger a snapshot publish.

@pomadchin pomadchin merged commit fd27b0c into PDAL:main Mar 14, 2024
5 checks passed
@pomadchin
Copy link
Collaborator

Could you test it with 2.6.2+2-fd27b0cc-SNAPSHOT?

@pomadchin
Copy link
Collaborator

pomadchin commented Mar 14, 2024

Ha, it does not really work on my mac 🤔

scala> System.load("/Users/.../Downloads/test/native/arm64-darwin/libpdaljni.2.6.dylib")
java.lang.UnsatisfiedLinkError: Can't load library: /Users/.../Downloads/test/native/arm64-darwin/libpdaljni.2.6.dylib

That's a dylib from the downloaded natives jar.

Wondering what's wrong with it.

$ file libpdaljni.2.6.dylib
libpdaljni.2.6.dylib: Mach-O 64-bit dynamically linked shared library arm64
$ otool -L libpdaljni.2.6.dylib
libpdaljni.2.6.dylib:
	@rpath/libpdaljni.2.6.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libpdalcpp.16.dylib (compatibility version 16.0.0, current version 16.3.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1600.151.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)

Which maches my locally built dylib as well 🤔

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

Why would it be referencing itself? @rpath/libpdaljni.2.6.dylib? or is that expected?

@pomadchin
Copy link
Collaborator

@metasim the first line is the ID string of the dynamic library, it is expected yea

@pomadchin
Copy link
Collaborator

My local otool diff (red - local, green - published via CI)

image

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

Output on my machine, which is macos 14.3.1

/Users/sfitch/Downloads/libpdaljni.2.6.dylib:
	@rpath/libpdaljni.2.6.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libpdalcpp.16.dylib (compatibility version 16.0.0, current version 16.3.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1600.151.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)

@pomadchin
Copy link
Collaborator

ha, does it work for you?

@pomadchin
Copy link
Collaborator

the only diff I see is /usr/lib/libc++.1.dylib 🤔

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

ha, does it work for you?

I need to convince macos it's safe first 😆

scala> System.load("/Users/sfitch/Downloads/libpdaljni.2.6.dylib")
java.lang.UnsatisfiedLinkError: /Users/sfitch/Downloads/libpdaljni.2.6.dylib: dlopen(/Users/sfitch/Downloads/libpdaljni.2.6.dylib, 0x0001): tried: '/Users/sfitch/Downloads/libpdaljni.2.6.dylib' (code signature in <4D31D938-9728-3052-ADBC-9F374E36F4D9> '/Users/sfitch/Downloads/libpdaljni.2.6.dylib' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/Users/sfitch/Downloads/libpdaljni.2.6.dylib' (no such file), '/Users/sfitch/Downloads/libpdaljni.2.6.dylib' (code signature in <4D31D938-9728-3052-ADBC-9F374E36F4D9> '/Users/sfitch/Downloads/libpdaljni.2.6.dylib' not valid for use in process: library load disallowed by system policy)
  at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
  at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
  at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
  at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
  at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
  at java.base/java.lang.Runtime.load0(Runtime.java:755)
  at java.base/java.lang.System.load(System.java:1953)
  ... 35 elided

Edit: use sudo xattr -d com.apple.quarantine ./libpdaljni.2.6.dylib

@pomadchin
Copy link
Collaborator

Oh man that's it; ha; weird so weird; I guess it's macos version diff

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

@pomadchin It's been a number of years since I've done RPATH wrangling.... any thoughts on why this wouldn't work?

❯ ls /opt/homebrew/lib/libpdalcpp.*
/opt/homebrew/lib/libpdalcpp.16.3.0.dylib /opt/homebrew/lib/libpdalcpp.16.dylib     /opt/homebrew/lib/libpdalcpp.dylib

❯ DYLD_LIBRARY_PATH=/opt/homebrew/lib scala

...

scala> System.load("/Users/sfitch/Downloads/libpdaljni.2.6.dylib")
java.lang.UnsatisfiedLinkError: /Users/sfitch/Downloads/libpdaljni.2.6.dylib: dlopen(/Users/sfitch/Downloads/libpdaljni.2.6.dylib, 0x0001): Library not loaded: @rpath/libpdalcpp.16.dylib

  Referenced from: <4D31D938-9728-3052-ADBC-9F374E36F4D9> /Users/sfitch/Downloads/libpdaljni.2.6.dylib

  Reason: tried: '/Users/runner/miniconda3/envs/pdal-java/lib/libpdalcpp.16.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/miniconda3/envs/pdal-java/lib/libpdalcpp.16.dylib' (no such file), '/Users/runner/miniconda3/envs/pdal-java/lib/libpdalcpp.16.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/miniconda3/envs/pdal-java/lib/libpdalcpp.16.dylib' (no such file), '/Users/sfitch/.sdkman/candidates/java/17.0.6-tem/lib/server/./libpdalcpp.16.dylib' (no such file), '/Users/sfitch/.sdkman/candidates/java/17.0.6-tem/lib/server/../libpdalcpp.16.dylib' (no such file), '/Users/sfitch/.sdkman/candidates/java/17.0.6-tem/bin/./libpdalcpp.16.dylib' (no such file), '/Users/sfitch/.sdkman/candidates/java/17.0.6-tem/bin/
  

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

Oh man that's it; ha; weird so weird; I guess it's macos version diff

They only have M1 builders for MacOS 14. You must be on 13?

@pomadchin
Copy link
Collaborator

Nah, I meant more like some new security stuff; wondering why x86 builds are fine and arm is not.

About libpdalcpp.16.dylib mb its not there? I'd reinstall pdal / try the new conda env with pdal 2.6.3 😃

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

Looks like the bound RPATH is to the runner's conda environment?

❯ otool -l libpdaljni.2.6.dylib | grep -A2 LC_RPATH
          cmd LC_RPATH
      cmdsize 56
         path /Users/runner/miniconda3/envs/pdal-java/lib (offset 12)

I'm assuming there's a way to get it to link without using @rpath.

@pomadchin
Copy link
Collaborator

yea, so it should be good; most likely you just really don't have a file its trying to find / or its somehwere else.

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

Not sure why it worked on x86 (older macos?), but I think I need to figure out how to not have it expect the library to be installed in /Users/runner/miniconda3/envs/pdal-java/lib. I'll work on it.

@pomadchin
Copy link
Collaborator

ha really?

just install pdal into the conda env; btw I think that's how conda envs work on mac; TBH locally I use PDAL via conda only 🤷

@pomadchin
Copy link
Collaborator

ok google for a bit, we need to sign apple binaries; that could be the arm thing, but ideally should be done with x86 binaries as well.

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

@pomadchin
Copy link
Collaborator

pomadchin commented Mar 14, 2024

btw smth is not loading for me locally even with xattr -d com.apple.quarantine; I'll look into it as well. I originally thought it works but eh ):

Another thing is that signature is $$ (dev account). ): Hopefully will be able to find some alternative solution that works.

@metasim
Copy link
Contributor Author

metasim commented Mar 14, 2024

btw smth is not loading for me locally

What version of MacOS are you on? If it's < 14, I think it's because the M1 builder runs on 14, and I need to find a setting to be backward compatible.

@pomadchin
Copy link
Collaborator

14.1.2

@pomadchin
Copy link
Collaborator

Moved signature stuff into #90

@metasim metasim deleted the feature/macos-aarch64 branch March 15, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ARM builds
2 participants