Search in sources :

Example 1 with Platform

use of com.google.devtools.build.lib.rules.apple.Platform in project bazel by bazelbuild.

the class AppleCcToolchain method getBuildVariables.

@Override
protected Map<String, String> getBuildVariables(RuleContext ruleContext) throws RuleErrorException {
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    if (appleConfiguration.getXcodeVersion() == null) {
        ruleContext.throwWithRuleError("Xcode version must be specified to use an Apple CROSSTOOL");
    }
    Platform platform = appleConfiguration.getSingleArchPlatform();
    Map<String, String> appleEnv = getEnvironmentBuildVariables(ruleContext);
    return ImmutableMap.<String, String>builder().put(XCODE_VERSION_KEY, appleConfiguration.getXcodeVersion().toStringWithMinimumComponents(2)).put(IOS_SDK_VERSION_KEY, appleConfiguration.getSdkVersionForPlatform(Platform.IOS_SIMULATOR).toStringWithMinimumComponents(2)).put(MACOS_SDK_VERSION_KEY, appleConfiguration.getSdkVersionForPlatform(Platform.MACOS).toStringWithMinimumComponents(2)).put(TVOS_SDK_VERSION_KEY, appleConfiguration.getSdkVersionForPlatform(Platform.TVOS_SIMULATOR).toStringWithMinimumComponents(2)).put(WATCHOS_SDK_VERSION_KEY, appleConfiguration.getSdkVersionForPlatform(Platform.WATCHOS_SIMULATOR).toStringWithMinimumComponents(2)).put(SDK_DIR_KEY, AppleToolchain.sdkDir()).put(SDK_FRAMEWORK_DIR_KEY, AppleToolchain.sdkFrameworkDir(platform, appleConfiguration)).put(PLATFORM_DEVELOPER_FRAMEWORK_DIR, AppleToolchain.platformDeveloperFrameworkDir(appleConfiguration)).put(XCODE_VERISON_OVERRIDE_VALUE_KEY, appleEnv.getOrDefault(AppleConfiguration.XCODE_VERSION_ENV_NAME, "")).put(APPLE_SDK_VERSION_OVERRIDE_VALUE_KEY, appleEnv.getOrDefault(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME, "")).put(APPLE_SDK_PLATFORM_VALUE_KEY, appleEnv.getOrDefault(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, "")).put(VERSION_MIN_KEY, appleConfiguration.getMinimumOsForPlatformType(platform.getType()).toString()).build();
}
Also used : Platform(com.google.devtools.build.lib.rules.apple.Platform) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration)

Example 2 with Platform

use of com.google.devtools.build.lib.rules.apple.Platform in project bazel by bazelbuild.

the class LegacyCompilationSupport method registerCompileActionTemplate.

/**
   * Registers a SpawnActionTemplate to compile the source file tree artifact, {@code sourceFiles},
   * which can contain multiple concrete source files unknown at analysis time. At execution time,
   * the SpawnActionTemplate will register one ObjcCompile action for each individual source file
   * under {@code sourceFiles}.
   *
   * <p>Note that this method currently does not support code coverage and sources other than ObjC
   * sources.
   *
   * @param sourceFiles tree artifact containing source files to compile
   * @param objFiles tree artifact containing object files compiled from {@code sourceFiles}
   * @param objcProvider ObjcProvider instance for this invocation
   * @param priorityHeaders priority headers to be included before the dependency headers
   * @param moduleMap the module map generated from the associated headers
   * @param compilationArtifacts the CompilationArtifacts instance for this invocation
   * @param otherFlags extra compilation flags to add to the compile action command line
   */
private void registerCompileActionTemplate(Artifact sourceFiles, Artifact objFiles, ObjcProvider objcProvider, Iterable<PathFragment> priorityHeaders, Optional<CppModuleMap> moduleMap, CompilationArtifacts compilationArtifacts, Iterable<String> otherFlags) {
    CustomCommandLine commandLine = compileActionCommandLine(sourceFiles, objFiles, objcProvider, priorityHeaders, moduleMap, compilationArtifacts.getPchFile(), Optional.<Artifact>absent(), otherFlags, /* runCodeCoverage=*/
    false, /* isCPlusPlusSource=*/
    false);
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    Platform platform = appleConfiguration.getSingleArchPlatform();
    NestedSet<Artifact> moduleMapInputs = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
    if (objcConfiguration.moduleMapsEnabled()) {
        moduleMapInputs = objcProvider.get(MODULE_MAP);
    }
    ruleContext.registerAction(new SpawnActionTemplate.Builder(sourceFiles, objFiles).setMnemonics("ObjcCompileActionTemplate", "ObjcCompile").setExecutable(xcrunwrapper(ruleContext)).setCommandLineTemplate(commandLine).setEnvironment(ObjcRuleClasses.appleToolchainEnvironment(appleConfiguration, platform)).setExecutionInfo(ObjcRuleClasses.darwinActionExecutionRequirement()).setOutputPathMapper(COMPILE_ACTION_TEMPLATE_OUTPUT_PATH_MAPPER).addCommonTransitiveInputs(objcProvider.get(HEADER)).addCommonTransitiveInputs(moduleMapInputs).addCommonInputs(compilationArtifacts.getPrivateHdrs()).addCommonTransitiveInputs(objcProvider.get(STATIC_FRAMEWORK_FILE)).addCommonTransitiveInputs(objcProvider.get(DYNAMIC_FRAMEWORK_FILE)).addCommonInputs(compilationArtifacts.getPchFile().asSet()).build(ruleContext.getActionOwner()));
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) Platform(com.google.devtools.build.lib.rules.apple.Platform) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)

