use of com.google.devtools.build.lib.rules.cpp.FdoSupportProvider in project bazel by bazelbuild.
the class CrosstoolCompilationSupport method registerLinkActions.
@Override
CompilationSupport registerLinkActions(ObjcProvider objcProvider, J2ObjcMappingFileProvider j2ObjcMappingFileProvider, J2ObjcEntryClassProvider j2ObjcEntryClassProvider, ExtraLinkArgs extraLinkArgs, Iterable<Artifact> extraLinkInputs, DsymOutputType dsymOutputType) throws InterruptedException {
Iterable<Artifact> prunedJ2ObjcArchives = computeAndStripPrunedJ2ObjcArchives(j2ObjcEntryClassProvider, j2ObjcMappingFileProvider, objcProvider);
ImmutableList<Artifact> bazelBuiltLibraries = Iterables.isEmpty(prunedJ2ObjcArchives) ? objcProvider.getObjcLibraries() : substituteJ2ObjcPrunedLibraries(objcProvider);
Artifact inputFileList = intermediateArtifacts.linkerObjList();
ImmutableSet<Artifact> forceLinkArtifacts = getForceLoadArtifacts(objcProvider);
Iterable<Artifact> objFiles = Iterables.concat(bazelBuiltLibraries, objcProvider.get(IMPORTED_LIBRARY), objcProvider.getCcLibraries());
// Clang loads archives specified in filelists and also specified as -force_load twice,
// resulting in duplicate symbol errors unless they are deduped.
objFiles = Iterables.filter(objFiles, Predicates.not(Predicates.in(forceLinkArtifacts)));
registerObjFilelistAction(objFiles, inputFileList);
LinkTargetType linkType = (objcProvider.is(Flag.USES_CPP)) ? LinkTargetType.OBJCPP_EXECUTABLE : LinkTargetType.OBJC_EXECUTABLE;
ObjcVariablesExtension extension = new ObjcVariablesExtension.Builder().setRuleContext(ruleContext).setObjcProvider(objcProvider).setConfiguration(ruleContext.getConfiguration()).setIntermediateArtifacts(intermediateArtifacts).setFrameworkNames(frameworkNames(objcProvider)).setLibraryNames(libraryNames(objcProvider)).setForceLoadArtifacts(getForceLoadArtifacts(objcProvider)).setAttributeLinkopts(attributes.linkopts()).addVariableCategory(VariableCategory.EXECUTABLE_LINKING_VARIABLES).build();
Artifact binaryToLink = getBinaryToLink();
CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":cc_toolchain");
FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
CppLinkAction executableLinkAction = new CppLinkActionBuilder(ruleContext, binaryToLink, ccToolchain, fdoSupport).setMnemonic("ObjcLink").addActionInputs(bazelBuiltLibraries).addActionInputs(objcProvider.getCcLibraries()).addTransitiveActionInputs(objcProvider.get(IMPORTED_LIBRARY)).addTransitiveActionInputs(objcProvider.get(STATIC_FRAMEWORK_FILE)).addTransitiveActionInputs(objcProvider.get(DYNAMIC_FRAMEWORK_FILE)).setCrosstoolInputs(ccToolchain.getLink()).addActionInputs(prunedJ2ObjcArchives).addActionInput(inputFileList).setLinkType(linkType).setLinkStaticness(LinkStaticness.FULLY_STATIC).addLinkopts(ImmutableList.copyOf(extraLinkArgs)).addVariablesExtension(extension).setFeatureConfiguration(getFeatureConfiguration(ruleContext, buildConfiguration)).build();
ruleContext.registerAction(executableLinkAction);
if (objcConfiguration.shouldStripBinary()) {
registerBinaryStripAction(binaryToLink, StrippingType.DEFAULT);
}
return this;
}
use of com.google.devtools.build.lib.rules.cpp.FdoSupportProvider in project bazel by bazelbuild.
the class NativeDepsHelper method createNativeDepsAction.
public static NativeDepsRunfiles createNativeDepsAction(final RuleContext ruleContext, CcLinkParams linkParams, Collection<String> extraLinkOpts, BuildConfiguration configuration, CcToolchainProvider toolchain, Artifact nativeDeps, String libraryIdentifier, Root bindirIfShared, boolean useDynamicRuntime) throws InterruptedException {
Preconditions.checkState(ruleContext.isLegalFragment(CppConfiguration.class), "%s does not have access to CppConfiguration", ruleContext.getRule().getRuleClass());
List<String> linkopts = new ArrayList<>(extraLinkOpts);
linkopts.addAll(linkParams.flattenedLinkopts());
Map<Artifact, NestedSet<Artifact>> linkstamps = CppHelper.resolveLinkstamps(ruleContext, linkParams);
List<Artifact> buildInfoArtifacts = linkstamps.isEmpty() ? ImmutableList.<Artifact>of() : ruleContext.getAnalysisEnvironment().getBuildInfo(ruleContext, CppBuildInfo.KEY, configuration);
boolean shareNativeDeps = configuration.getFragment(CppConfiguration.class).shareNativeDeps();
NestedSet<LibraryToLink> linkerInputs = linkParams.getLibraries();
Artifact sharedLibrary;
if (shareNativeDeps) {
PathFragment sharedPath = getSharedNativeDepsPath(LinkerInputs.toLibraryArtifacts(linkerInputs), linkopts, linkstamps.keySet(), buildInfoArtifacts, ruleContext.getFeatures());
libraryIdentifier = sharedPath.getPathString();
sharedLibrary = ruleContext.getShareableArtifact(sharedPath.replaceName(sharedPath.getBaseName() + ".so"), configuration.getBinDirectory(ruleContext.getRule().getRepository()));
} else {
sharedLibrary = nativeDeps;
}
FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
CppLinkActionBuilder builder = new CppLinkActionBuilder(ruleContext, sharedLibrary, configuration, toolchain, fdoSupport);
if (useDynamicRuntime) {
builder.setRuntimeInputs(ArtifactCategory.DYNAMIC_LIBRARY, toolchain.getDynamicRuntimeLinkMiddleman(), toolchain.getDynamicRuntimeLinkInputs());
} else {
builder.setRuntimeInputs(ArtifactCategory.STATIC_LIBRARY, toolchain.getStaticRuntimeLinkMiddleman(), toolchain.getStaticRuntimeLinkInputs());
}
CppLinkAction linkAction = builder.setLinkArtifactFactory(SHAREABLE_LINK_ARTIFACT_FACTORY).setCrosstoolInputs(toolchain.getLink()).addLibraries(linkerInputs).setLinkType(LinkTargetType.DYNAMIC_LIBRARY).setLinkStaticness(LinkStaticness.MOSTLY_STATIC).setLibraryIdentifier(libraryIdentifier).addLinkopts(linkopts).setNativeDeps(true).addLinkstamps(linkstamps).build();
ruleContext.registerAction(linkAction);
Artifact linkerOutput = linkAction.getPrimaryOutput();
if (shareNativeDeps) {
// Collect dynamic-linker-resolvable symlinks for C++ runtime library dependencies.
// Note we only need these symlinks when --share_native_deps is on, as shared native deps
// mangle path names such that the library's conventional _solib RPATH entry
// no longer resolves (because the target directory's relative depth gets lost).
List<Artifact> runtimeSymlinks;
if (useDynamicRuntime) {
runtimeSymlinks = new LinkedList<>();
for (final Artifact runtimeInput : toolchain.getDynamicRuntimeLinkInputs()) {
final Artifact runtimeSymlink = ruleContext.getPackageRelativeArtifact(getRuntimeLibraryPath(ruleContext, runtimeInput), bindirIfShared);
// Since runtime library symlinks are underneath the target's output directory and
// multiple targets may share the same output directory, we need to make sure this
// symlink's generating action is only set once.
ruleContext.registerAction(new SymlinkAction(ruleContext.getActionOwner(), runtimeInput, runtimeSymlink, null));
runtimeSymlinks.add(runtimeSymlink);
}
} else {
runtimeSymlinks = ImmutableList.of();
}
ruleContext.registerAction(new SymlinkAction(ruleContext.getActionOwner(), linkerOutput, nativeDeps, null));
return new NativeDepsRunfiles(nativeDeps, runtimeSymlinks);
}
return new NativeDepsRunfiles(linkerOutput, ImmutableList.<Artifact>of());
}
use of com.google.devtools.build.lib.rules.cpp.FdoSupportProvider in project bazel by bazelbuild.
the class J2ObjcAspect method buildAspect.
private ConfiguredAspect buildAspect(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters, J2ObjcSource j2ObjcSource, J2ObjcMappingFileProvider directJ2ObjcMappingFileProvider, Iterable<Attribute> depAttributes) throws InterruptedException {
ConfiguredAspect.Builder builder = new ConfiguredAspect.Builder(this, parameters, ruleContext);
ObjcCommon common;
XcodeProvider xcodeProvider;
if (!Iterables.isEmpty(j2ObjcSource.getObjcSrcs())) {
common = common(ruleContext, j2ObjcSource.getObjcSrcs(), j2ObjcSource.getObjcHdrs(), j2ObjcSource.getHeaderSearchPaths(), depAttributes);
xcodeProvider = xcodeProvider(ruleContext, common, j2ObjcSource.getObjcHdrs(), j2ObjcSource.getHeaderSearchPaths(), depAttributes);
try {
CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":j2objc_cc_toolchain");
FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":j2objc_cc_toolchain");
CompilationSupport compilationSupport = CompilationSupport.createWithSelectedImplementation(ruleContext, ruleContext.getConfiguration(), ObjcRuleClasses.j2objcIntermediateArtifacts(ruleContext), CompilationAttributes.Builder.fromRuleContext(ruleContext).build());
compilationSupport.registerCompileAndArchiveActions(common.getCompilationArtifacts().get(), common.getObjcProvider(), EXTRA_COMPILE_ARGS, ImmutableList.<PathFragment>of(), ccToolchain, fdoSupport).registerFullyLinkAction(common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB), ccToolchain, fdoSupport);
} catch (RuleErrorException e) {
ruleContext.ruleError(e.getMessage());
}
} else {
common = common(ruleContext, ImmutableList.<Artifact>of(), ImmutableList.<Artifact>of(), ImmutableList.<PathFragment>of(), depAttributes);
xcodeProvider = xcodeProvider(ruleContext, common, ImmutableList.<Artifact>of(), ImmutableList.<PathFragment>of(), depAttributes);
}
return builder.addProvider(exportedJ2ObjcMappingFileProvider(base, ruleContext, directJ2ObjcMappingFileProvider)).addProvider(common.getObjcProvider()).addProvider(xcodeProvider).build();
}
Aggregations