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 default toolchains for MacOS. #20310

Merged
merged 4 commits into from
Sep 9, 2022
Merged

Conversation

prbprbprb
Copy link
Contributor

@prbprbprb prbprbprb commented Mar 29, 2022

Fixes gradle-native #1096

Adds two new default toolchain targets for MacOS x86_64 and
arm64 which use Clang's -arch argument to target the correct
architecture. On MacOS, this is used in preference to the
existing Intel64Architecture target which passes -m64 to the
toolchain.

This is sufficient for NativeExecutableSpec to target
osx_x86-64 and osx_aarch64 on both Intel and M1 Macs.

I haven't (yet!) located any tests for this functionality, and
so this PR doesn't include any test changes. Happy to add them
if you can point me in the right direction.

Signed-off-by: Pete Bentley [email protected]

Fixes gradle-native #1096

Context

Ease of use on both Intel and ARM based Macs.

Contributor Checklist

  • Review Contribution Guidelines
  • Make sure that all commits are signed off to indicate that you agree to the terms of Developer Certificate of Origin.
  • Make sure all contributed code can be distributed under the terms of the Apache License 2.0, e.g. the code was written by yourself or the original code is licensed under a license compatible to Apache License 2.0.
  • Check "Allow edit from maintainers" option in pull request so that additional changes can be pushed by Gradle team
  • Provide integration tests (under <subproject>/src/integTest) to verify changes from a user perspective
  • Provide unit tests (under <subproject>/src/test) to verify logic
  • Update User Guide, DSL Reference, and Javadoc for public-facing changes
  • Ensure that tests pass sanity check: ./gradlew sanityCheck
  • Ensure that tests pass locally: ./gradlew <changed-subproject>:quickTest

Gradle Core Team Checklist

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation
  • Recognize contributor in release notes

@prbprbprb
Copy link
Contributor Author

@big-guy possibly of interest to you as you recently fixed the arm-v8/aarch64 confusion in native builds?

@big-guy big-guy added the from:contributor PR by an external contributor label Apr 1, 2022
@ljacomet ljacomet added the in:native-platform c, cpp, swift and other native languages support, etc label Apr 8, 2022
@big-guy
Copy link
Member

big-guy commented Apr 20, 2022

Thanks @prbprbprb

We have an experimental M1-based pipeline I can run this through

@prbprbprb
Copy link
Contributor Author

Thanks! I kinda forgot about the docs changes, I'll get on that.

And do you have any pointer to where I should be adding tests?

@big-guy
Copy link
Member

big-guy commented Apr 20, 2022

@prbprbprb take a look at

I think making that also check for aarch64 would do it.

I think these are the only docs that need to be updated right now:
https://github.com/gradle/gradle/blob/34f6ad81c5f95c3da29eb7a6e273b00344d75b17/subprojects/docs/src/docs/userguide/native/native_software.adoc#using-tool-chains

I think there are more things we can do after this, but this is enough to get this merged.

Thanks!

@prbprbprb
Copy link
Contributor Author

Thanks, I'll work through that! One corner case I forgot - if there are versions of Xcode in the wild old enough not to support the -arch probe args we might need to fall back to -m64. I'll talk to some MacOS folk and see :)

Happy to take follow-on work too as we also want to support ARM Linux better in Conscrypt.

@big-guy big-guy added this to the 7.6 RC1 milestone Apr 22, 2022
@big-guy big-guy self-assigned this Apr 22, 2022
@DPUkyle
Copy link
Contributor

DPUkyle commented May 9, 2022

@prbprbprb we'd like to merge this PR in the next week or so; do you think you'll have time to contribute any tests or look at the corner-case for older Xcode versions?

@prbprbprb
Copy link
Contributor Author

I do apologise, kind of swamped with the day job recently. I will have time to look at this PR over the coming weekend but if it's easier for you take over the work in the meantime then you have my blessing.

@prbprbprb
Copy link
Contributor Author

Working on it but note that both the supplies args tests in AbstractGccCompatibleToolChainTest.groovy appear to be currently broken... I can randomly change the expectations in the where: clause and they still pass :)

@prbprbprb
Copy link
Contributor Author

Unit tests and docs updated. Do we need an integration test?

@prbprbprb
Copy link
Contributor Author

do you think you'll have time to [...] look at the corner-case for older Xcode versions?

Looks like the -arch flag has been around on MacOS since at least their PPC days, so I don't think we need to worry about it.

