maven-nar / nar-maven-plugin

Native ARchive plugin for Maven
https://maven-nar.github.io/
Apache License 2.0
231 stars 159 forks source link

Support Apple M1 chips. #371

Open syhily opened 3 years ago

syhily commented 3 years ago

no linker is defined in the aol.properties file for 'aarch64.MacOSX.linker'

mondain commented 3 years ago

@syhily it's pretty simple to add other entries in the aol.properties file; I'm sure the maintainers would appreciate a patch / PR, if you or anyone else do the leg-work on this support.

mondain commented 3 years ago

@syhily I added this section to my aol.properties file for M1

#
# MacOSX ("Mac OS X" => MacOSX) Apple Silicon M1 (64 bits)
#
aarch64.MacOSX.linker=g++

aarch64.MacOSX.g++.cpp.compiler=g++
aarch64.MacOSX.g++.cpp.defines=Darwin GNU_GCC 
aarch64.MacOSX.g++.cpp.options=-Wall -Wno-long-long -Wpointer-arith -Wconversion
aarch64.MacOSX.g++.cpp.includes=**/*.cc **/*.cpp **/*.cxx
aarch64.MacOSX.g++.cpp.excludes=

aarch64.MacOSX.g++.c.compiler=gcc
aarch64.MacOSX.g++.c.defines=Darwin GNU_GCC 
aarch64.MacOSX.g++.c.options=-Wall -Wno-long-long -Wpointer-arith -Wconversion
aarch64.MacOSX.g++.c.includes=**/*.c
aarch64.MacOSX.g++.c.excludes=

aarch64.MacOSX.g++.fortran.compiler=gfortran
aarch64.MacOSX.g++.fortran.defines=Darwin GNU_GCC 
aarch64.MacOSX.g++.fortran.options=-Wall -fno-automatic -fno-second-underscore
aarch64.MacOSX.g++.fortran.includes=**/*.f **/*.for
aarch64.MacOSX.g++.fortran.excludes=

aarch64.MacOSX.g++.java.include=include
aarch64.MacOSX.g++.java.runtimeDirectory=IGNORED

aarch64.MacOSX.g++.lib.prefix=lib
aarch64.MacOSX.g++.shared.prefix=lib
aarch64.MacOSX.g++.static.extension=a
aarch64.MacOSX.g++.shared.extension=dylib
aarch64.MacOSX.g++.plugin.extension=bundle
aarch64.MacOSX.g++.jni.extension=jnilib
aarch64.MacOSX.g++.executable.extension=

To use a custom aol properties file, you have to set a property like this in your pom.xml:

<nar.aolProperties>${project.basedir}/aol.properties</nar.aolProperties>

Or pass it as -D${project.basedir}/aol.properties replace the project basedir with your path

mondain commented 3 years ago

Oddly, I just noticed this after I found my c++ / dylib didn't get compiled. Nothing that I do seems to get it to find my c++ source.

[INFO] --- nar-maven-plugin:3.10.1:nar-compile (default-nar-compile) @ red5pro-cauldron ---
[INFO] Nothing to compile

Ideas?

mondain commented 3 years ago

I ran with -X and I can see that it indeed knows my forced sourceDirectory

[DEBUG] Configuring mojo 'com.github.maven-nar:nar-maven-plugin:3.10.1:nar-compile' with basic configurator -->
[DEBUG]   (f) baseDir = /Users/mondain/Documents/GitHub/myproject
[DEBUG]   (f) classesDirectory = /Users/mondain/Documents/GitHub/myproject/target/classes
[DEBUG]   (f) sourceDirectory = /Users/mondain/Documents/GitHub/myproject/src/main/c++
[DEBUG]   (f) options = [-verbose, -fshow-source-location, -I/Users/mondain/Documents/GitHub/myproject/src/main/include/${nar.aol}]
[DEBUG]   (s) cpp = com.github.maven_nar.Cpp:

[DEBUG]   (f) directDepsOnly = false
[DEBUG]   (f) dryRun = false
[DEBUG]   (f) embedManifest = true
[DEBUG]   (f) failOnError = true
[DEBUG]   (f) ignore = false
[DEBUG]   (f) includesType = local
[DEBUG]   (f) layout = com.github.maven_nar.NarLayout21
[DEBUG]   (f) type = jni
[DEBUG]   (f) libraries = [Library: type: jni]
[DEBUG]   (f) libtool = true
[DEBUG]   (f) name = avformat
[DEBUG]   (f) type = shared
[DEBUG]   (f) directory = /Users/mondain/Documents/GitHub/myproject/src/main/lib/${nar.aol}
[DEBUG]   (f) name = swscale
[DEBUG]   (f) type = shared
[DEBUG]   (f) directory = /Users/mondain/Documents/GitHub/myproject/src/main/lib/${nar.aol}
[DEBUG]   (f) name = avcodec
[DEBUG]   (f) type = shared
[DEBUG]   (f) directory = /Users/mondain/Documents/GitHub/myproject/src/main/lib/${nar.aol}
[DEBUG]   (f) name = avutil
[DEBUG]   (f) type = shared
[DEBUG]   (f) directory = /Users/mondain/Documents/GitHub/myproject/src/main/lib/${nar.aol}
[DEBUG]   (f) name = avfilter
[DEBUG]   (f) type = shared
[DEBUG]   (f) directory = /Users/mondain/Documents/GitHub/myproject/src/main/lib/${nar.aol}
[DEBUG]   (f) name = swresample
[DEBUG]   (f) type = shared
[DEBUG]   (f) directory = /Users/mondain/Documents/GitHub/myproject/src/main/lib/${nar.aol}
[DEBUG]   (f) name = opus
[DEBUG]   (f) type = shared
[DEBUG]   (f) directory = /Users/mondain/Documents/GitHub/myproject/src/main/lib/${nar.aol}
[DEBUG]   (f) libs = [com.github.maven_nar.Lib@44f24a20, com.github.maven_nar.Lib@1859e2a4, com.github.maven_nar.Lib@46349b95, com.github.maven_nar.Lib@176996c3, com.github.maven_nar.Lib@411c6d44, com.github.maven_nar.Lib@1687eb01, com.github.maven_nar.Lib@748d2277]
[DEBUG]   (f) linker = com.github.maven_nar.Linker@2f897dab
[DEBUG]   (f) localRepository =       id: local
      url: file:///Users/mondain/.m2/repository/
   layout: default