Example 3 with Platform

use of com.google.devtools.build.lib.rules.apple.Platform in project bazel by bazelbuild.

the class LegacyCompilationSupport method commonLinkAndCompileFlagsForClang.

/** Returns a list of clang flags used for all link and compile actions executed through clang. */
private List<String> commonLinkAndCompileFlagsForClang(ObjcProvider provider, ObjcConfiguration objcConfiguration, AppleConfiguration appleConfiguration) {
    ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
    Platform platform = appleConfiguration.getSingleArchPlatform();
    String minOSVersionArg;
    switch(platform) {
        case IOS_SIMULATOR:
            minOSVersionArg = "-mios-simulator-version-min";
            break;
        case IOS_DEVICE:
            minOSVersionArg = "-miphoneos-version-min";
            break;
        case WATCHOS_SIMULATOR:
            minOSVersionArg = "-mwatchos-simulator-version-min";
            break;
        case WATCHOS_DEVICE:
            minOSVersionArg = "-mwatchos-version-min";
            break;
        case TVOS_SIMULATOR:
            minOSVersionArg = "-mtvos-simulator-version-min";
            break;
        case TVOS_DEVICE:
            minOSVersionArg = "-mtvos-version-min";
            break;
        default:
            throw new IllegalArgumentException("Unhandled platform " + platform);
    }
    DottedVersion minOSVersion = appleConfiguration.getMinimumOsForPlatformType(platform.getType());
    builder.add(minOSVersionArg + "=" + minOSVersion);
    if (objcConfiguration.generateDsym()) {
        builder.add("-g");
    }
    return builder.add("-arch", appleConfiguration.getSingleArchitecture()).add("-isysroot", AppleToolchain.sdkDir()).addAll(commonFrameworkFlags(provider, appleConfiguration)).build();
}
Also used : DottedVersion(com.google.devtools.build.lib.rules.apple.DottedVersion) Platform(com.google.devtools.build.lib.rules.apple.Platform) ImmutableList(com.google.common.collect.ImmutableList) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)

Example 4 with Platform

use of com.google.devtools.build.lib.rules.apple.Platform in project bazel by bazelbuild.

the class AppleBinary method create.

