Skip to content

Commit 6345c80

Browse files
keithcopybara-github
authored andcommitted
Add --host_macos_minimum_os flag
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
1 parent 86409b7 commit 6345c80

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ public class AppleCommandLineOptions extends FragmentOptions {
163163
+ "If unspecified, uses 'macos_sdk_version'.")
164164
public DottedVersion.Option macosMinimumOs;
165165

166+
@Option(
167+
name = "host_macos_minimum_os",
168+
defaultValue = "null",
169+
converter = DottedVersionConverter.class,
170+
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
171+
effectTags = {OptionEffectTag.LOSES_INCREMENTAL_STATE},
172+
help =
173+
"Minimum compatible macOS version for host targets. "
174+
+ "If unspecified, uses 'macos_sdk_version'.")
175+
public DottedVersion.Option hostMacosMinimumOs;
176+
166177
@Option(
167178
name = "experimental_prefer_mutual_xcode",
168179
defaultValue = "true",
@@ -488,6 +499,7 @@ public FragmentOptions getHost() {
488499
host.watchOsSdkVersion = watchOsSdkVersion;
489500
host.tvOsSdkVersion = tvOsSdkVersion;
490501
host.macOsSdkVersion = macOsSdkVersion;
502+
host.macosMinimumOs = hostMacosMinimumOs;
491503
// The host apple platform type will always be MACOS, as no other apple platform type can
492504
// currently execute build actions. If that were the case, a host_apple_platform_type flag might
493505
// be needed.

src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBuildVariablesTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,45 @@ public void testAppleBuildVariablesMacos() throws Exception {
196196
.contains(dummyMinimumOsValue);
197197
}
198198

199+
@Test
200+
public void testAppleBuildVariablesMacosHost() throws Exception {
201+
MockObjcSupport.setup(mockToolsConfig);
202+
String dummyMinimumOsValue = "13.579";
203+
useConfiguration(
204+
"--crosstool_top=//tools/osx/crosstool",
205+
"--cpu=darwin_x86_64",
206+
"--host_cpu=darwin_x86_64",
207+
"--macos_minimum_os=10.11",
208+
"--host_macos_minimum_os=" + dummyMinimumOsValue);
209+
scratch.file(
210+
"x/BUILD",
211+
"apple_binary(",
212+
" name = 'bin',",
213+
" deps = [':a'],",
214+
" platform_type = 'macos',",
215+
")",
216+
"cc_library(",
217+
" name = 'a',",
218+
" srcs = ['a.cc'],",
219+
")");
220+
scratch.file("x/a.cc");
221+
222+
ConfiguredTarget target = getHostConfiguredTarget("//x:bin");
223+
Artifact lipoBin =
224+
getBinArtifact(
225+
Label.parseAbsolute("//x:bin", ImmutableMap.of()).getName() + "_lipobin", target);
226+
Action lipoAction = getGeneratingAction(lipoBin);
227+
Artifact bin = ActionsTestUtil.getFirstArtifactEndingWith(lipoAction.getInputs(), "_bin");
228+
CommandAction appleBinLinkAction = (CommandAction) getGeneratingAction(bin);
229+
Artifact archive =
230+
ActionsTestUtil.getFirstArtifactEndingWith(appleBinLinkAction.getInputs(), "liba.a");
231+
CppLinkAction ccArchiveAction = (CppLinkAction) getGeneratingAction(archive);
232+
233+
CcToolchainVariables variables = ccArchiveAction.getLinkCommandLine().getBuildVariables();
234+
assertThat(getVariableValue(getRuleContext(), variables, AppleCcToolchain.VERSION_MIN_KEY))
235+
.contains(dummyMinimumOsValue);
236+
}
237+
199238
@Test
200239
public void testDefaultBuildVariablesIos() throws Exception {
201240
MockObjcSupport.setup(mockToolsConfig);

0 commit comments

Comments
 (0)