Skip to content

Commit

Permalink
Add support to Swift Concurrency backport using swift-stdlib-tool (#69)
Browse files Browse the repository at this point in the history
* Add swift config  swift_stdlib_tool_run_on_subfolders to prevent to import libraries needed for 3rd party libs that supports iOS below 12
Add swift config swift_stdlib_tool_import_only_concurrency_lib to import only libswift_concurrency* libraries

* change from boolean type to Optional<Boolean> to match initializers

Co-authored-by: Lucas Marcal <[email protected]>
  • Loading branch information
Lcsmarcal and Lucas Marcal authored Jan 26, 2023
1 parent 77b7f81 commit 629551f
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 203 deletions.
15 changes: 7 additions & 8 deletions src/com/facebook/buck/apple/AppleBinaryDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,24 @@ public AppleBinaryDescription(
SwiftLibraryDescription swiftDelegate,
AppleConfig appleConfig,
CxxBuckConfig cxxBuckConfig,
SwiftBuckConfig swiftBuckConfig,
DownwardApiConfig downwardApiConfig,
CxxBinaryImplicitFlavors cxxBinaryImplicitFlavors,
CxxBinaryFactory cxxBinaryFactory,
CxxBinaryMetadataFactory cxxBinaryMetadataFactory,
CxxBinaryFlavored cxxBinaryFlavored) {
CxxBinaryFlavored cxxBinaryFlavored,
SwiftBuckConfig swiftBuckConfig) {
this.toolchainProvider = toolchainProvider;
this.xcodeDescriptions = xcodeDescriptions;
// TODO(T22135033): Make apple_binary not use a Swift delegate
this.swiftDelegate = Optional.of(swiftDelegate);
this.appleConfig = appleConfig;
this.cxxBuckConfig = cxxBuckConfig;
this.swiftBuckConfig = swiftBuckConfig;
this.downwardApiConfig = downwardApiConfig;
this.cxxBinaryImplicitFlavors = cxxBinaryImplicitFlavors;
this.cxxBinaryFactory = cxxBinaryFactory;
this.cxxBinaryMetadataFactory = cxxBinaryMetadataFactory;
this.cxxBinaryFlavored = cxxBinaryFlavored;
this.swiftBuckConfig = swiftBuckConfig;
}

@Override
Expand Down Expand Up @@ -422,13 +422,10 @@ private BuildRule createBundleBuildRule(
Optional.empty(),
Optional.empty(),
appleConfig.getCodesignTimeout(),
swiftBuckConfig.getCopyStdlibToFrameworks(),
swiftBuckConfig.getStdlibToolEnabled(),
Optional.empty(),
cxxBuckConfig.shouldCacheStrip(),
appleConfig.useEntitlementsWhenAdhocCodeSigning(),
Predicates.alwaysTrue(),
swiftBuckConfig.getSliceAppPackageSwiftRuntime(),
swiftBuckConfig.getSliceAppBundleSwiftRuntime(),
downwardApiConfig.isEnabledForApple(),
args.getTargetSdkVersion(),
appleConfig.getIncrementalBundlingEnabled(),
Expand All @@ -437,7 +434,9 @@ private BuildRule createBundleBuildRule(
appleConfig.getIncrementalHashCacheEnabled(),
false,
false,
Optional.empty());
Optional.empty(),
swiftBuckConfig.getSwiftStdlibToolRunOnSubfolders(),
swiftBuckConfig.getSwiftStdlibToolConcurrencyLibsOnly());
}

