Skip to content

fix: codegen plugin target/path improvements #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ user.bazelrc
compile_commands.json
external
.cache
MODULE.bazel.lock
17 changes: 15 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ module(
compatibility_level = 3,
)

bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "ecsact_runtime", version = "0.5.0")
bazel_dep(name = "rules_ecsact", version = "0.4.0")
bazel_dep(name = "rules_ecsact", version = "0.4.8")
bazel_dep(name = "ecsact_codegen", version = "0.1.2")
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)

git_override(
module_name = "hedron_compile_commands",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
commit = "204aa593e002cbd177d30f11f54cff3559110bb9",
)

ecsact = use_extension("@rules_ecsact//ecsact:extensions.bzl", "ecsact")
ecsact.sdk_toolchain(version = "0.6.2")
use_repo(ecsact, "ecsact_toolchains", "ecsact_sdk")

register_toolchains("@ecsact_toolchains//:all")
33 changes: 0 additions & 33 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,34 +1 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "hedron_compile_commands",
sha256 = "5ca68712a6e64d35d5c0e19346b0880529dc536784a91157dd035fcb7bd731ea",
strip_prefix = "bazel-compile-commands-extractor-4d5671472a7272ea19dd61debf1e64d8aed27b41",
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/4d5671472a7272ea19dd61debf1e64d8aed27b41.tar.gz",
)

load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")

hedron_compile_commands_setup()

http_archive(
name = "com_grail_bazel_toolchain",
sha256 = "3cf25401af555309cb6b3f4cc5aad6ae131e34313b82dda0df927626c55b8c46",
strip_prefix = "bazel-toolchain-214fc1cc5d9010fafeaa16a67059caefb1c338aa",
url = "https://github.com/grailbio/bazel-toolchain/archive/214fc1cc5d9010fafeaa16a67059caefb1c338aa.zip",
)

load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies")

bazel_toolchain_dependencies()

load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")

llvm_toolchain(
name = "llvm_toolchain",
llvm_version = "16.0.4",
)

load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")

llvm_register_toolchains()
22 changes: 18 additions & 4 deletions codegen_plugin.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_ecsact//ecsact:defs.bzl", "ecsact_codegen_plugin")
load("@rules_ecsact//ecsact/private:ecsact_codegen_plugin.bzl", "EcsactCodegenPluginInfo")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")

def _cc_ecsact_codegen_plugin_impl(ctx):
plugin = None
Expand All @@ -12,7 +13,19 @@ def _cc_ecsact_codegen_plugin_impl(ctx):
if file.extension == "dll":
plugin = file

plugin_well_known_path = ctx.actions.declare_file(
"{}.{}".format(ctx.attr.name, plugin.extension),
sibling = plugin,
)
ctx.actions.expand_template(
template = plugin,
output = plugin_well_known_path,
)

return [
DefaultInfo(
files = depset([plugin_well_known_path]),
),
EcsactCodegenPluginInfo(
output_extension = ctx.attr.output_extension,
plugin = plugin,
Expand Down Expand Up @@ -69,11 +82,12 @@ def cc_ecsact_codegen_plugin(name = None, srcs = [], deps = [], defines = [], no
no_validate_test: Don't create plugin validation test (not recommended)
**kwargs: Passed to underling cc_binary
"""
name_hash = hash(name)
cc_binary(
name = "{}_bin".format(name),
name = "{}__bin".format(name_hash),
srcs = srcs + [
"@ecsact_runtime//dylib:dylib.cc",
":{}__pn".format(name),
":{}__pn".format(name_hash),
],
deps = deps + [
"@ecsact_runtime//:dylib",
Expand All @@ -86,12 +100,12 @@ def cc_ecsact_codegen_plugin(name = None, srcs = [], deps = [], defines = [], no
)

_cc_ecsact_codegen_plugin_src(
name = "{}__pn".format(name),
name = "{}__pn".format(name_hash),
output_extension = output_extension,
)

_cc_ecsact_codegen_plugin(
name = name,
cc_binary = ":{}_bin".format(name),
cc_binary = ":{}__bin".format(name_hash),
output_extension = output_extension,
)
10 changes: 6 additions & 4 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ecsact_srcs = [

ecsact_codegen(
name = "ecsact_cc_system_impl_srcs",
output_directory = "_ecsact_cc_system_impl_srcs",
srcs = ecsact_srcs,
plugins = [
"@ecsact_lang_cpp//cpp_systems_source_codegen",
Expand All @@ -20,6 +21,7 @@ ecsact_codegen(

ecsact_codegen(
name = "ecsact_cc_hdrs",
output_directory = "_ecsact_cc_hdrs",
srcs = ecsact_srcs,
plugins = [
"@ecsact_lang_cpp//cpp_header_codegen",
Expand All @@ -33,7 +35,7 @@ cc_library(
name = "ecsact_cc",
hdrs = [":ecsact_cc_hdrs"],
copts = copts,
strip_include_prefix = "ecsact_cc_hdrs",
strip_include_prefix = "_ecsact_cc_hdrs",
deps = [
"@ecsact_lang_cpp//:execution_context",
],
Expand All @@ -44,7 +46,7 @@ cc_library(
copts = copts,
srcs = ["meta_check.cc"],
deps = [
"//:ecsact_cc",
":ecsact_cc",
"@ecsact_lang_cpp//:type_info",
"@ecsact_runtime//:lib",
],
Expand All @@ -55,11 +57,11 @@ cc_binary(
copts = copts,
srcs = [
"system_impls.cc",
"//:ecsact_cc_system_impl_srcs",
":ecsact_cc_system_impl_srcs",
],
linkshared = True,
deps = [
"//:ecsact_cc",
":ecsact_cc",
"@ecsact_runtime//dylib:dynamic",
],
)
Expand Down