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

Add support for Apple M1 build #382

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

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?

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.
4 participants