snapshots: [enabled => true, update => always]
 releases: [enabled => true, update => always]
   blocked: false

[DEBUG]   (f) mavenProject = MavenProject: com.myproject:myproject:9.0.0 @ /Users/mondain/Documents/GitHub/myproject/pom.xml
[DEBUG]   (f) onlySpecifiedCompilers = false
[DEBUG]   (f) outputDirectory = /Users/mondain/Documents/GitHub/myproject/target
[DEBUG]   (f) projectRepos = [   excluded for privacy   ]
[DEBUG]   (f) remoteArtifactRepositories = [     excluded for privacy    ]
[DEBUG]   (f) repoSession = org.eclipse.aether.DefaultRepositorySystemSession@d5d5353
[DEBUG]   (f) runtime = dynamic
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@242b6e1a
[DEBUG]   (f) skip = false
[DEBUG]   (f) skipRanlib = false
[DEBUG]   (f) skipTests = true
[DEBUG]   (f) syslibsFromDependencies = false
[DEBUG] -- end configuration --
[DEBUG] linker original name not exist 
[DEBUG] aol_linker: g++
[DEBUG] Added to sourceDirectory: /Users/mondain/Documents/GitHub/myproject/src/main/c++
[DEBUG] Added to sourceDirectory: /Users/mondain/Documents/GitHub/myproject/src/main/java
[DEBUG] Added to sourceDirectory: /Users/mondain/Documents/GitHub/myproject/src/main
[DEBUG] Added to sourceDirectory: /Users/mondain/Documents/GitHub/myproject/src/main/java
[DEBUG] Added to sourceDirectory: /Users/mondain/Documents/GitHub/myproject/src/main
[DEBUG] Added to sourceDirectory: /Users/mondain/Documents/GitHub/myproject/src/main/java
[INFO] Nothing to compile
[DEBUG] Using com.github.maven_nar.NarLayout21
[DEBUG] Added to sourceDirectory: /Users/mondain/Documents/GitHub/myproject/src/main/c++
mondain commented 3 years ago

@syhily @GregDomjan So it seems there's quite a bit more to this whole Mac M1 thing; I've looked through all the relevant classes for doing the compilation in the nar-plugin, but nothing seems out of the ordinary and everything still works with my builds on a non-M1 Mac. It seems that clang takes over for gcc/g++ on the M1 and does not compile as expected and I'm not sure how to remedy that with the nar-plugin. What I have had to do is skip the nar-plugin for my native compile step and use g++ directly from a script and not the clang g++ configuration that is set up by Apple on the M1, but the brew version instead. That all being said, if we could configure the nar-plugin compile goal to use a different g++ install, it may work again for this work-around of Apple's bullshit. Ping me back if anyone else is interested in this stuff...

marschall commented 2 years ago

@mondain I had the same problem but could fix it by replacing g++ with gpp, in addition I had to add include/darwin. So for me with only C it looks like this:

aarch64.MacOSX.linker=g++

aarch64.MacOSX.gpp.c.compiler=gcc
aarch64.MacOSX.gpp.c.defines=Darwin GNU_GCC 
aarch64.MacOSX.gpp.c.options=-Wall -Wno-long-long -Wpointer-arith -Wconversion
aarch64.MacOSX.gpp.c.includes=**/*.c
aarch64.MacOSX.gpp.c.excludes=

aarch64.MacOSX.gpp.java.include=include;include/darwin
aarch64.MacOSX.gpp.java.runtimeDirectory=IGNORED

aarch64.MacOSX.gpp.lib.prefix=lib
aarch64.MacOSX.gpp.shared.prefix=lib
aarch64.MacOSX.gpp.static.extension=a
aarch64.MacOSX.gpp.shared.extension=dylib
aarch64.MacOSX.gpp.plugin.extension=bundle
aarch64.MacOSX.gpp.jni.extension=jnilib
aarch64.MacOSX.gpp.executable.extension=
avirlrma commented 2 years ago

Hi, I tried the method suggested by @mondain above, & passed the aol.properties file like this: -Dconf/aol.properties, but this doesn't seem to be picked up.

& the process till bails out with:

Caused by: java.lang.RuntimeException: Unhandled architecture/OS: aarch64-MacOSX
    at org.newsclub.net.unix.NarSystem.getAOLs(NarSystem.java:110)
    at org.newsclub.net.unix.NarSystem.loadLibrary(NarSystem.java:30)
    ... 44 more

Any ideas on this?