@@ -94,6 +94,8 @@ public AbstractGccCompatibleToolChain(String name, BuildOperationExecutor buildO

target(new Intel32Architecture());
target(new Intel64Architecture());
target(new OsxIntelArchitecture());
Copy link
Contributor

Choose a reason for hiding this comment

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

💄 It would be better if we could avoid duplicated architecture. It would be possible to choose different flags by using getPlatform() on the toolchain. The downside of merging Intel64Architecture and OsxIntelArchitecture is some tests may need to be adjusted which can be troublesome.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're suggesting three architectures, correct? And the probing for OS-dependent qualities will happen in their implementations?

  • Intel32Architecture
  • Intel64Architecture
  • Arm64Architecture

Copy link
Contributor

Choose a reason for hiding this comment

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

We could use Arm64Architecture, but I think for this PR using OsxArm64Architecture would be enough. Adding arm64 support for all OS is a big can of worm to open.

@big-guy big-guy removed their assignment Jul 1, 2022
@gradle gradle deleted a comment from DPUkyle Jul 13, 2022
bot-gradle added a commit that referenced this pull request Jul 13, 2022
While looking through #20310 , the author mentioned that some of the existing tests weren't working. Indeed, the implicit assertions buried within a closure were returning false but not failing the tests.

I checked with @leonard84 who shared the [modern way](https://spockframework.org/spock/docs/2.1/release_notes.html#_code_argument_constraints_are_treated_as_implicit_assertions) to check these conditions.

I've updated the test to use this method and confirm it now passes on CI. Note that I have changed the test conditions to make it pass, but I'm not sure whether this behavior is truly expected or not. As such, I'm open to suggestions/fixes to the production code as well.

Note I've seen some flakiness from `o.g.a.i.c.LibrariesSourceGeneratorTest.generated sources can be compiled` on java 8, but I don't see how it's related.

Co-authored-by: Kyle Moore <[email protected]>
@DPUkyle DPUkyle force-pushed the osx_toolchain branch 2 times, most recently from 87a0fca to b22ee22 Compare July 13, 2022 23:44
@DPUkyle DPUkyle force-pushed the osx_toolchain branch 2 times, most recently from 1d8c1db to 3230377 Compare July 14, 2022 00:01
@gradle gradle deleted a comment from DPUkyle Jul 14, 2022
@DPUkyle DPUkyle requested a review from big-guy July 14, 2022 01:04
@DPUkyle
Copy link
Contributor

DPUkyle commented Jul 14, 2022

@lacasseio can you have another look?

@gradle gradle deleted a comment from DPUkyle Jul 22, 2022
@big-guy big-guy changed the base branch from master to release August 9, 2022 21:43
Copy link
Contributor

@nathan-contino nathan-contino left a comment

Choose a reason for hiding this comment

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

LGTM

@big-guy big-guy added the @core Issue owned by GBT Core label Sep 7, 2022
prbprbprb and others added 4 commits September 9, 2022 08:53
Fixes gradle#1096

Adds two new default toolschain targets for MacOS x86_64 and
arm64 which use Clang's `-arch` argument to target the correct
architecture.  On MacOS, this is used in preference to the
existing `Intel64Architecture` target which passes `-m64` to the
toolchain.

This is sufficient for `NativeExecutableSpec` to target
`osx_x86-64` and `osx_aarch64` on both Intel and M1 Macs.

I haven't (yet!) located any tests for this functionality, and
so this PR doesn't include any test changes.  Happy to add them
if you can point me in the right direction.

Signed-off-by: Pete Bentley <[email protected]>
Notes:
Multi-arch support breaks some previous assumptions,
especially as dummyOS is an instance of the current OS and the
`TargetPlatformConfiguration`s (existing and added) also depend
on the current OS. I worked around it with `@IgnoreIf`s but there
ought to be a way to test all configs on all OSes.

Cherry-pick and merge changes from PR gradle#20882

Use @requires rather than inverted @IgnoreIf.

Also drop spurious blank line that crept in.

Signed-off-by: Pete Bentley <[email protected]>
Fixes gradle#1096

Adds two new default toolschain targets for MacOS x86_64 and
arm64 which use Clang's `-arch` argument to target the correct
architecture.  On MacOS, this is used in preference to the
existing `Intel64Architecture` target which passes `-m64` to the
toolchain.

This is sufficient for `NativeExecutableSpec` to target
`osx_x86-64` and `osx_aarch64` on both Intel and M1 Macs.

I haven't (yet!) located any tests for this functionality, and
so this PR doesn't include any test changes.  Happy to add them
if you can point me in the right direction.

Signed-off-by: Pete Bentley <[email protected]>
Signed-off-by: Kyle Moore <[email protected]>
@big-guy
Copy link
Member

big-guy commented Sep 9, 2022

@bot-gradle test this

@gradle gradle deleted a comment from DPUkyle Sep 9, 2022
@bot-gradle
Copy link
Collaborator

OK, I've already triggered the following builds for you:

@DPUkyle
Copy link
Contributor

DPUkyle commented Sep 9, 2022

@bot-gradle test and merge

@gradle gradle deleted a comment from big-guy Sep 9, 2022
@bot-gradle
Copy link
Collaborator

Your PR is queued. See the queue page for details.

@bot-gradle
Copy link
Collaborator

OK, I've already triggered a build for you.

@bot-gradle bot-gradle merged commit 23f07b6 into gradle:release Sep 9, 2022
DPUkyle added a commit that referenced this pull request Sep 10, 2022
bot-gradle added a commit that referenced this pull request Sep 10, 2022
Extension of #20310 , but enables native integration tests on M1.

The production code changes are mercifully small:
 - `MachineArchitecture.java` - defines a new AMD64 attribute
 - `GenerateXcodeProjectFileTask.java` - samples MachineArchitecture value to generate M1-compatible Xcode project
  - `default.xcsettings` - modify default Xcode project template to support "new build system" for future compatibility
  - `AbstractGccCompatibleToolChain.java` - Passes correct compiler flag when building on M1; from contributor in #20310

The remaining changes to tests and fixtures pass on my local environment, nevertheless I had to disable several tests due to the old Xcode versions present on our CI infrastructure.

Co-authored-by: Kyle Moore <[email protected]>
bot-gradle added a commit that referenced this pull request Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@core Issue owned by GBT Core from:contributor PR by an external contributor in:native-platform c, cpp, swift and other native languages support, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NativeExecutableSpec should have default toolchains which target MacOS Intel and ARM
7 participants