dfdb1f2680
Your old version of the software released under the old license can still be used under the terms of the old license. I have received the following statement from the past contributors Luis Holanda, Jeremy Volkman and Fabian Hahn: I hereby confirm that I am the copyright holder or authorized by the copyright holder of this contribution. As such I hereby confirm that all contributions made to bazel-zig-cc by me or on behalf of me, hereby is licensed under the Apache 2.0 License [http://www.apache.org/licenses/LICENSE-2.0]. I am aware that my previous contributions will still be available under the MIT license as well. I confirm that I am aware of the bazel-zig-cc teams intention to release bazel-zig-cc under the Apache 2.0 License from release [1.0] and onwards, and that the bazel-zig-cc no longer will accept contributions made under the MIT and that any future submissions from myself will be considered to be licensed under Apache 2.0 unless I expressly state otherwise. Copyright and re-licensing for Google and Uber employees has been resolved internally. Since not all contributors took action to re-license the code yet, portions of bazel-zig-cc remain licensed as MIT. I have started this project during my personal time with my personal resources. I am now handing over all copyrights to this code to Uber Technologies, Inc.
79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
# Copyright 2023 Uber Technologies, Inc.
|
|
# Licensed under the Apache License, Version 2.0
|
|
|
|
def _vars_script(env, run_under, cmd):
|
|
ret = ["#!/bin/sh"]
|
|
for k, v in env.items():
|
|
ret += ['export {}="{}"'.format(k, v)]
|
|
ret += ['exec {} {} "$@"'.format(run_under, cmd)]
|
|
return "\n".join(ret) + "\n" # trailing newline is easier on the eyes
|
|
|
|
def _platform_transition_impl(settings, attr):
|
|
_ignore = settings
|
|
return {
|
|
"//command_line_option:platforms": "@zig_sdk{}".format(attr.platform),
|
|
}
|
|
|
|
_platform_transition = transition(
|
|
implementation = _platform_transition_impl,
|
|
inputs = [],
|
|
outputs = [
|
|
"//command_line_option:platforms",
|
|
],
|
|
)
|
|
|
|
def _platform_binary_impl(ctx):
|
|
source_info = ctx.attr.src[DefaultInfo]
|
|
|
|
executable = None
|
|
if source_info.files_to_run and source_info.files_to_run.executable:
|
|
command = _vars_script(ctx.attr.env, ctx.attr.run_under, source_info.files_to_run.executable.short_path)
|
|
executable = ctx.actions.declare_file("{}_{}".format(ctx.file.src.basename, ctx.attr.platform))
|
|
ctx.actions.write(
|
|
output = executable,
|
|
content = command,
|
|
is_executable = True,
|
|
)
|
|
|
|
return [DefaultInfo(
|
|
executable = executable,
|
|
files = depset([executable]),
|
|
runfiles = ctx.runfiles(files = ctx.files.src),
|
|
)]
|
|
|
|
_attrs = {
|
|
"src": attr.label(
|
|
allow_single_file = True,
|
|
mandatory = True,
|
|
doc = "Target to build.",
|
|
),
|
|
"platform": attr.string(
|
|
doc = "The platform to build the target for.",
|
|
),
|
|
"run_under": attr.string(
|
|
doc = "wrapper executable",
|
|
),
|
|
"env": attr.string_dict(
|
|
doc = "Environment variables for the test",
|
|
),
|
|
"_allowlist_function_transition": attr.label(
|
|
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
|
|
),
|
|
}
|
|
|
|
# wrap a single exectable and build it for the specified platform.
|
|
platform_binary = rule(
|
|
implementation = _platform_binary_impl,
|
|
cfg = _platform_transition,
|
|
attrs = _attrs,
|
|
executable = True,
|
|
)
|
|
|
|
# wrap a single test target and build it for the specified platform.
|
|
platform_test = rule(
|
|
implementation = _platform_binary_impl,
|
|
cfg = _platform_transition,
|
|
attrs = _attrs,
|
|
test = True,
|
|
)
|