11cb0ef41Sopenharmony_cidef _v8_disable_pointer_compression(settings, attr):
21cb0ef41Sopenharmony_ci    return {
31cb0ef41Sopenharmony_ci        "//:v8_enable_pointer_compression": "False",
41cb0ef41Sopenharmony_ci    }
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_civ8_disable_pointer_compression = transition(
71cb0ef41Sopenharmony_ci    implementation = _v8_disable_pointer_compression,
81cb0ef41Sopenharmony_ci    inputs = [],
91cb0ef41Sopenharmony_ci    outputs = ["//:v8_enable_pointer_compression"],
101cb0ef41Sopenharmony_ci)
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci# The implementation of transition_rule: all this does is copy the
131cb0ef41Sopenharmony_ci# cc_binary's output to its own output and propagate its runfiles
141cb0ef41Sopenharmony_ci# and executable to use for "$ bazel run".
151cb0ef41Sopenharmony_ci#
161cb0ef41Sopenharmony_ci# This makes transition_rule as close to a pure wrapper of cc_binary
171cb0ef41Sopenharmony_ci# as possible.
181cb0ef41Sopenharmony_cidef _v8_binary_non_pointer_compression(ctx):
191cb0ef41Sopenharmony_ci    binary = ctx.attr.binary[0]
201cb0ef41Sopenharmony_ci    outfile = ctx.actions.declare_file(ctx.label.name)
211cb0ef41Sopenharmony_ci    cc_binary_outfile = binary[DefaultInfo].files.to_list()[0]
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci    ctx.actions.run_shell(
241cb0ef41Sopenharmony_ci        inputs = [cc_binary_outfile],
251cb0ef41Sopenharmony_ci        outputs = [outfile],
261cb0ef41Sopenharmony_ci        command = "cp %s %s" % (cc_binary_outfile.path, outfile.path),
271cb0ef41Sopenharmony_ci    )
281cb0ef41Sopenharmony_ci    return [
291cb0ef41Sopenharmony_ci        DefaultInfo(
301cb0ef41Sopenharmony_ci            executable = outfile,
311cb0ef41Sopenharmony_ci            data_runfiles = binary[DefaultInfo].data_runfiles,
321cb0ef41Sopenharmony_ci        ),
331cb0ef41Sopenharmony_ci    ]
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci# The purpose of this rule is to transition to a config where v8_target_cpu is
361cb0ef41Sopenharmony_ci# set to the appropriate architecture, which will remain in place through exec
371cb0ef41Sopenharmony_ci# transitions, so mksnapshot can for instance build on x64 but for arm64.
381cb0ef41Sopenharmony_civ8_binary_non_pointer_compression = rule(
391cb0ef41Sopenharmony_ci    implementation = _v8_binary_non_pointer_compression,
401cb0ef41Sopenharmony_ci    attrs = {
411cb0ef41Sopenharmony_ci        # This is the cc_binary whose deps will select() on that feature.
421cb0ef41Sopenharmony_ci        # Note specificaly how it's configured with v8_target_cpu_transition, which
431cb0ef41Sopenharmony_ci        # ensures that setting propagates down the graph.
441cb0ef41Sopenharmony_ci        "binary": attr.label(cfg = v8_disable_pointer_compression),
451cb0ef41Sopenharmony_ci        # This is a stock Bazel requirement for any rule that uses Starlark
461cb0ef41Sopenharmony_ci        # transitions. It's okay to copy the below verbatim for all such rules.
471cb0ef41Sopenharmony_ci        #
481cb0ef41Sopenharmony_ci        # The purpose of this requirement is to give the ability to restrict
491cb0ef41Sopenharmony_ci        # which packages can invoke these rules, since Starlark transitions
501cb0ef41Sopenharmony_ci        # make much larger graphs possible that can have memory and performance
511cb0ef41Sopenharmony_ci        # consequences for your build. The whitelist defaults to "everything".
521cb0ef41Sopenharmony_ci        # But you can redefine it more strictly if you feel that's prudent.
531cb0ef41Sopenharmony_ci        "_allowlist_function_transition": attr.label(
541cb0ef41Sopenharmony_ci            default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
551cb0ef41Sopenharmony_ci        ),
561cb0ef41Sopenharmony_ci    },
571cb0ef41Sopenharmony_ci    # Making this executable means it works with "$ bazel run".
581cb0ef41Sopenharmony_ci    executable = True,
591cb0ef41Sopenharmony_ci)
60