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

Pass macOS version min flag in osx CROSSTOOL #6891

Closed
wants to merge 1 commit into from

Conversation

keith
Copy link
Member

@keith keith commented Dec 11, 2018

This fixes an issue where cc_library targets that are dependent on from
swift_binaries weren't passed the version min flag which lead to linker
warnings about version mismatches.

More details: bazelbuild/rules_swift#114

@jin jin added the z-team-Apple Deprecated. Send to rules_apple, or label team-Rules-CPP + platform:apple label Dec 11, 2018
@jin jin assigned jmmv and aragos Dec 11, 2018
@jin
Copy link
Member

jin commented Dec 11, 2018

@jmmv assigning to you since @aragos is OOO, feel free to reassign.

@jmmv jmmv requested a review from sergiocampama December 11, 2018 22:08
@jmmv
Copy link
Contributor

jmmv commented Dec 11, 2018

I think the Apple rules folks are better suited to review this. Assigned to them as reviewers.

@jin jin assigned sergiocampama and unassigned jmmv Dec 11, 2018
@keith
Copy link
Member Author

keith commented Dec 11, 2018

I'm investigating the failures, it looks like somehow the iOS SDK version is sneaking into the commands

@keith
Copy link
Member Author

keith commented Dec 11, 2018

Hmm actually. I think the problem is related to #6366

Since we're not passing --apple_platform_type for any of the tests, it's defaulting to iOS. Now the question is why it would be using these new crosstool arguments if that's the case

@trybka
Copy link
Contributor

trybka commented Dec 11, 2018

Perhaps the platform override specifying 'macos' is causing it to use the darwin CROSSTOOL stanza (and thus, your new flags) but the lack of apple_platform_type is passing the wrong version-min into the build var?

@keith
Copy link
Member Author

keith commented Dec 11, 2018

It must be. Without my patch the correct target is passed to one of these failing tests:

clang" "-cc1" "-triple" "x86_64-apple-macosx10.14.0" ...

But with this patch that triple and this new flag are broken:

clang" "-cc1" "-triple" "x86_64-apple-macosx12.1.0" ...

@keith
Copy link
Member Author

keith commented Dec 11, 2018

It turns out even with my change the isysroot / __BAZEL_XCODE_SDKROOT__ is still set correctly too 🤔

@trybka
Copy link
Contributor

trybka commented Dec 14, 2018

Can you modify the test configurations for things which run on darwin/macos to pass the correct --apple_platform_type, does that help?

@keith
Copy link
Member Author

keith commented Dec 14, 2018 via email

bazel-io pushed a commit that referenced this pull request Dec 14, 2018
For more info, please see #6891.

RELNOTES: None.
PiperOrigin-RevId: 225565277
@trybka
Copy link
Contributor

trybka commented Dec 17, 2018

Does it work now with bf04c53 submitted?

@keith keith force-pushed the ks/macos-version-min branch from 25ccda5 to 6cefcf6 Compare December 18, 2018 01:54
@keith
Copy link
Member Author

keith commented Dec 18, 2018

I've rebased on master so if someone could re-trigger the tests we can find out!

@keith
Copy link
Member Author

keith commented Dec 18, 2018

Looks like it's having the same issue. Which makes sense locally since that change only applied to CI

@keith
Copy link
Member Author

keith commented Dec 19, 2018

@sergiocampama any advice on the test side here?

@sergiocampama
Copy link
Contributor

these tests continue to fail because the tests themselves invoke bazel, and those invocations do not have the --apple_platform_type set.

@keith keith force-pushed the ks/macos-version-min branch from 6cefcf6 to b4e10f3 Compare January 3, 2019 21:21
@keith
Copy link
Member Author

keith commented Jan 3, 2019

Hmm so I actually think this is an existing bug that my change is surfacing. Without my commit if you build a tiny cc_binary:

cc_binary(
    name = "foo",
    srcs = ["foo.cc"],
)

with -s you see the command doesn't pass any platform specific flags:

