Skip to content

Commit

Permalink
Add --host_macos_minimum_os flag
Browse files Browse the repository at this point in the history
This flag makes sure we set the minimum macOS version when compiling
host tools. Otherwise you can end up not sharing caches across
different OS versions.

Fixes #12988

Closes #13001.

PiperOrigin-RevId: 400859563
  • Loading branch information
keith authored and copybara-github committed Oct 5, 2021
1 parent 86409b7 commit 6345c80
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ public class AppleCommandLineOptions extends FragmentOptions {
+ "If unspecified, uses 'macos_sdk_version'.")
public DottedVersion.Option macosMinimumOs;

@Option(
name = "host_macos_minimum_os",
defaultValue = "null",
converter = DottedVersionConverter.class,
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.LOSES_INCREMENTAL_STATE},
help =
"Minimum compatible macOS version for host targets. "
+ "If unspecified, uses 'macos_sdk_version'.")
public DottedVersion.Option hostMacosMinimumOs;

@Option(
name = "experimental_prefer_mutual_xcode",
defaultValue = "true",
Expand Down Expand Up @@ -488,6 +499,7 @@ public FragmentOptions getHost() {
host.watchOsSdkVersion = watchOsSdkVersion;
host.tvOsSdkVersion = tvOsSdkVersion;
host.macOsSdkVersion = macOsSdkVersion;
host.macosMinimumOs = hostMacosMinimumOs;
// The host apple platform type will always be MACOS, as no other apple platform type can
// currently execute build actions. If that were the case, a host_apple_platform_type flag might
// be needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,45 @@ public void testAppleBuildVariablesMacos() throws Exception {
.contains(dummyMinimumOsValue);
}

@Test
public void testAppleBuildVariablesMacosHost() throws Exception {
MockObjcSupport.setup(mockToolsConfig);
String dummyMinimumOsValue = "13.579";
useConfiguration(
"--crosstool_top=//tools/osx/crosstool",
"--cpu=darwin_x86_64",
"--host_cpu=darwin_x86_64",
"--macos_minimum_os=10.11",
"--host_macos_minimum_os=" + dummyMinimumOsValue);
scratch.file(
"x/BUILD",
"apple_binary(",
" name = 'bin',",
" deps = [':a'],",
" platform_type = 'macos',",
")",
"cc_library(",
" name = 'a',",
" srcs = ['a.cc'],",
")");
scratch.file("x/a.cc");

ConfiguredTarget target = getHostConfiguredTarget("//x:bin");
Artifact lipoBin =
getBinArtifact(
Label.parseAbsolute("//x:bin", ImmutableMap.of()).getName() + "_lipobin", target);
Action lipoAction = getGeneratingAction(lipoBin);
Artifact bin = ActionsTestUtil.getFirstArtifactEndingWith(lipoAction.getInputs(), "_bin");
CommandAction appleBinLinkAction = (CommandAction) getGeneratingAction(bin);
Artifact archive =
ActionsTestUtil.getFirstArtifactEndingWith(appleBinLinkAction.getInputs(), "liba.a");
CppLinkAction ccArchiveAction = (CppLinkAction) getGeneratingAction(archive);

CcToolchainVariables variables = ccArchiveAction.getLinkCommandLine().getBuildVariables();
assertThat(getVariableValue(getRuleContext(), variables, AppleCcToolchain.VERSION_MIN_KEY))
.contains(dummyMinimumOsValue);
}

@Test
public void testDefaultBuildVariablesIos() throws Exception {
MockObjcSupport.setup(mockToolsConfig);
Expand Down

0 comments on commit 6345c80

Please sign in to comment.