Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.3.0] Add changes to cc_shared_library from head to 6.3 #18606

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,8 @@ private boolean createDynamicLinkAction(
"-Wl,-soname="
+ SolibSymlinkAction.getDynamicLibrarySoname(
linkerOutput.getRootRelativePath(),
/* preserveName= */ false,
/* preserveName= */ dynamicLinkType
!= LinkTargetType.NODEPS_DYNAMIC_LIBRARY,
actionConstructionContext.getConfiguration().getMnemonic()));
}
}
Expand Down Expand Up @@ -841,6 +842,10 @@ private boolean createDynamicLinkAction(
if (dynamicLinkActionBuilder.getAllLtoBackendArtifacts() != null) {
ccLinkingOutputs.addAllLtoArtifacts(dynamicLinkActionBuilder.getAllLtoBackendArtifacts());
}
Artifact implLibraryLinkArtifact = getDynamicLibrarySolibSymlinkOutput(linkerOutput);
if (implLibraryLinkArtifact != null) {
dynamicLinkActionBuilder.setDynamicLibrarySolibSymlinkOutput(implLibraryLinkArtifact);
}
CppLinkAction dynamicLinkAction = dynamicLinkActionBuilder.build();
if (dynamicLinkType.isExecutable()) {
ccLinkingOutputs.setExecutable(linkerOutput);
Expand All @@ -866,14 +871,16 @@ private boolean createDynamicLinkAction(
}
libraryToLinkBuilder.setDynamicLibrary(dynamicLibrary.getArtifact());
} else {
Artifact implLibraryLinkArtifact =
SolibSymlinkAction.getDynamicLibrarySymlink(
/* actionRegistry= */ actionRegistry,
/* actionConstructionContext= */ actionConstructionContext,
ccToolchain.getSolibDirectory(),
dynamicLibrary.getArtifact(),
/* preserveName= */ false,
/* prefixConsumer= */ false);
if (dynamicLinkType == LinkTargetType.NODEPS_DYNAMIC_LIBRARY) {
implLibraryLinkArtifact =
SolibSymlinkAction.getDynamicLibrarySymlink(
/* actionRegistry= */ actionRegistry,
/* actionConstructionContext= */ actionConstructionContext,
ccToolchain.getSolibDirectory(),
dynamicLibrary.getArtifact(),
/* preserveName= */ false,
/* prefixConsumer= */ false);
}
libraryToLinkBuilder.setDynamicLibrary(implLibraryLinkArtifact);
libraryToLinkBuilder.setResolvedSymlinkDynamicLibrary(dynamicLibrary.getArtifact());

Expand All @@ -884,7 +891,8 @@ private boolean createDynamicLinkAction(
/* actionConstructionContext= */ actionConstructionContext,
ccToolchain.getSolibDirectory(),
interfaceLibrary.getArtifact(),
/* preserveName= */ false,
// Need to preserve name for transitive shared libraries that may be distributed.
/* preserveName= */ dynamicLinkType != LinkTargetType.NODEPS_DYNAMIC_LIBRARY,
/* prefixConsumer= */ false);
libraryToLinkBuilder.setInterfaceLibrary(libraryLinkArtifact);
libraryToLinkBuilder.setResolvedSymlinkInterfaceLibrary(interfaceLibrary.getArtifact());
Expand Down Expand Up @@ -1048,4 +1056,24 @@ private static List<LinkerInputs.LibraryToLink> convertLibraryToLinkListToLinker
}
return librariesToLinkBuilder.build();
}

@Nullable
private Artifact getDynamicLibrarySolibSymlinkOutput(Artifact linkerOutputArtifact) {
if (dynamicLinkType != LinkTargetType.DYNAMIC_LIBRARY
|| neverlink
|| featureConfiguration.isEnabled(CppRuleClasses.COPY_DYNAMIC_LIBRARIES_TO_BINARY)) {
return null;
}
return SolibSymlinkAction.getDynamicLibrarySymlink(
/* actionRegistry= */ actionRegistry,
/* actionConstructionContext= */ actionConstructionContext,
ccToolchain.getSolibDirectory(),
linkerOutputArtifact,
// For transitive shared libraries we want to preserve the name of the original library so
// that distribution artifacts can be linked against it and not against the mangled name.
// This makes it possible to find the library on the system if the RPATH has been set
// properly.
/* preserveName= */ true,
/* prefixConsumer= */ false);
}
}
121 changes: 121 additions & 0 deletions src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
import net.starlark.java.eval.StarlarkThread;
import net.starlark.java.eval.Structure;
import net.starlark.java.eval.Tuple;
import com.google.devtools.build.docgen.annot.DocCategory;
import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi;
import net.starlark.java.annot.Param;
import net.starlark.java.annot.ParamType;
import net.starlark.java.annot.StarlarkBuiltin;
import net.starlark.java.annot.StarlarkMethod;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.BuiltinProvider;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.docgen.annot.StarlarkConstructor;
import com.google.devtools.build.lib.starlarkbuildapi.core.StructApi;
import net.starlark.java.eval.Starlark;

/**
* A module that contains Starlark utilities for C++ support.
Expand Down Expand Up @@ -139,11 +151,120 @@ public abstract class CcModule

public abstract CppSemantics getSemantics(Language language);

/**
* This class exists only for a 6.3 cherrypick. For 7.0 this will be in Starlark.
*/
@StarlarkBuiltin(
name = "CcSharedLibraryHintInfo",
category = DocCategory.PROVIDER,
documented = false
)
@Immutable
private static final class CcSharedLibraryHintInfo extends NativeInfo implements StructApi {
private static final Provider PROVIDER = new Provider();

private final List<String> attributes;
private final List<Label> owners;

public CcSharedLibraryHintInfo(
List<String> attributes,
List<Label> owners) {
this.attributes = attributes;
this.owners = owners;
}

@StarlarkMethod(
name = "attributes",
structField = true,
allowReturnNones = true,
documented = false)
@Nullable
public Sequence<String> getAttributes() {
return attributes == null ? null : StarlarkList.immutableCopyOf(attributes);
}

@StarlarkMethod(
name = "owners",
structField = true,
allowReturnNones = true,
documented = false)
@Nullable
public Sequence<Label> getOwners() {
return owners == null ? null : StarlarkList.immutableCopyOf(owners);
}

@Override
public Provider getProvider() {
return PROVIDER;
}

public static class Provider extends BuiltinProvider<CcSharedLibraryHintInfo>
implements ProviderApi {
private Provider() {
super("CcSharedLibraryHintInfo", CcSharedLibraryHintInfo.class);
}
}
}

@StarlarkMethod(
name = "CcSharedLibraryHintInfo_6_X_constructor_do_not_use",
documented = false,
parameters = {
@Param(
name = "attributes",
documented = false,
positional = false,
named = true,
defaultValue = "None",
allowedTypes = {
@ParamType(type = Sequence.class),
@ParamType(type = NoneType.class)
}),
@Param(
name = "owners",
documented = false,
positional = false,
named = true,
defaultValue = "None",
allowedTypes = {
@ParamType(type = Sequence.class),
@ParamType(type = NoneType.class)
}),
}
)
public CcSharedLibraryHintInfo ccSharedLibraryHintInfoConstructor(
Object starlarkAttributesObject,
Object starlarkOwnersObject) throws EvalException {
List<String> attributes = null;
if (starlarkAttributesObject != Starlark.NONE) {
attributes = convertFromNoneable(
starlarkAttributesObject, /* defaultValue= */ (Sequence<String>) null).getImmutableList();
}
List<Label> owners = null;
if (starlarkOwnersObject != Starlark.NONE) {
owners = convertFromNoneable(
starlarkOwnersObject, /* defaultValue= */ (Sequence<Label>) null).getImmutableList();
}
return new CcSharedLibraryHintInfo(
attributes,
owners
);
}

@StarlarkMethod(
name = "CcSharedLibraryHintInfo_6_X_getter_do_not_use",
documented = false,
structField = true)
public Provider getCcSharedLibraryHintInfo() {
return CcSharedLibraryHintInfo.PROVIDER;
}

@Override
public Provider getCcToolchainProvider() {
return CcToolchainProvider.PROVIDER;
}


@Override
public FeatureConfigurationForStarlark configureFeatures(
Object ruleContextOrNone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public Artifact create(
private boolean isStampingEnabled;
private final Map<String, String> executionInfo = new LinkedHashMap<>();

// We have to add the dynamicLibrarySolibOutput to the CppLinkActionBuilder so that it knows how
// to set up the RPATH properly with respect to the symlink itself and not the original library.
private Artifact dynamicLibrarySolibSymlinkOutput;

/**
* Creates a builder that builds {@link CppLinkAction}s.
*
Expand Down Expand Up @@ -803,7 +807,8 @@ public CppLinkAction build() throws InterruptedException, RuleErrorException {
nonExpandedLinkerInputs,
needWholeArchive,
ruleErrorConsumer,
((RuleContext) actionConstructionContext).getWorkspaceName());
((RuleContext) actionConstructionContext).getWorkspaceName(),
dynamicLibrarySolibSymlinkOutput);
CollectedLibrariesToLink collectedLibrariesToLink =
librariesToLinkCollector.collectLibrariesToLink();

Expand Down Expand Up @@ -1536,4 +1541,11 @@ public CppLinkActionBuilder addExecutionInfo(Map<String, String> executionInfo)
this.executionInfo.putAll(executionInfo);
return this;
}

@CanIgnoreReturnValue
public CppLinkActionBuilder setDynamicLibrarySolibSymlinkOutput(
Artifact dynamicLibrarySolibSymlinkOutput) {
this.dynamicLibrarySolibSymlinkOutput = dynamicLibrarySolibSymlinkOutput;
return this;
}
}
Loading