@Override
public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    PlatformType platformType = MultiArchSplitTransitionProvider.getPlatformType(ruleContext);
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    Platform platform = appleConfiguration.getMultiArchPlatform(platformType);
    ImmutableListMultimap<BuildConfiguration, ObjcProvider> configurationToNonPropagatedObjcMap = ruleContext.getPrerequisitesByConfiguration("non_propagated_deps", Mode.SPLIT, ObjcProvider.class);
    ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap = ruleContext.getPrerequisitesByConfiguration("deps", Mode.SPLIT);
    Set<BuildConfiguration> childConfigurations = getChildConfigurations(ruleContext);
    Artifact outputArtifact = ObjcRuleClasses.intermediateArtifacts(ruleContext).combinedArchitectureBinary();
    MultiArchBinarySupport multiArchBinarySupport = new MultiArchBinarySupport(ruleContext);
    Map<BuildConfiguration, ObjcProvider> objcProviderByDepConfiguration = multiArchBinarySupport.objcProviderByDepConfiguration(childConfigurations, configToDepsCollectionMap, configurationToNonPropagatedObjcMap, getDylibProviders(ruleContext), getDylibProtoProviders(ruleContext));
    multiArchBinarySupport.registerActions(platform, getExtraLinkArgs(ruleContext), objcProviderByDepConfiguration, getExtraLinkInputs(ruleContext), configToDepsCollectionMap, outputArtifact);
    NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder().add(outputArtifact);
    RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build());
    ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder();
    for (ObjcProvider objcProvider : objcProviderByDepConfiguration.values()) {
        objcProviderBuilder.addTransitiveAndPropagate(objcProvider);
    }
    objcProviderBuilder.add(MULTI_ARCH_LINKED_BINARIES, outputArtifact);
    ObjcProvider objcProvider = objcProviderBuilder.build();
    // TODO(cparsons): Stop propagating ObjcProvider directly from this rule.
    targetBuilder.addProvider(ObjcProvider.class, objcProvider);
    switch(getBinaryType(ruleContext)) {
        case EXECUTABLE:
            targetBuilder.addNativeDeclaredProvider(new AppleExecutableBinaryProvider(outputArtifact, objcProvider));
            break;
        case DYLIB:
            targetBuilder.addNativeDeclaredProvider(new AppleDylibBinaryProvider(outputArtifact, objcProvider));
            break;
        case LOADABLE_BUNDLE:
            targetBuilder.addNativeDeclaredProvider(new AppleLoadableBundleBinaryProvider(outputArtifact));
            break;
    }
    AppleDebugOutputsProvider.Builder builder = AppleDebugOutputsProvider.Builder.create();
    for (BuildConfiguration childConfig : childConfigurations) {
        AppleConfiguration childAppleConfig = childConfig.getFragment(AppleConfiguration.class);
        ObjcConfiguration childObjcConfig = childConfig.getFragment(ObjcConfiguration.class);
        IntermediateArtifacts intermediateArtifacts = new IntermediateArtifacts(ruleContext, /*archiveFileNameSuffix*/
        "", /*outputPrefix*/
        "", childConfig);
        String arch = childAppleConfig.getSingleArchitecture();
        if (childAppleConfig.getBitcodeMode() == AppleBitcodeMode.EMBEDDED) {
            Artifact bitcodeSymbol = intermediateArtifacts.bitcodeSymbolMap();
            builder.addOutput(arch, OutputType.BITCODE_SYMBOLS, bitcodeSymbol);
        }
        if (childObjcConfig.generateDsym()) {
            Artifact dsymBinary = intermediateArtifacts.dsymSymbol(DsymOutputType.APP);
            builder.addOutput(arch, OutputType.DSYM_BINARY, dsymBinary);
        }
        if (childObjcConfig.generateLinkmap()) {
            Artifact linkmap = intermediateArtifacts.linkmap();
            builder.addOutput(arch, OutputType.LINKMAP, linkmap);
        }
    }
    targetBuilder.addNativeDeclaredProvider(builder.build());
    return targetBuilder.build();
}
Also used : Platform(com.google.devtools.build.lib.rules.apple.Platform) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) PlatformType(com.google.devtools.build.lib.rules.apple.Platform.PlatformType)

Example 5 with Platform

use of com.google.devtools.build.lib.rules.apple.Platform in project bazel by bazelbuild.

the class AppleWatch2Extension method validateAttributesAndConfiguration.

private void validateAttributesAndConfiguration(RuleContext ruleContext) throws RuleErrorException {
    boolean hasError = false;
    Multiset<Artifact> appResources = HashMultiset.create();
    appResources.addAll(ruleContext.getPrerequisiteArtifacts("app_resources", Mode.TARGET).list());
    appResources.addAll(ruleContext.getPrerequisiteArtifacts("app_strings", Mode.TARGET).list());
    for (Multiset.Entry<Artifact> entry : appResources.entrySet()) {
        if (entry.getCount() > 1) {
            ruleContext.ruleError("The same file was included multiple times in this rule: " + entry.getElement().getRootRelativePathString());
            hasError = true;
        }
    }
    Multiset<Artifact> extResources = HashMultiset.create();
    extResources.addAll(ruleContext.getPrerequisiteArtifacts("ext_resources", Mode.TARGET).list());
    extResources.addAll(ruleContext.getPrerequisiteArtifacts("ext_strings", Mode.TARGET).list());
    for (Multiset.Entry<Artifact> entry : extResources.entrySet()) {
        if (entry.getCount() > 1) {
            ruleContext.ruleError("The same file was included multiple times in this rule: " + entry.getElement().getRootRelativePathString());
            hasError = true;
        }
    }
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    Platform watchPlatform = appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS);
    Platform iosPlatform = appleConfiguration.getMultiArchPlatform(PlatformType.IOS);
    if (watchPlatform.isDevice() != iosPlatform.isDevice()) {
        hasError = true;
        if (watchPlatform.isDevice()) {
            ruleContext.ruleError(String.format("Building a watch extension for watch device architectures [%s] " + "requires a device ios architecture. Found [%s] instead.", Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.WATCHOS)), Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.IOS))));
        } else {
            ruleContext.ruleError(String.format("Building a watch extension for ios device architectures [%s] " + "requires a device watch architecture. Found [%s] instead.", Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.IOS)), Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.WATCHOS))));
        }
        ruleContext.ruleError("For building watch extension, there may only be a watch device " + "architecture if and only if there is an ios device architecture");
    }
    if (hasError) {
        throw new RuleErrorException();
    }
}
Also used : Platform(com.google.devtools.build.lib.rules.apple.Platform) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

Platform (com.google.devtools.build.lib.rules.apple.Platform)6 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)4 Artifact (com.google.devtools.build.lib.actions.Artifact)3 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)1 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)1 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 DottedVersion (com.google.devtools.build.lib.rules.apple.DottedVersion)1 PlatformType (com.google.devtools.build.lib.rules.apple.Platform.PlatformType)1