Skip to content

Commit

Permalink
C++: Implements Skylark cc_common.compile()/link().
Browse files Browse the repository at this point in the history
Working towards #4570.

RELNOTES:none
PiperOrigin-RevId: 205274676
  • Loading branch information
oquenchil authored and Copybara-Service committed Jul 19, 2018
1 parent cfa35f3 commit 769f72e
Show file tree
Hide file tree
Showing 9 changed files with 861 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcBinaryRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcImportRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcLibraryRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcModule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcTestRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses;
import com.google.devtools.build.lib.rules.core.CoreRules;
Expand All @@ -27,7 +28,6 @@
import com.google.devtools.build.lib.rules.cpp.CcImportRule;
import com.google.devtools.build.lib.rules.cpp.CcLibcTopAlias;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.cpp.CcModule;
import com.google.devtools.build.lib.rules.cpp.CcToolchainAliasRule;
import com.google.devtools.build.lib.rules.cpp.CcToolchainRule;
import com.google.devtools.build.lib.rules.cpp.CcToolchainSuiteRule;
Expand Down Expand Up @@ -77,7 +77,7 @@ public void init(ConfiguredRuleClassProvider.Builder builder) {
builder.addRuleDefinition(new FdoProfileRule());
builder.addRuleDefinition(new FdoPrefetchHintsRule());

builder.addSkylarkBootstrap(new CcBootstrap(new CcModule()));
builder.addSkylarkBootstrap(new CcBootstrap(new BazelCcModule()));
builder.addSkylarkAccessibleTopLevels("CcCompilationInfo", CcCompilationInfo.PROVIDER);
builder.addSkylarkAccessibleTopLevels("CcLinkingInfo", CcLinkingInfo.PROVIDER);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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.bazel.rules.cpp;

import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.skylark.SkylarkRuleContext;
import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo;
import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo;
import com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper.LinkingInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.cpp.CcModule;
import com.google.devtools.build.lib.rules.cpp.CcModule.CcSkylarkInfo;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables;
import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.BazelCcModuleApi;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.SkylarkList;

/**
* A module that contains Skylark utilities for C++ support.
*
* <p>This is a work in progress. The API is guarded behind --experimental_enable_cc_skylark_api.
* The API is under development and unstable.
*/
public class BazelCcModule extends CcModule
implements BazelCcModuleApi<
CcToolchainProvider,
FeatureConfiguration,
CompilationInfo,
CcCompilationInfo,
CcCompilationOutputs,
LinkingInfo,
CcLinkingInfo,
CcToolchainVariables,
LibraryToLink,
CcLinkParams,
CcSkylarkInfo> {

@Override
public CompilationInfo compile(
SkylarkRuleContext skylarkRuleContext,
FeatureConfiguration skylarkFeatureConfiguration,
CcToolchainProvider skylarkCcToolchainProvider,
SkylarkList<Artifact> sources,
SkylarkList<Artifact> headers,
Object skylarkIncludes,
Object skylarkCopts,
SkylarkList<CcCompilationInfo> ccCompilationInfos)
throws EvalException {
return BazelCcModule.compile(
BazelCppSemantics.INSTANCE,
skylarkRuleContext,
skylarkFeatureConfiguration,
skylarkCcToolchainProvider,
sources,
headers,
skylarkIncludes,
skylarkCopts,
/* generateNoPicOutputs= */ "conditionally",
/* generatePicOutputs= */ "conditionally",
/* skylarkAdditionalCompilationInputs= */ Runtime.NONE,
/* skylarkAdditionalIncludeScanningRoots= */ Runtime.NONE,
ccCompilationInfos,
/* purpose= */ Runtime.NONE);
}

@Override
public LinkingInfo link(
SkylarkRuleContext skylarkRuleContext,
FeatureConfiguration skylarkFeatureConfiguration,
CcToolchainProvider skylarkCcToolchainProvider,
CcCompilationOutputs ccCompilationOutputs,
Object skylarkLinkopts,
Object dynamicLibrary,
SkylarkList<CcLinkingInfo> skylarkCcLinkingInfos,
boolean neverLink)
throws InterruptedException, EvalException {
return BazelCcModule.link(
BazelCppSemantics.INSTANCE,
skylarkRuleContext,
skylarkFeatureConfiguration,
skylarkCcToolchainProvider,
ccCompilationOutputs,
skylarkLinkopts,
/* shouldCreateStaticLibraries= */ true,
dynamicLibrary,
skylarkCcLinkingInfos,
neverLink);
}
}
Loading

0 comments on commit 769f72e

Please sign in to comment.