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

Include CPU in darwin platform string #7062

Closed
wants to merge 3 commits into from

Conversation

keith
Copy link
Member

@keith keith commented Jan 8, 2019

Bazel uses the CPU to determine the --apple_platform_type to build for
in some cases. Previously on a macOS machine the CPU would be returned
as just darwin, which isn't considered a valid macOS CPU, instead we
should return what we support and include the architecture.

@keith
Copy link
Member Author

keith commented Jan 8, 2019

cc @philwo since you were mentioned on the TODO

@keith
Copy link
Member Author

keith commented Jan 8, 2019

An alternative (or addition to this) could be to add darwin the the list of macOS CPUs here

private static final ImmutableSet<String> MACOS_TARGET_CPUS =
ImmutableSet.of("darwin_x86_64");
let me know if that would make sense to do too.

I could also do what is done for Windows and return unknown in this case, I don't know if bazel supports 32 bit macOS systems but I assume it does not.

default:
// We only support x64 Windows for now.
return "unknown";

@keith
Copy link
Member Author

keith commented Jan 9, 2019

It looks like some other stuff also assumes it's just darwin

if os_name.startswith("mac os"):
return "darwin"
which also appears to be causing the test failures. I'm leaning more towards adding darwin to MACOS_TARGET_CPUS but I'm still debugging the tests

@keith
Copy link
Member Author

keith commented Jan 9, 2019

I pushed a possible fix here, I'm not entirely sure this is the right option. Running this locally doesn't actually work but I believe it's because the tests invoke my globally installed bazel somehow, instead of the one that was just build, and therefore get the old local_config_cc

@iirina iirina added the z-team-Apple Deprecated. Send to rules_apple, or label team-Rules-CPP + platform:apple label Jan 14, 2019
@iirina iirina requested a review from aragos January 14, 2019 08:25
@aragos
Copy link
Contributor

aragos commented Jan 14, 2019

Some considerations: As you mention above I don't think there is more than a single macOS identifier, all the supported machines run on an x86 64bit darwin. The fact that two values exist for the same purpose has historical reasons (people didn't agree on what was the "correct" one). I don't think supporting both is the way to go though, updating everything to just use one version seems saner.

In any case, some tests appear to be failing on buildkite with your changes, please make sure that's green (go to "details" above, click on the failing pipeline (macOS JDK8), you can see the detailed test logs by going to that pipeline's "Artifacts" tab).

@keith
Copy link
Member Author

keith commented Jan 14, 2019 via email

Bazel uses the CPU to determine the --apple_platform_type to build for
in some cases. Previously on a macOS machine the CPU would be returned
as just `darwin`, which isn't considered a valid macOS CPU, instead we
should return what we support and include the architecture.
@keith
Copy link
Member Author

keith commented Jan 14, 2019

@trybka while working on this fix I'm hitting a new issue that @sergiocampama thinks you might be able to help with.

This test:

@Test
public void testCcLibraryWithDashStatic() throws Exception {
checkWarning(
"badlib",
"lib_with_dash_static",
// message:
"in linkopts attribute of cc_library rule //badlib:lib_with_dash_static: "
+ "Using '-static' here won't work. Did you mean to use 'linkstatic=1' instead?",
// build file:
"cc_library(name = 'lib_with_dash_static',",
" srcs = [ 'ok.cc' ],",
" linkopts = [ '-static' ])");
}

Fails on macOS with this change because of this conditional:

if (ApplePlatform.isApplePlatform(ccToolchain.getTargetCpu()) && result.contains("-static")) {
ruleContext.attributeError(
"linkopts", "Apple builds do not support statically linked binaries");
}

Before my change ApplePlatform.isApplePlatform("darwin") would return false, which seemed to have incorrectly made this test pass. Now that I'm fixing that by changing the CPU in this case to one that isApplePlatform returns true for, this test fails.

So I have 2 questions:

  1. Why can't apple platforms support static cc_library targets?
  2. If there's a un-fixable reason for 1, how should I fix this test?

@keith
Copy link
Member Author

keith commented Jan 14, 2019

@aragos I've updated this PR to only support darwin_x86_64 in case we have to support other architectures in the future. We'll see if there are any new test failures besides the ones mentioned above

@@ -284,7 +284,7 @@ def _is_linux(platform):
return platform == "k8"

def _is_darwin(platform):
return platform == "darwin"
return platform.startswith("darwin")
Copy link
Member Author

Choose a reason for hiding this comment

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

I might be able to change this to just darwin_x86_64, I'm not entirely sure, but also if we eventually have to support a new darwin, I assume this is what we'll want

@keith
Copy link
Member Author

keith commented Jan 14, 2019

It looks like the only failing test is the one I commented about above, so once we have a solution to that this should be green

@keith
Copy link
Member Author

keith commented Jan 14, 2019

I've pushed one possible solution for the test failure I asked about above 7c16844

This commit separates the failing test for darwin and validates that it errors with that message in this case, instead of having just the warning

@hlopko hlopko added the P2 We'll consider working on this in future. (Assignee optional) label Jan 16, 2019
@hlopko
Copy link
Member

hlopko commented Jan 16, 2019

I don't think we can accept this without going through incompatible flag. This can (and will) break existing code. Since we are planning to migrate C++ (and objc transitively) rules to platforms (https://www.bazel.build/roadmaps/cpp.html#c-rules-use-platforms-2019q1) I think the better course of action is to make https://source.bazel.build/bazel/+/5609d14ece35fc57084bb66161c7b579cd836c5e:tools/platforms/BUILD more robust, and force users to migrate only once. Wdyt?

@keith
Copy link
Member Author

keith commented Jan 16, 2019

What do you mean by making that platform configuration more robust?

@keith
Copy link
Member Author

keith commented Jan 16, 2019

Also I guess a non-breaking change we could make here instead would be to add darwin to the acceptable list of macOS apple platforms. This would fix the underlying issue and just not set us up for the future as much

@keith
Copy link
Member Author

keith commented Jan 17, 2019

I've submitted the darwin addition option here: #7151

@hlopko
Copy link
Member

hlopko commented Jan 18, 2019

By more robust I mean having enough constraint_values to express all reasonable cases. But I should first sync with @aragos because he has plans that involve --cpu and platforms and related universes...

@keith
Copy link
Member Author

keith commented Jan 18, 2019

Sounds good, I'm hoping we can merge the alternative fix here #7151 and then punt on this portion of it until it's a better time

bazel-io pushed a commit that referenced this pull request Jan 22, 2019
This is an alternative solution to #7062 that is more backwards compatible

Closes #7151.

PiperOrigin-RevId: 230388622
@keith
Copy link
Member Author

keith commented Jan 23, 2019

The other PR has landed, so the original core issue is fixed here. We can revisit this in the future

@keith keith closed this Jan 23, 2019
@aragos aragos added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed P2 We'll consider working on this in future. (Assignee optional) labels Jan 23, 2019
weixiao-huang pushed a commit to weixiao-huang/bazel that referenced this pull request Jan 31, 2019
This is an alternative solution to bazelbuild#7062 that is more backwards compatible

Closes bazelbuild#7151.

PiperOrigin-RevId: 230388622
@keith keith deleted the ks/darwin-cpu branch September 25, 2020 19:41
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this pull request Sep 4, 2022
    This is an alternative solution to bazelbuild/bazel#7062 that is more backwards compatible

    Closes #7151.

    PiperOrigin-RevId: 230388622
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes P3 We're not considering working on this, but happy to review a PR. (No assignee) 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.

5 participants