Skip to content

Commit f357d7f

Browse files
authored
fix: codegen plugin target/path improvements (#182)
1 parent 25fb752 commit f357d7f

File tree

6 files changed

+41
-44
lines changed

6 files changed

+41
-44
lines changed

.bazelignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test
1+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ user.bazelrc
33
compile_commands.json
44
external
55
.cache
6+
MODULE.bazel.lock

MODULE.bazel

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@ module(
44
compatibility_level = 3,
55
)
66

7-
bazel_dep(name = "rules_cc", version = "0.0.8")
7+
bazel_dep(name = "rules_cc", version = "0.0.9")
88
bazel_dep(name = "bazel_skylib", version = "1.4.2")
99
bazel_dep(name = "ecsact_runtime", version = "0.5.0")
10-
bazel_dep(name = "rules_ecsact", version = "0.4.0")
10+
bazel_dep(name = "rules_ecsact", version = "0.4.8")
1111
bazel_dep(name = "ecsact_codegen", version = "0.1.2")
12+
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
13+
14+
git_override(
15+
module_name = "hedron_compile_commands",
16+
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
17+
commit = "204aa593e002cbd177d30f11f54cff3559110bb9",
18+
)
19+
20+
ecsact = use_extension("@rules_ecsact//ecsact:extensions.bzl", "ecsact")
21+
ecsact.sdk_toolchain(version = "0.6.2")
22+
use_repo(ecsact, "ecsact_toolchains", "ecsact_sdk")
23+
24+
register_toolchains("@ecsact_toolchains//:all")

WORKSPACE.bazel

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1 @@
1-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
21

3-
http_archive(
4-
name = "hedron_compile_commands",
5-
sha256 = "5ca68712a6e64d35d5c0e19346b0880529dc536784a91157dd035fcb7bd731ea",
6-
strip_prefix = "bazel-compile-commands-extractor-4d5671472a7272ea19dd61debf1e64d8aed27b41",
7-
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/4d5671472a7272ea19dd61debf1e64d8aed27b41.tar.gz",
8-
)
9-
10-
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
11-
12-
hedron_compile_commands_setup()
13-
14-
http_archive(
15-
name = "com_grail_bazel_toolchain",
16-
sha256 = "3cf25401af555309cb6b3f4cc5aad6ae131e34313b82dda0df927626c55b8c46",
17-
strip_prefix = "bazel-toolchain-214fc1cc5d9010fafeaa16a67059caefb1c338aa",
18-
url = "https://github.com/grailbio/bazel-toolchain/archive/214fc1cc5d9010fafeaa16a67059caefb1c338aa.zip",
19-
)
20-
21-
load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies")
22-
23-
bazel_toolchain_dependencies()
24-
25-
load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")
26-
27-
llvm_toolchain(
28-
name = "llvm_toolchain",
29-
llvm_version = "16.0.4",
30-
)
31-
32-
load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
33-
34-
llvm_register_toolchains()

codegen_plugin.bzl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load("@rules_ecsact//ecsact:defs.bzl", "ecsact_codegen_plugin")
22
load("@rules_ecsact//ecsact/private:ecsact_codegen_plugin.bzl", "EcsactCodegenPluginInfo")
33
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
4+
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
45

56
def _cc_ecsact_codegen_plugin_impl(ctx):
67
plugin = None
@@ -12,7 +13,19 @@ def _cc_ecsact_codegen_plugin_impl(ctx):
1213
if file.extension == "dll":
1314
plugin = file
1415

16+
plugin_well_known_path = ctx.actions.declare_file(
17+
"{}.{}".format(ctx.attr.name, plugin.extension),
18+
sibling = plugin,
19+
)
20+
ctx.actions.expand_template(
21+
template = plugin,
22+
output = plugin_well_known_path,
23+
)
24+
1525
return [
26+
DefaultInfo(
27+
files = depset([plugin_well_known_path]),
28+
),
1629
EcsactCodegenPluginInfo(
1730
output_extension = ctx.attr.output_extension,
1831
plugin = plugin,
@@ -69,11 +82,12 @@ def cc_ecsact_codegen_plugin(name = None, srcs = [], deps = [], defines = [], no
6982
no_validate_test: Don't create plugin validation test (not recommended)
7083
**kwargs: Passed to underling cc_binary
7184
"""
85+
name_hash = hash(name)
7286
cc_binary(
73-
name = "{}_bin".format(name),
87+
name = "{}__bin".format(name_hash),
7488
srcs = srcs + [
7589
"@ecsact_runtime//dylib:dylib.cc",
76-
":{}__pn".format(name),
90+
":{}__pn".format(name_hash),
7791
],
7892
deps = deps + [
7993
"@ecsact_runtime//:dylib",
@@ -86,12 +100,12 @@ def cc_ecsact_codegen_plugin(name = None, srcs = [], deps = [], defines = [], no
86100
)
87101

88102
_cc_ecsact_codegen_plugin_src(
89-
name = "{}__pn".format(name),
103+
name = "{}__pn".format(name_hash),
90104
output_extension = output_extension,
91105
)
92106

93107
_cc_ecsact_codegen_plugin(
94108
name = name,
95-
cc_binary = ":{}_bin".format(name),
109+
cc_binary = ":{}__bin".format(name_hash),
96110
output_extension = output_extension,
97111
)

test/BUILD.bazel

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ecsact_srcs = [
1212

1313
ecsact_codegen(
1414
name = "ecsact_cc_system_impl_srcs",
15+
output_directory = "_ecsact_cc_system_impl_srcs",
1516
srcs = ecsact_srcs,
1617
plugins = [
1718
"@ecsact_lang_cpp//cpp_systems_source_codegen",
@@ -20,6 +21,7 @@ ecsact_codegen(
2021

2122
ecsact_codegen(
2223
name = "ecsact_cc_hdrs",
24+
output_directory = "_ecsact_cc_hdrs",
2325
srcs = ecsact_srcs,
2426
plugins = [
2527
"@ecsact_lang_cpp//cpp_header_codegen",
@@ -33,7 +35,7 @@ cc_library(
3335
name = "ecsact_cc",
3436
hdrs = [":ecsact_cc_hdrs"],
3537
copts = copts,
36-
strip_include_prefix = "ecsact_cc_hdrs",
38+
strip_include_prefix = "_ecsact_cc_hdrs",
3739
deps = [
3840
"@ecsact_lang_cpp//:execution_context",
3941
],
@@ -44,7 +46,7 @@ cc_library(
4446
copts = copts,
4547
srcs = ["meta_check.cc"],
4648
deps = [
47-
"//:ecsact_cc",
49+
":ecsact_cc",
4850
"@ecsact_lang_cpp//:type_info",
4951
"@ecsact_runtime//:lib",
5052
],
@@ -55,11 +57,11 @@ cc_binary(
5557
copts = copts,
5658
srcs = [
5759
"system_impls.cc",
58-
"//:ecsact_cc_system_impl_srcs",
60+
":ecsact_cc_system_impl_srcs",
5961
],
6062
linkshared = True,
6163
deps = [
62-
"//:ecsact_cc",
64+
":ecsact_cc",
6365
"@ecsact_runtime//dylib:dynamic",
6466
],
6567
)

0 commit comments

Comments
 (0)