Skip to content

Commit

Permalink
Initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Mar 8, 2024
1 parent 59cf396 commit 5313d07
Show file tree
Hide file tree
Showing 26 changed files with 922 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ public final class BuildLanguageOptions extends OptionsBase {
+ "cc_shared_library will be available")
public boolean experimentalCcSharedLibrary;

@Option(
name = "experimental_cc_static_library",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS, OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
OptionMetadataTag.EXPERIMENTAL,
},
help =
"If set to true, rule attributes and Starlark API methods needed for the rule "
+ "cc_static_library will be available")
public boolean experimentalCcStaticLibrary;
@Option(
name = "incompatible_require_linker_input_cc_api",
defaultValue = "true",
Expand Down Expand Up @@ -759,6 +771,7 @@ public StarlarkSemantics toStarlarkSemantics() {
.setBool(EXPERIMENTAL_GOOGLE_LEGACY_API, experimentalGoogleLegacyApi)
.setBool(EXPERIMENTAL_PLATFORMS_API, experimentalPlatformsApi)
.setBool(EXPERIMENTAL_CC_SHARED_LIBRARY, experimentalCcSharedLibrary)
.setBool(EXPERIMENTAL_CC_STATIC_LIBRARY, experimentalCcStaticLibrary)
.setBool(EXPERIMENTAL_REPO_REMOTE_EXEC, experimentalRepoRemoteExec)
.setBool(EXPERIMENTAL_DISABLE_EXTERNAL_PACKAGE, experimentalDisableExternalPackage)
.setBool(EXPERIMENTAL_SIBLING_REPOSITORY_LAYOUT, experimentalSiblingRepositoryLayout)
Expand Down Expand Up @@ -849,6 +862,7 @@ public StarlarkSemantics toStarlarkSemantics() {
public static final String EXPERIMENTAL_BZL_VISIBILITY = "+experimental_bzl_visibility";
public static final String CHECK_BZL_VISIBILITY = "+check_bzl_visibility";
public static final String EXPERIMENTAL_CC_SHARED_LIBRARY = "-experimental_cc_shared_library";
public static final String EXPERIMENTAL_CC_STATIC_LIBRARY = "-experimental_cc_static_library";
public static final String EXPERIMENTAL_DISABLE_EXTERNAL_PACKAGE =
"-experimental_disable_external_package";
public static final String EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,12 @@ public boolean checkExperimentalCcSharedLibrary(StarlarkThread thread) throws Ev
return thread.getSemantics().getBool(BuildLanguageOptions.EXPERIMENTAL_CC_SHARED_LIBRARY);
}

@Override
public boolean checkExperimentalCcStaticLibrary(StarlarkThread thread) throws EvalException {
isCalledFromStarlarkCcCommon(thread);
return thread.getSemantics().getBool(BuildLanguageOptions.EXPERIMENTAL_CC_STATIC_LIBRARY);
}

@Override
public boolean getIncompatibleDisableObjcLibraryTransition(StarlarkThread thread)
throws EvalException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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.rules.cpp;

import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.Type.STRING_LIST;

import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.packages.RuleClass;

/** A dummy rule for <code>cc_static_library</code> rule. */
public class CcStaticLibraryRule implements RuleDefinition {
@Override
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
return builder
.add(
attr("tags", STRING_LIST)
.orderIndependent()
.taggable()
.nonconfigurable("low-level attribute, used in TargetUtils without configurations"))
.build();
}

@Override
public Metadata getMetadata() {
return Metadata.builder()
.name("cc_static_library")
.factoryClass(BaseRuleClasses.EmptyRuleConfiguredTargetFactory.class)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,13 @@ LinkerInputT createLinkerInput(
documented = false)
boolean checkExperimentalCcSharedLibrary(StarlarkThread thread) throws EvalException;

@StarlarkMethod(
name = "check_experimental_cc_static_library",
doc = "DO NOT USE. This is to guard use of cc_static_library.",
useStarlarkThread = true,
documented = false)
boolean checkExperimentalCcStaticLibrary(StarlarkThread thread) throws EvalException;

@StarlarkMethod(
name = "incompatible_disable_objc_library_transition",
useStarlarkThread = true,
Expand Down
3 changes: 3 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/action_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ CLIF_MATCH_ACTION_NAME = "clif-match"
# A string constant for the obj copy actions.
OBJ_COPY_ACTION_NAME = "objcopy_embed_data"

VALIDATE_STATIC_LIBRARY = "validate-static-library"

ACTION_NAMES = struct(
c_compile = C_COMPILE_ACTION_NAME,
cpp_compile = CPP_COMPILE_ACTION_NAME,
Expand Down Expand Up @@ -122,4 +124,5 @@ ACTION_NAMES = struct(
objcpp_compile = OBJCPP_COMPILE_ACTION_NAME,
clif_match = CLIF_MATCH_ACTION_NAME,
objcopy_embed_data = OBJ_COPY_ACTION_NAME,
validate_static_library = VALIDATE_STATIC_LIBRARY,
)
5 changes: 5 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/cc_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ def _check_experimental_cc_shared_library():
cc_common_internal.check_private_api(allowlist = _PRIVATE_STARLARKIFICATION_ALLOWLIST)
return cc_common_internal.check_experimental_cc_shared_library()

def _check_experimental_cc_static_library():
cc_common_internal.check_private_api(allowlist = _PRIVATE_STARLARKIFICATION_ALLOWLIST)
return cc_common_internal.check_experimental_cc_static_library()

def _incompatible_disable_objc_library_transition():
cc_common_internal.check_private_api(allowlist = _PRIVATE_STARLARKIFICATION_ALLOWLIST)
return cc_common_internal.incompatible_disable_objc_library_transition()
Expand Down Expand Up @@ -905,6 +909,7 @@ cc_common = struct(
merge_compilation_contexts = _merge_compilation_contexts,
merge_linking_contexts = _merge_linking_contexts,
check_experimental_cc_shared_library = _check_experimental_cc_shared_library,
check_experimental_cc_static_library = _check_experimental_cc_static_library,
create_module_map = _create_module_map,
create_debug_context = _create_debug_context,
merge_debug_context = _merge_debug_context,
Expand Down
2 changes: 2 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1259,4 +1259,6 @@ cc_helper = struct(
proto_output_root = _proto_output_root,
package_source_root = _package_source_root,
tokenize = _tokenize,
get_base_name = _get_base_name,
replace_name = _replace_name,
)
Loading

0 comments on commit 5313d07

Please sign in to comment.