use of com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions.AppleBitcodeMode in project bazel by bazelbuild.
the class LegacyCompilationSupport method linkCommandLine.
private CommandLine linkCommandLine(ExtraLinkArgs extraLinkArgs, ObjcProvider objcProvider, Artifact linkedBinary, Optional<Artifact> dsymBundleZip, Iterable<Artifact> ccLibraries, Iterable<Artifact> bazelBuiltLibraries, Optional<Artifact> linkmap, Optional<Artifact> bitcodeSymbolMap) {
Iterable<String> libraryNames = libraryNames(objcProvider);
CustomCommandLine.Builder commandLine = CustomCommandLine.builder().addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath());
if (objcProvider.is(USES_CPP)) {
commandLine.add(CLANG_PLUSPLUS).add("-stdlib=libc++").add("-std=gnu++11");
} else {
commandLine.add(CLANG);
}
// Do not perform code stripping on tests because XCTest binary is linked not as an executable
// but as a bundle without any entry point.
boolean isTestTarget = TargetUtils.isTestRule(ruleContext.getRule());
if (objcConfiguration.shouldStripBinary() && !isTestTarget) {
commandLine.add("-dead_strip").add("-no_dead_strip_inits_and_terms");
}
Iterable<Artifact> ccLibrariesToForceLoad = Iterables.filter(ccLibraries, ALWAYS_LINKED_CC_LIBRARY);
ImmutableSet<Artifact> forceLinkArtifacts = ImmutableSet.<Artifact>builder().addAll(objcProvider.get(FORCE_LOAD_LIBRARY)).addAll(ccLibrariesToForceLoad).build();
Artifact inputFileList = intermediateArtifacts.linkerObjList();
Iterable<Artifact> objFiles = Iterables.concat(bazelBuiltLibraries, objcProvider.get(IMPORTED_LIBRARY), ccLibraries);
// 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);
if (objcConfiguration.shouldPrioritizeStaticLibs()) {
commandLine.add("-filelist").add(inputFileList.getExecPathString());
}
AppleBitcodeMode bitcodeMode = appleConfiguration.getBitcodeMode();
commandLine.add(bitcodeMode.getCompileAndLinkFlags());
if (bitcodeMode == AppleBitcodeMode.EMBEDDED) {
commandLine.add("-Xlinker").add("-bitcode_verify");
commandLine.add("-Xlinker").add("-bitcode_hide_symbols");
commandLine.add("-Xlinker").add("-bitcode_symbol_map").add("-Xlinker").add(bitcodeSymbolMap.get().getExecPathString());
}
commandLine.add(commonLinkAndCompileFlagsForClang(objcProvider, objcConfiguration, appleConfiguration)).add("-Xlinker").add("-objc_abi_version").add("-Xlinker").add("2").add("-Xlinker").add("-rpath").add("-Xlinker").add("@executable_path/Frameworks").add("-fobjc-link-runtime").add(DEFAULT_LINKER_FLAGS).addBeforeEach("-framework", frameworkNames(objcProvider)).addBeforeEach("-weak_framework", SdkFramework.names(objcProvider.get(WEAK_SDK_FRAMEWORK))).addFormatEach("-l%s", libraryNames);
if (!objcConfiguration.shouldPrioritizeStaticLibs()) {
commandLine.add("-filelist").add(inputFileList.getExecPathString());
}
commandLine.addExecPath("-o", linkedBinary).addBeforeEachExecPath("-force_load", forceLinkArtifacts).add(extraLinkArgs).add(objcProvider.get(ObjcProvider.LINKOPT));
if (buildConfiguration.isCodeCoverageEnabled()) {
if (buildConfiguration.isLLVMCoverageMapFormatEnabled()) {
commandLine.add(LINKER_LLVM_COVERAGE_FLAGS);
} else {
commandLine.add(LINKER_COVERAGE_FLAGS);
}
}
for (String linkopt : attributes.linkopts()) {
commandLine.add("-Wl," + linkopt);
}
if (linkmap.isPresent()) {
commandLine.add("-Xlinker -map").add("-Xlinker " + linkmap.get().getExecPath());
}
// absolute paths to archive files, which are only valid in the link action.
if (dsymBundleZip.isPresent()) {
PathFragment dsymPath = FileSystemUtils.removeExtension(dsymBundleZip.get().getExecPath());
commandLine.add("&&").addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath()).add(DSYMUTIL).add(linkedBinary.getExecPathString()).add("-o " + dsymPath).add("&& zipped_bundle=${PWD}/" + dsymBundleZip.get().getShellEscapedExecPathString()).add("&& cd " + dsymPath).add("&& /usr/bin/zip -q -r \"${zipped_bundle}\" .");
}
return commandLine.build();
}
Aggregations