Skip to content

Conversation

@GregDomjan
Copy link
Member

As per discussion on #371
@syhily @mondain

@GregDomjan GregDomjan self-assigned this Sep 21, 2021
@marschall
Copy link
Contributor

I don't think this works.

  1. I think you need to replace aarch64.MacOSX.g++.* with aarch64.MacOSX.gpp.*
  2. I think you need to replace aarch64.MacOSX.g++.java.include=include with aarch64.MacOSX.gpp.java.include=include;include/darwin

@Demogorgon314
Copy link

Any progress?

@marschall
Copy link
Contributor

@Demogorgon314 I have a build running with these properties

https://github.com/marschall/exception-counter/blob/master/src/nar/apple.arm.aol.properties

@GregDomjan GregDomjan force-pushed the feature/I371-Apple-M1 branch from 898f108 to d7e6ba9 Compare August 13, 2022 03:01
@GregDomjan GregDomjan linked an issue Aug 13, 2022 that may be closed by this pull request
@GregDomjan
Copy link
Member Author

@Demogorgon314 @marschall Updated the original suggested config from @mondain based on feedback, linker name g++ is converted to gpp when used to lookup properties.

I still don't have a mac to test it, but seems to be logically more on target now.

@GregDomjan GregDomjan force-pushed the feature/I371-Apple-M1 branch from d7e6ba9 to 8e4d842 Compare January 6, 2023 05:06
@adamretter
Copy link

I would like to be able to produce a Universal Binary on macOS, see: https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary

I have an existing plugin configuration for building x86_64 on macOS x86_64 like this:

            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.10.2-SNAPSHOT</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <id>compile-native</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>nar-validate</goal>
                            <goal>nar-compile</goal>
                        </goals>
                        <configuration>
                            <java>
                                <include>true</include>
                                <link>false</link>
                            </java>
                            <libraries>
                                <library>
                                    <type>executable</type>
                                    <run>false</run>
                                    <linkCPP>false</linkCPP>
                                </library>
                            </libraries>
                            <c>
                                <clearDefaultOptions>true</clearDefaultOptions>
                                <options>
                                    <option>-arch</option>
                                    <option>x86_64</option>
                                    <option>-mmacosx-version-min=10.9</option>
                                    <option>-fobjc-exceptions</option>
                                    <option>-std=c99</option>
                                    <option>-DLIBJLI_DYLIB="${java.home}/jre/lib/jli/libjli.dylib"</option>
                                    <option>-c</option> <!-- NOTE: compile only, don't link at this stage! -->
                                </options>
                            </c>
                            <linker>
                                <options>
                                    <option>-framework</option>
                                    <option>Cocoa</option>
                                    <option>-mmacosx-version-min=10.9</option>
                                </options>
                            </linker>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I am guessing that I should be able to have two compilation executions, one for x86_64 and one for arm64, and then have an additional maven plugin that just calls the lipo tool to combine the two binaries.

Whilst it is easy to cross-compile for arm64 macOS on an x86_64 macOS machine, I can't seem to figure out how to do it using the nar-maven-plugin and this PR specifically. I have to first achieve this by changing these options:

<option>-arch</option>
<option>arm64</option>

However I get the following errors:

[INFO] --- nar-maven-plugin:3.10.2-SNAPSHOT:nar-validate (compile-native) @ appbundler ---
[INFO] Using AOL: x86_64-MacOSX-gpp
[INFO]
[INFO] --- nar-maven-plugin:3.10.2-SNAPSHOT:nar-compile (compile-native) @ appbundler ---
[INFO] Compiling 1 native files
[INFO] Warning: clang cannot dynamically link libgcc
[INFO] 1 total files to be compiled.
[INFO] Found 16 processors available
[INFO] Limited used processors to 1
[INFO]
Starting Core 0 with 1 source files...
[INFO] Linking...
[INFO] OUTPUT>ld: warning: ignoring file /Users/aretter/code/evolvedbinary/appbundler-maven-build/target/nar/obj/x86_64-MacOSX-gpp-executable/main.2193ccd9.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
[INFO] OUTPUT>Undefined symbols for architecture x86_64:
[INFO] OUTPUT>  "_main", referenced from:
[INFO] OUTPUT>     implicit entry/start for main executable
[INFO] OUTPUT>ld: symbol(s) not found for architecture x86_64
[ERROR] OUTPUT>clang: error: linker command failed with exit code 1 (use -v to see invocation)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

However running file shows that an arm64 binary is produced, i.e.:

$ file target/nar/obj/x86_64-MacOSX-gpp-executable/main.2193ccd9.o

target/nar/obj/x86_64-MacOSX-gpp-executable/main.2193ccd9.o: Mach-O 64-bit object arm64

Any ideas?

Copy link

@adamretter adamretter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes are needed in practice

aarch64.MacOSX.gpp.fortran.includes=**/*.f **/*.for
aarch64.MacOSX.gpp.fortran.excludes=

aarch64.MacOSX.gpp.java.include=include

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be include;include/darwin

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be **/*.f **/*.for **/*.f90

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be **/*.c **/*.m

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be **/*.cc **/*.cpp **/*.cxx **/*.mm

@GregDomjan GregDomjan force-pushed the feature/I371-Apple-M1 branch from 8e4d842 to 89eb856 Compare July 12, 2025 00:04
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

Successfully merging this pull request may close these issues.

Support Apple M1 chips.

5 participants