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

macosx-arm64 support #3

Open
phronmophobic opened this issue Aug 8, 2024 · 10 comments
Open

macosx-arm64 support #3

phronmophobic opened this issue Aug 8, 2024 · 10 comments

Comments

@phronmophobic
Copy link

I've recently been playing with a wrapper for webgpu and the clj-manifold3d project seems like a natural complement for generating meshes. I was able to get it to work by compiling manifold locally, but it would be great have native jars for arm64.

I started work on updating the github workflow to work on mac osx, but I did run into some complications, https://github.com/phronmophobic/manifold.

  • The workflow build uses homebrew and requires users of the jar to also use homebrew. The install name and linked dependencies of the shared libraries are hardcoded to homebrew paths and in some cases, paths to the home directory of the workflow runner.
  • I was able to make the install name and rpath changes, but there's still some work getting the libraries that are shipped via javacpp to find the libraries that aren't shipped with javacpp (ie. libassimp and libpng).

I'm not sure how interested you would be in a pull request that fixes these issues, but I could send a cleaned up patch once I get it working if you are. Thanks for the library!

webgpu

@cartesian-theatrics
Copy link
Contributor

Hello,

Thanks for reporting this. I have not been tracking issues here.

I do not have a Mac so it's hard for me to validate the Mac build. If you have a fix I'd love to see it! We might want to just ship libassimp and libpng in the jar.

@phronmophobic
Copy link
Author

It's been a few months since I've looked at this. I wasn't able to get the build to run in github's CI, but I don't quite remember what steps are remaining. I'll have to look into it again once I get some free time.

I have not been tracking issues here.

Is there a more convenient place to discuss the project? clj-manifold3d is a really neat project and would be a great complement to clj-webgpu that I've been playing with.

@cartesian-theatrics
Copy link
Contributor

The new release (1.1.1) removed the need for libassimp and other shared object deps. Hopefully the osx support is better now. idk much about what would be required to compile for arm64.

@phronmophobic
Copy link
Author

Very cool! Thanks! I'll try and see if I can make a github CI build working next week.

@phronmophobic
Copy link
Author

@cartesian-theatrics, Ok, so I was able to build the latest locally. Several classes and field names changed, but after working through those issues it seemed to work ok locally.

I tried building the library using github CI, but the shared libraries still aren't portable to non build machines. The install names for libfreetype, libassimp, and libpng are still hard coded to absolute paths.

I think the following bash commands should fix the paths:

install_name_tool -id '@rpath/libfreetype.6.16.0.dylib' libfreetype.6.16.0.dylib
install_name_tool -change /opt/homebrew/opt/libpng/lib/libpng16.16.dylib '@rpath/libpng16.16.dylib' libfreetype.6.16.0.dylib
install_name_tool -change /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.0.dylib '@rpath/libharfbuzz.0.dylib' libfreetype.6.16.0.dylib

install_name_tool -change /opt/homebrew/opt/assimp/lib/libassimp.5.dylib '@rpath/libassimp.5.dylib' libmeshIO.dylib
install_name_tool -change /Users/runner/work/manifold/manifold/build/_deps/freetype2-build/libfreetype.6.dylib '@rpath/libfreetype.6.dylib' libmeshIO.dylib

However, I'm not really sure how to run these commands inside the build process. One option might be to add a build step to bindings/java/pom.xml to execute these commands via a plugin before the package step. chatgpt recommended exec-maven-plugin, but I'm sure if that's something that sounds reasonable to you and didn't want to go down that rabbit hole if you weren't interested in that approach.

@cartesian-theatrics
Copy link
Contributor

Thanks for diving into this! I'm busy for the next couple days, but I'll try to get an MR up soon against the java bindings repo where we can debug this. We can add stages to inspect build artifacts and hopefully go from there.

@phronmophobic
Copy link
Author

I decided to try a few more things. The above is not quite right, but with a few tweaks, I was able to set the rpath. However, setting the rpath doesn't seem to help much. In the past, that has been useful for other libraries 3rd party libraries that might be in other jars, but it doesn't seem to help for libraries that are expected to provided on the system path.

I've been googling, but haven't found any way around this other than one of the following:

  • compiling dependencies as static libraries to include inside of libmanifold
  • creating jars with libassimp and other dependencies to extract into the same folder as libmanifold
  • including libassimp and other dependencies inside the libmanifold jar.

@phronmophobic
Copy link
Author

Another option that seems to work is to update the dependent paths in libmanifold to use macport compatible paths. The downside of this approach is that there would be separate dependencies for homebrew and macports and that these jars would conflict with each other if both are included on the same classpath.

@lynaghk
Copy link

lynaghk commented Jan 19, 2025

Hi y'all, I'm late to the party but also trying to build and run this on an M1 Mac. @cartesian-theatrics What's the intended way to build your fork? I didn't see much in the README and wasn't sure if the next stuff in the repo is necessary or not. (I know nothing about Nix.)

FWIW in case anyone else comes along, here's what worked for me on SovereignShop/manifold@bb3d3e4:

sudo port install assimp minizip
export LIBRARY_PATH=/opt/local/lib:$LIBRARY_PATH

git clone https://github.com/SovereignShop/manifold manifold-jni
cd manifold-jni
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMANIFOLD_DEBUG=ON -DMANIFOLD_EXPORT=ON .. && make -j
cd ../bindings/java
mvn versions:set -DnewVersion=0.0.1 --file pom.xml
mvn package -Dos.classifier=mac-arm

Then I was able to fire up a REPL with this deps.edn:

{:paths ["src/"]
 :deps {org.clojure/clojure {:mvn/version "1.12.0"}
        org.clojure/core.match {:mvn/version "1.0.1"}
        org.clojars.cartesiantheatrics/clj-manifold3d {:mvn/version "1.1.1"}
        org.clojars.cartesiantheatrics/manifold3d$mac-arm {:local/root "/Users/dev/software/manifold-jni/bindings/java/target/manifold3d-0.0.1-mac-arm.jar"}}

 :aliases {:dev {:extra-paths ["dev/" "test/"]}}}

And the full build log.txt

@phronmophobic
Copy link
Author

@lynaghk That's essentially the same steps I used. The only thing I would add is that I believe you also need libpng installed, which you might have already installed previously.

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

3 participants