external/local_config_cc/wrapped_clang '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++11' -iquote . -iquote bazel-out/darwin-fastbuild/genfiles -iquote bazel-out/darwin-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/darwin-fastbuild/genfiles/external/bazel_tools -iquote bazel-out/darwin-fastbuild/bin/external/bazel_tools -MD -MF bazel-out/darwin-fastbuild/bin/_objs/foo/foo.d '-frandom-seed=bazel-out/darwin-fastbuild/bin/_objs/foo/foo.o' -isysroot __BAZEL_XCODE_SDKROOT__ -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c foo.cc -o bazel-out/darwin-fastbuild/bin/_objs/foo/foo.o

I think this is already wrong because since --apple_platform_type defaults to iOS, it should be passing an iOS target at least? But instead it's allowing clang to pick a default. The final foo.o binary here isn't actually an iOS binary since clang picks macOS as the default:

% otool -l bazel-out/darwin-fastbuild/bin/foo | grep -C 2 platform
       cmd LC_BUILD_VERSION
   cmdsize 32
  platform macos
       sdk 10.14
     minos 10.14

Then with my change we actually start passing the version min flag, with the version based on apple_platform_type, but somehow it's pulling from the macOS portion of the crosstool, even though apple_platform_type is iOS, which correctly leads to the clang error.

@sergiocampama
Copy link
Contributor

The error stems from this line.

What happens is that the version is being set for the platform type, which by default is iOS. But the CROSSTOOL is setting up the flags for whatever CPU is set, which by default appears to be the host cpu, in this case being darwin_x86_64. This is the mismatch that makes the CROSSTOOL choose the macos flags, but the crosstool variables to choose the default platform type's version, which is iOS.

@keith
Copy link
Member Author

keith commented Jan 4, 2019

Trying to fix this by merging #6366 first instead

@keith keith force-pushed the ks/macos-version-min branch from b4e10f3 to 958efac Compare January 9, 2019 21:56
@keith
Copy link
Member Author

keith commented Jan 9, 2019

Now that the linked PR is merged I've rebased this one, which should mean our tests are green here. I have a local change to validate that apple_platform_type is the same as expected for cpu so we can catch the issue that blocked this earlier in the future, but that change currently depends on #7062

This fixes an issue where cc_library targets that are dependent on from
swift_binaries weren't passed the version min flag which lead to linker
warnings about version mismatches.
@keith keith force-pushed the ks/macos-version-min branch from 958efac to 1b9e840 Compare January 9, 2019 22:47
@keith
Copy link
Member Author

keith commented Jan 14, 2019

@trybka mind reviewing this now that everything's green?

@keith
Copy link
Member Author

keith commented Jan 22, 2019

@trybka friendly ping!

Copy link
Contributor

@trybka trybka left a comment

Choose a reason for hiding this comment

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

LGTM

@keith
Copy link
Member Author

keith commented Jan 24, 2019

Thanks! @trybka can you help me land this?

@keith
Copy link
Member Author

keith commented Jan 25, 2019

@trybka if you have a chance it would be great if we could land this for 0.23

@trybka
Copy link
Contributor

trybka commented Jan 27, 2019

@keith sorry for the delay, I'm not officially on the Bazel team, but they're helping me learn the process. I've sent it for review to land, and hope to get it imported on Monday.

@keith
Copy link
Member Author

keith commented Jan 27, 2019

Oh sorry I didn't know. Sounds great though thanks!

@bazel-io bazel-io closed this in fb8cad8 Jan 28, 2019
@keith keith deleted the ks/macos-version-min branch January 28, 2019 17:13
@keith
Copy link
Member Author

keith commented Jan 28, 2019

Thanks!

weixiao-huang pushed a commit to weixiao-huang/bazel that referenced this pull request Jan 31, 2019
This fixes an issue where cc_library targets that are dependent on from
swift_binaries weren't passed the version min flag which lead to linker
warnings about version mismatches.

More details: bazelbuild/rules_swift#114

Closes bazelbuild#6891.

PiperOrigin-RevId: 231229169
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes z-team-Apple Deprecated. Send to rules_apple, or label team-Rules-CPP + platform:apple
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants