diff options
author | plf <plf@google.com> | 2018-07-02 06:50:30 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-02 06:51:54 -0700 |
commit | 95a40bea2d0488ba3afc803b9082b16cadef1deb (patch) | |
tree | e3c00515980ebb47d368aa67bed791125c5972de /src/main/java/com/google/devtools/build/lib/skylarkbuildapi | |
parent | c7a01554d0fa01aab41577e241ae262fdda45d95 (diff) |
C++: Exposes C++ Skylark providers to Bazel
RELNOTES:none
PiperOrigin-RevId: 202943806
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skylarkbuildapi')
4 files changed, 222 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java index 73c5e498a8..f1e3a65c85 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java @@ -14,8 +14,10 @@ package com.google.devtools.build.lib.skylarkbuildapi.cpp; - +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.skylark.SkylarkRuleContext; import com.google.devtools.build.lib.skylarkbuildapi.ProviderApi; +import com.google.devtools.build.lib.skylarkbuildapi.SkylarkRuleContextApi; import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.ParamType; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; @@ -33,7 +35,10 @@ import com.google.devtools.build.lib.syntax.SkylarkNestedSet; public interface CcModuleApi< CcToolchainProviderT extends CcToolchainProviderApi, FeatureConfigurationT extends FeatureConfigurationApi, - CcToolchainVariablesT extends CcToolchainVariablesApi> { + CcToolchainVariablesT extends CcToolchainVariablesApi, + LibraryToLinkT extends LibraryToLinkApi, + CcLinkParamsT extends CcLinkParamsApi, + CcSkylarkInfoT extends CcSkylarkInfoApi> { @SkylarkCallable( name = "CcToolchainInfo", @@ -450,4 +455,135 @@ public interface CcModuleApi< @SkylarkCallable(name = "empty_variables", documented = false) CcToolchainVariablesT getVariables(); + + @SkylarkCallable( + name = "create_library_to_link", + documented = false, + parameters = { + @Param( + name = "ctx", + doc = "Skylark rule context.", + positional = false, + named = true, + type = SkylarkRuleContext.class), + @Param( + name = "library", + doc = "Library to be linked.", + positional = false, + named = true, + type = Artifact.class), + @Param( + name = "artifact_category", + doc = + "Artifact category. Can be: static_library, alwayslink_static_library, " + + "dynamic_library or interface_library", + positional = false, + named = true, + type = String.class) + }) + LibraryToLinkT createLibraryLinkerInput( + SkylarkRuleContext skylarkRuleContext, Artifact library, String skylarkArtifactCategory) + throws EvalException; + + @SkylarkCallable( + name = "create_symlink_library_to_link", + documented = false, + parameters = { + @Param( + name = "ctx", + doc = "Skylark rule context.", + positional = false, + named = true, + type = SkylarkRuleContext.class), + @Param( + name = "cc_toolchain", + doc = "C++ toolchain provider to be used.", + positional = false, + named = true, + type = CcToolchainProviderApi.class), + @Param( + name = "library", + doc = "Library that should be symlinked.", + positional = false, + named = true, + type = Artifact.class), + }) + LibraryToLinkT createSymlinkLibraryLinkerInput( + SkylarkRuleContext skylarkRuleContext, CcToolchainProviderT ccToolchain, Artifact library); + + @SkylarkCallable( + name = "create_cc_link_params", + doc = "Creates cc link parameters", + parameters = { + @Param( + name = "ctx", + positional = false, + named = true, + type = SkylarkRuleContextApi.class, + doc = "The rule context."), + @Param( + name = "libraries_to_link", + doc = + "List of libraries that should be passed to the linker/archiver. They can be " + + "static and/or dynamic libraries.", + positional = false, + named = true, + noneable = true, + defaultValue = "None", + allowedTypes = { + @ParamType(type = SkylarkNestedSet.class), + @ParamType(type = NoneType.class) + }), + @Param( + name = "dynamic_libraries_for_runtime", + doc = + "When 'libraries_to_link' has dynamic libraries, then the runtime library can " + + "be specified as well. This is not obligatory though, as we may provide a " + + "library for linking and at runtime the actual library will be provided by " + + "the system.", + positional = false, + named = true, + noneable = true, + defaultValue = "None", + allowedTypes = { + @ParamType(type = SkylarkNestedSet.class), + @ParamType(type = NoneType.class) + }), + @Param( + name = "user_link_flags", + doc = "List of user provided linker flags.", + positional = false, + named = true, + noneable = true, + defaultValue = "None", + allowedTypes = { + @ParamType(type = SkylarkNestedSet.class), + @ParamType(type = NoneType.class) + }) + }) + CcLinkParamsT createCcLinkParams( + SkylarkRuleContext skylarkRuleContext, + Object skylarkLibrariesToLink, + Object skylarkDynamicLibrariesForRuntime, + Object skylarkUserLinkFlags) + throws EvalException; + + @SkylarkCallable( + name = "create_cc_skylark_info", + documented = false, + parameters = { + // TODO(plf): Make this parameter mandatory. Change cc_embed_data.bzl first. + @Param( + name = "ctx", + doc = "Skylark rule context.", + positional = false, + named = true, + noneable = true, + defaultValue = "None", + allowedTypes = { + @ParamType(type = SkylarkRuleContextApi.class), + @ParamType(type = NoneType.class) + }) + }) + CcSkylarkInfoT createCcSkylarkInfo(Object skylarkRuleContextObject) throws EvalException; } diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcSkylarkInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcSkylarkInfoApi.java new file mode 100644 index 0000000000..dc764a064f --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcSkylarkInfoApi.java @@ -0,0 +1,26 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.skylarkbuildapi.cpp; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; + +/** Skylark rules need to provide this to be a dependency of native cc_* rules. */ +@SkylarkModule( + name = "cc_skylark_info", + category = SkylarkModuleCategory.PROVIDER, + doc = "Temporary provider to mark C++ Skylark rules") +// TODO(b/77669139): Delete this class. Use {@link CcCompilationInfo} instead. +public interface CcSkylarkInfoApi {} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LibraryToLinkApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LibraryToLinkApi.java new file mode 100644 index 0000000000..a8421654c7 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LibraryToLinkApi.java @@ -0,0 +1,29 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.skylarkbuildapi.cpp; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; + +/** + * A library the user can link to. This is different from a simple linker input in that it also has + * a library identifier. + */ +@SkylarkModule( + name = "LibraryToLink", + category = SkylarkModuleCategory.BUILTIN, + documented = false, + doc = "A library the user can link to.") +public interface LibraryToLinkApi {} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkerInputApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkerInputApi.java new file mode 100644 index 0000000000..13707d21e6 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkerInputApi.java @@ -0,0 +1,29 @@ +// Copyright 2014 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.skylarkbuildapi.cpp; + +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; + +/** + * Something that appears on the command line of the linker. Since we sometimes expand archive files + * to their constituent object files, we need to keep information whether a certain file contains + * embedded objects and if so, the list of the object files themselves. + */ +public interface LinkerInputApi { + /** Returns the artifact that is the input of the linker. */ + @SkylarkCallable(name = "artifact", doc = "Artifact passed to the linker.") + Artifact getArtifact(); +} |