Skip to content

Instantly share code, notes, and snippets.

@malkia
Created January 1, 2023 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malkia/16fcb04b316e3c482b9324fa60b358d1 to your computer and use it in GitHub Desktop.
Save malkia/16fcb04b316e3c482b9324fa60b358d1 to your computer and use it in GitHub Desktop.
force_compilation_mode bazel transition rule
force_compilation_mode = rule(
# implementation = lambda ctx:
# DefaultInfo( runfiles = ctx.runfiles(
# transitive_files = depset(
# transitive = [ depset( transitive = [x[DefaultInfo].files] ) for x in ctx.attr.data ]
# ))),
implementation = lambda ctx:
DefaultInfo( files = depset(
transitive = [ depset( transitive = [x[DefaultInfo].files] ) for x in ctx.attr.data ]
)),
attrs = {
"compilation_mode": attr.string(mandatory = True),
"data": attr.label_list(
mandatory = True,
cfg = transition(
implementation = lambda settings, attr: {
"//command_line_option:compilation_mode": attr.compilation_mode
},
inputs = [],
outputs = ["//command_line_option:compilation_mode"],
),
),
# This attribute is required to use starlark transitions. It allows
# allowlisting usage of this rule. For more information, see
# https://docs.bazel.build/versions/master/skylark/config.html#user-defined-transitions
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}
)
# load("t.bzl", "force_compilation_mode")
#
# cc_binary(
# name = "a",
# srcs = ["a.c"],
# visibility = ["//visibility:public"]
# )
#
# force_compilation_mode(
# compilation_mode = "dbg",
# name = "d",
# data = [":a"]
# )
#
# force_compilation_mode(
# compilation_mode = "opt",
# name = "o",
# data = [":a"]
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment