generated from bazel-contrib/rules-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from aherrmann/dynamic-linker
feat: Support custom dynamic linker
- Loading branch information
Showing
8 changed files
with
164 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
zig/tests/integration_tests/workspace/custom_interpreter/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
load("@rules_zig//zig:defs.bzl", "zig_binary", "zig_configure_binary") | ||
load("@rules_zig//zig:toolchain.bzl", "zig_target_toolchain") | ||
load(":cc.bzl", "cc_config") | ||
|
||
constraint_setting( | ||
name = "interpreter", | ||
) | ||
|
||
constraint_value( | ||
name = "custom_interpreter", | ||
constraint_setting = ":interpreter", | ||
) | ||
|
||
platform( | ||
name = "x86_64-linux-custom_interpreter", | ||
constraint_values = [ | ||
"@platforms//os:linux", | ||
"@platforms//cpu:x86_64", | ||
":custom_interpreter", | ||
], | ||
) | ||
|
||
zig_target_toolchain( | ||
name = "x86_64-linux-custom_interpreter_target", | ||
dynamic_linker = "/custom/loader.so", | ||
target = "x86_64-linux-gnu", | ||
) | ||
|
||
toolchain( | ||
name = "x86_64-linux-custom_interpreter_toolchain", | ||
target_compatible_with = [ | ||
"@platforms//os:linux", | ||
"@platforms//cpu:x86_64", | ||
":custom_interpreter", | ||
], | ||
toolchain = ":x86_64-linux-custom_interpreter_target", | ||
toolchain_type = "@rules_zig//zig/target:toolchain_type", | ||
) | ||
|
||
cc_config( | ||
name = "cc_x86_64-linux-custom_interpreter_toolchain", | ||
target_compatible_with = [ | ||
"@platforms//os:linux", | ||
"@platforms//cpu:x86_64", | ||
], | ||
) | ||
|
||
zig_binary( | ||
name = "binary", | ||
cdeps = ["@rules_zig//zig/lib:libc"], | ||
main = "main.zig", | ||
tags = ["manual"], | ||
) | ||
|
||
zig_configure_binary( | ||
name = "binary-custom_interpreter", | ||
actual = ":binary", | ||
tags = ["manual"], | ||
target = ":x86_64-linux-custom_interpreter", | ||
) |
46 changes: 46 additions & 0 deletions
46
zig/tests/integration_tests/workspace/custom_interpreter/cc.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Dummy CC toolchain for custom-interpreter test. | ||
Provides a dummy CC toolchain such that the custom_interpreter test also works | ||
on other platforms than Linux without having to supply a proper C/C++ | ||
cross-compilation toolchain. | ||
""" | ||
|
||
def _cc_toolchain_config_impl(ctx): | ||
return cc_common.create_cc_toolchain_config_info( | ||
ctx = ctx, | ||
toolchain_identifier = "cc-dummy-toolchain", | ||
host_system_name = "dummy", | ||
target_system_name = "dummy", | ||
target_cpu = "dummy", | ||
target_libc = "gnu", | ||
compiler = "dummy", | ||
abi_version = "unknown", | ||
abi_libc_version = "unknown", | ||
) | ||
|
||
_cc_toolchain_config = rule( | ||
implementation = _cc_toolchain_config_impl, | ||
attrs = {}, | ||
provides = [CcToolchainConfigInfo], | ||
) | ||
|
||
def cc_config(*, name, target_compatible_with): | ||
_cc_toolchain_config(name = name + "_cc_config") | ||
native.cc_toolchain( | ||
name = name + "_cc_toolchain", | ||
toolchain_identifier = "dummy-toolchain", | ||
toolchain_config = ":" + name + "_cc_config", | ||
all_files = ":empty", | ||
compiler_files = ":empty", | ||
dwp_files = ":empty", | ||
linker_files = ":empty", | ||
objcopy_files = ":empty", | ||
strip_files = ":empty", | ||
supports_param_files = 0, | ||
) | ||
native.toolchain( | ||
name = name, | ||
target_compatible_with = target_compatible_with, | ||
toolchain = ":" + name + "_cc_toolchain", | ||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", | ||
) |
7 changes: 7 additions & 0 deletions
7
zig/tests/integration_tests/workspace/custom_interpreter/main.zig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const c = @cImport({ | ||
@cInclude("stdio.h"); | ||
}); | ||
|
||
pub fn main() void { | ||
_ = c.puts("Hello world!"); | ||
} |