private BuildRule createBinary(
Expand Down
61 changes: 31 additions & 30 deletions src/com/facebook/buck/apple/AppleBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,11 @@ public class AppleBundle extends AbstractBuildRule

@AddToRuleKey private final Optional<Tool> swiftStdlibTool;

@AddToRuleKey private final Tool lipo;

@AddToRuleKey private final Optional<Tool> bitcodeStripTool;
@AddToRuleKey private final ImmutableList<String> codesignFlags;

@AddToRuleKey private final Optional<String> codesignIdentitySubjectName;

@AddToRuleKey private final boolean copySwiftStdlibToFrameworks;
@AddToRuleKey private final boolean swiftStdlibToolEnabled;

@AddToRuleKey private final boolean sliceAppPackageSwiftRuntime;
@AddToRuleKey private final boolean sliceAppBundleSwiftRuntime;

private final Path sdkPath;

private final BuildRule binary;
Expand Down Expand Up @@ -182,6 +175,12 @@ public class AppleBundle extends AbstractBuildRule

@AddToRuleKey private final boolean inputBasedRulekeyEnabled;

@AddToRuleKey private final Optional<Boolean> skipCopyingSwiftStdlib;

private final boolean swiftStdlibRunOnSubfolders;

private final boolean swiftStdlibConcurrencyLibsOnly;

AppleBundle(
BuildTarget buildTarget,
ProjectFilesystem projectFilesystem,
Expand All @@ -204,10 +203,7 @@ public class AppleBundle extends AbstractBuildRule
ImmutableList<String> codesignFlags,
Optional<String> codesignIdentity,
Duration codesignTimeout,
boolean copySwiftStdlibToFrameworks,
boolean swiftStdlibToolEnabled,
boolean sliceAppPackageSwiftRuntime,
boolean sliceAppBundleSwiftRuntime,
Optional<Boolean> skipCopyingSwiftStdlib,
boolean withDownwardApi,
Optional<SourcePath> maybeEntitlementsFile,
boolean dryRunCodeSigning,
Expand All @@ -216,7 +212,9 @@ public class AppleBundle extends AbstractBuildRule
Optional<SourcePath> nonProcessedResourcesContentHashesFileSourcePath,
Optional<SourcePath> processedResourcesContentHashesFileSourcePath,
boolean incrementalBundlingEnabled,
boolean inputBasedRulekeyEnabled) {
boolean inputBasedRulekeyEnabled,
boolean swiftStdlibRunOnSubfolders,
boolean swiftStdlibConcurrencyLibsOnly) {
super(buildTarget, projectFilesystem);
this.buildRuleParams = params;
this.extension = extension;
Expand Down Expand Up @@ -262,22 +260,22 @@ public class AppleBundle extends AbstractBuildRule
appleCxxPlatform.getSwiftPlatform().isPresent()
? appleCxxPlatform.getSwiftPlatform().get().getSwiftStdlibTool()
: Optional.empty();
this.lipo = appleCxxPlatform.getLipo();
this.bitcodeStripTool = appleCxxPlatform.getBitcodeStripTool();

this.skipCopyingSwiftStdlib = skipCopyingSwiftStdlib;
this.codesignTimeout = codesignTimeout;
this.copySwiftStdlibToFrameworks = copySwiftStdlibToFrameworks;
this.swiftStdlibToolEnabled = swiftStdlibToolEnabled;
this.depsSupplier = BuildableSupport.buildDepsSupplier(this, graphBuilder);

this.sliceAppPackageSwiftRuntime = sliceAppPackageSwiftRuntime;
this.sliceAppBundleSwiftRuntime = sliceAppBundleSwiftRuntime;
this.infoPlistBundlePath = bundleRoot.resolve(infoPlistPathRelativeToBundle.getPath());
this.nonProcessedResourcesContentHashesFileSourcePath =
nonProcessedResourcesContentHashesFileSourcePath;
this.processedResourcesContentHashesFileSourcePath =
processedResourcesContentHashesFileSourcePath;
this.incrementalBundlingEnabled = incrementalBundlingEnabled;
this.inputBasedRulekeyEnabled = inputBasedRulekeyEnabled;

this.swiftStdlibRunOnSubfolders = swiftStdlibRunOnSubfolders;
this.swiftStdlibConcurrencyLibsOnly = swiftStdlibConcurrencyLibsOnly;
}

public static String getBinaryName(BuildTarget buildTarget, Optional<String> productName) {
Expand Down Expand Up @@ -1086,10 +1084,9 @@ public void addSwiftStdlibStepIfNeeded(
boolean isForPackaging) {
// It's apparently safe to run this even on a non-swift bundle (in that case, no libs
// are copied over).
boolean shouldCopySwiftStdlib = swiftStdlibToolEnabled &&
(!extension.equals(AppleBundleExtension.APPEX.fileExtension) &&
(!extension.equals(AppleBundleExtension.FRAMEWORK.fileExtension) ||
copySwiftStdlibToFrameworks));
boolean shouldCopySwiftStdlib = !skipCopyingSwiftStdlib.orElse(false)
&& !extension.equals(AppleBundleExtension.APPEX.fileExtension)
&& !extension.equals(AppleBundleExtension.FRAMEWORK.fileExtension);

if (swiftStdlibTool.isPresent() && shouldCopySwiftStdlib) {
String tempDirPattern = isForPackaging ? "__swift_packaging_temp__%s" : "__swift_temp__%s";
Expand All @@ -1098,23 +1095,27 @@ public void addSwiftStdlibStepIfNeeded(

stepsBuilder.addAll(MakeCleanDirectoryStep.of(BuildCellRelativePath.of(tempPath)));

boolean sliceArchitectures =
(isForPackaging ? sliceAppPackageSwiftRuntime : sliceAppBundleSwiftRuntime);
ImmutableSet<Path> subfolderPaths = ImmutableSet.of();

if (swiftStdlibRunOnSubfolders) {
subfolderPaths = ImmutableSet.of(
bundleRoot.resolve(destinations.getFrameworksPath()),
bundleRoot.resolve(destinations.getPlugInsPath()));
}

stepsBuilder.add(
new SwiftStdlibStep(
getProjectFilesystem().getRootPath(),
tempPath.getPath(),
sdkPath,
destinationPath,
swiftStdlibTool.get().getCommandPrefix(resolver),
lipo.getCommandPrefix(resolver),
bundleBinaryPath,
ImmutableSet.of(
bundleRoot.resolve(destinations.getFrameworksPath()),
bundleRoot.resolve(destinations.getPlugInsPath())),
subfolderPaths,
codeSignIdentitySupplier,
sliceArchitectures,
withDownwardApi));
withDownwardApi,
bitcodeStripTool.get().getCommandPrefix(resolver),
swiftStdlibConcurrencyLibsOnly));
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/com/facebook/buck/apple/AppleBundleDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ public AppleBundleDescription(
AppleLibraryDescription appleLibraryDescription,
AppleConfig appleConfig,
CxxBuckConfig cxxBuckConfig,
SwiftBuckConfig swiftBuckConfig,
DownwardApiConfig downwardApiConfig) {
DownwardApiConfig downwardApiConfig,
SwiftBuckConfig swiftBuckConfig) {
this.toolchainProvider = toolchainProvider;
this.xcodeDescriptions = xcodeDescriptions;
this.appleBinaryDescription = appleBinaryDescription;
this.appleLibraryDescription = appleLibraryDescription;
this.appleConfig = appleConfig;
this.cxxBuckConfig = cxxBuckConfig;
this.swiftBuckConfig = swiftBuckConfig;
this.downwardApiConfig = downwardApiConfig;
this.swiftBuckConfig = swiftBuckConfig;
}

@Override
Expand Down Expand Up @@ -232,13 +232,10 @@ public AppleBundle createBuildRule(
args.getIbtoolModuleFlag(),
args.getIbtoolFlags(),
appleConfig.getCodesignTimeout(),
swiftBuckConfig.getCopyStdlibToFrameworks(),
swiftBuckConfig.getStdlibToolEnabled(),
args.getSkipCopyingSwiftStdlib(),
cxxBuckConfig.shouldCacheStrip(),
appleConfig.useEntitlementsWhenAdhocCodeSigning(),
resourceFilter,
swiftBuckConfig.getSliceAppPackageSwiftRuntime(),
swiftBuckConfig.getSliceAppBundleSwiftRuntime(),
downwardApiConfig.isEnabledForApple(),
minOSVersion,
appleConfig.getIncrementalBundlingEnabled(),
Expand All @@ -247,7 +244,9 @@ public AppleBundle createBuildRule(
appleConfig.getIncrementalHashCacheEnabled(),
false,
false,
Optional.empty());
Optional.empty(),
swiftBuckConfig.getSwiftStdlibToolRunOnSubfolders(),
swiftBuckConfig.getSwiftStdlibToolConcurrencyLibsOnly());
}

private static Optional<String> getMinimumOSVersionForBundle(
Expand Down
8 changes: 4 additions & 4 deletions src/com/facebook/buck/apple/AppleDescriptionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public Collection<Description<?>> getDescriptions(DescriptionCreationContext con
swiftLibraryDescription,
appleConfig,
cxxBuckConfig,
swiftBuckConfig,
downwardApiConfig,
cxxBinaryImplicitFlavors,
cxxBinaryFactory,
cxxBinaryMetadataFactory,
cxxBinaryFlavored);
cxxBinaryFlavored,
swiftBuckConfig);

return Arrays.asList(
new AppleAssetCatalogDescription(),
Expand All @@ -124,8 +124,8 @@ public Collection<Description<?>> getDescriptions(DescriptionCreationContext con
appleLibraryDescription,
appleConfig,
cxxBuckConfig,
swiftBuckConfig,
downwardApiConfig),
downwardApiConfig,
swiftBuckConfig),
new AppleTestDescription(
toolchainProvider,
xcodeDescriptions,
Expand Down
18 changes: 8 additions & 10 deletions src/com/facebook/buck/apple/AppleDescriptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -792,13 +792,10 @@ static AppleBundle createAppleBundle(
Optional<Boolean> ibtoolModuleFlag,
Optional<ImmutableList<String>> ibtoolFlags,
Duration codesignTimeout,
boolean copySwiftStdlibToFrameworks,
boolean swiftStdlibToolEnabled,
Optional<Boolean> skipCopyingSwiftStdlib,
boolean cacheStrips,
boolean useEntitlementsWhenAdhocCodeSigning,
Predicate<BuildTarget> filter,
boolean sliceAppPackageSwiftRuntime,
boolean sliceAppBundleSwiftRuntime,
boolean withDownwardApi,
Optional<String> minimumOSVersion,
boolean incrementalBundlingEnabled,
Expand All @@ -807,7 +804,9 @@ static AppleBundle createAppleBundle(
boolean shouldCacheFileHashes,
boolean shouldEmbedXctest,
boolean doNotEmbedHostAppInTestBundle,
Optional<AppleTestDescription.TestHostInfo> testHostInfo) {
Optional<AppleTestDescription.TestHostInfo> testHostInfo,
boolean swiftStdlibRunOnSubfolders,
boolean swiftStdlibConcurrencyLibsOnly) {
AppleCxxPlatform appleCxxPlatform =
ApplePlatforms.getAppleCxxPlatformForBuildTarget(
graphBuilder,
Expand Down Expand Up @@ -1412,10 +1411,7 @@ static AppleBundle createAppleBundle(
codesignFlags,
codesignAdhocIdentity,
codesignTimeout,
copySwiftStdlibToFrameworks,
swiftStdlibToolEnabled,
sliceAppPackageSwiftRuntime,
sliceAppBundleSwiftRuntime,
skipCopyingSwiftStdlib,
withDownwardApi,
entitlementsReadyForCodeSign,
dryRunCodeSigning,
Expand All @@ -1424,7 +1420,9 @@ static AppleBundle createAppleBundle(
nonProcessedResourcesContentHashesFileSourcePath,
processResources.getSourcePathToContentHashes(),
incrementalBundlingEnabled,
bundleInputBasedRulekeyEnabled);
bundleInputBasedRulekeyEnabled,
swiftStdlibRunOnSubfolders,
swiftStdlibConcurrencyLibsOnly);
}

private static Optional<SourcePath> entitlementsSourcePath(
Expand Down
9 changes: 4 additions & 5 deletions src/com/facebook/buck/apple/AppleLibraryDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,10 @@ private <A extends AbstractAppleLibraryDescriptionArg> BuildRule createFramework
Optional.empty(),
Optional.empty(),
appleConfig.getCodesignTimeout(),
swiftBuckConfig.getCopyStdlibToFrameworks(),
swiftBuckConfig.getStdlibToolEnabled(),
Optional.empty(),
cxxBuckConfig.shouldCacheStrip(),
appleConfig.useEntitlementsWhenAdhocCodeSigning(),
Predicates.alwaysTrue(),
swiftBuckConfig.getSliceAppPackageSwiftRuntime(),
swiftBuckConfig.getSliceAppBundleSwiftRuntime(),
downwardApiConfig.isEnabledForApple(),
args.getTargetSdkVersion(),
appleConfig.getIncrementalBundlingEnabled(),
Expand All @@ -560,7 +557,9 @@ private <A extends AbstractAppleLibraryDescriptionArg> BuildRule createFramework
appleConfig.getIncrementalHashCacheEnabled(),
false,
false,
Optional.empty());
Optional.empty(),
swiftBuckConfig.getSwiftStdlibToolRunOnSubfolders(),
swiftBuckConfig.getSwiftStdlibToolConcurrencyLibsOnly());
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/com/facebook/buck/apple/AppleTestDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,10 @@ public BuildRule createBuildRule(
Optional.empty(),
Optional.empty(),
appleConfig.getCodesignTimeout(),
swiftBuckConfig.getCopyStdlibToFrameworks(),
swiftBuckConfig.getStdlibToolEnabled(),
args.getSkipCopyingSwiftStdlib(),
cxxBuckConfig.shouldCacheStrip(),
appleConfig.useEntitlementsWhenAdhocCodeSigning(),
Predicates.alwaysTrue(),
swiftBuckConfig.getSliceAppPackageSwiftRuntime(),
swiftBuckConfig.getSliceAppBundleSwiftRuntime(),
downwardApiConfig.isEnabledForApple(),
args.getTargetSdkVersion(),
appleConfig.getIncrementalBundlingEnabled(),
Expand All @@ -412,7 +409,9 @@ public BuildRule createBuildRule(
appleConfig.getIncrementalHashCacheEnabled(),
appleConfig.getEmbedXctestInTestBundles(),
appleConfig.getDoNotEmbedHostAppInTestBundle(),
testHostWithTargetApp));
testHostWithTargetApp,
swiftBuckConfig.getSwiftStdlibToolRunOnSubfolders(),
swiftBuckConfig.getSwiftStdlibToolConcurrencyLibsOnly()));

Optional<SourcePath> xctool =
getXctool(projectFilesystem, params, targetConfiguration, graphBuilder);
Expand Down
3 changes: 3 additions & 0 deletions src/com/facebook/buck/apple/AppleToolchainDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ public BuildRule createBuildRule(
.setAppleSdkPaths(sdkPaths)
.setAppleSdk(sdk)
.setWatchKitStubBinary(args.getWatchKitStubBinary())
.setBitcodeStripTool(args.getBitcodeStripTool()
.map(path -> Tools.resolveTool(path, actionGraphBuilder)))
.build();

return new AppleToolchainBuildRule(
Expand Down Expand Up @@ -311,5 +313,6 @@ interface AbstractAppleToolchainDescriptionArg extends BuildRuleArg {

/** WatchKit stub binary (WK) */
Optional<SourcePath> getWatchKitStubBinary();
Optional<SourcePath> getBitcodeStripTool();
}
}
2 changes: 2 additions & 0 deletions src/com/facebook/buck/apple/HasAppleBundleFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public interface HasAppleBundleFields {

ImmutableMap<String, String> getInfoPlistSubstitutions();

Optional<Boolean> getSkipCopyingSwiftStdlib();

@Value.Default
default AppleAssetCatalogsCompilationOptions getAssetCatalogsCompilationOptions() {
return AppleAssetCatalogsCompilationOptions.builder().build();
Expand Down
Loading

0 comments on commit 629551f

Please sign in to comment.