Skip to content

feat: allow ecsact cli used as a toolchain #38

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 3 commits into from
Sep 21, 2023
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
external
dist
test
15 changes: 5 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# bazel
/bazel-*
/user.bazelrc

# https://github.com/hedronvision/bazel-compile-commands-extractor
/compile_commands.json
/external

# clangd
/.cache/
bazel-*
user.bazelrc
compile_commands.json
external
.cache/

# ecsact codegen
*.ecsact.*

12 changes: 12 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_ecsact//ecsact:toolchain.bzl", "ecsact_toolchain")
load("//bazel/tools:cc_stamp_header.bzl", "cc_stamp_header")
load("//bazel:copts.bzl", "copts")

Expand Down Expand Up @@ -29,3 +30,14 @@ alias(
name = "ecsact_cli",
actual = ":ecsact",
)

ecsact_toolchain(
name = "ecsact_toolchain",
target_tool = ":ecsact",
)

toolchain(
name = "toolchain",
toolchain = ":ecsact_toolchain",
toolchain_type = "@rules_ecsact//ecsact:toolchain_type",
)
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ bazel_dep(name = "ecsact_codegen", version = "0.1.2")
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2")
bazel_dep(name = "magic_enum", version = "0.9.3")
bazel_dep(name = "docopt.cpp", version = "0.6.2")
bazel_dep(name = "rules_ecsact", version = "0.4.2")
7 changes: 7 additions & 0 deletions test/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import %workspace%/../bazel/common.bazelrc

common [email protected]//:use_std_fs
build:windows --workspace_status_command=../bazel/tools/wsc.cmd
build:linux --workspace_status_command=../bazel/tools/wsc.sh

try-import %workspace%/user.bazelrc
38 changes: 38 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_ecsact//ecsact:defs.bzl", "ecsact_codegen", "ecsact_codegen_plugin")
load("@ecsact_cli//bazel:copts.bzl", "copts")

cc_binary(
name = "test_codegen_plugin_bin",
linkshared = True,
copts = copts,
srcs = [
"test_codegen_plugin.cc",
"@ecsact_runtime//dylib:dylib.cc",
],
deps = [
"@ecsact_codegen//:plugin",
"@ecsact_runtime//dylib:meta",
"@ecsact_runtime//dylib:util",
],
)

ecsact_codegen_plugin(
name = "test_codegen_plugin",
plugin = ":test_codegen_plugin_bin",
output_extension = "txt",
)

ecsact_codegen(
name = "codegen_test",
srcs = ["test.ecsact"],
plugins = [":test_codegen_plugin"],
)

build_test(
name = "build_test",
targets = [
":codegen_test",
],
)
15 changes: 15 additions & 0 deletions test/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module(name = "ecsact_cli_test")

bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_ecsact", version = "0.4.2")
bazel_dep(name = "ecsact_codegen", version = "0.1.2")
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2")
bazel_dep(name = "ecsact_runtime", version = "0.5.1")
bazel_dep(name = "ecsact_cli")

local_path_override(
module_name = "ecsact_cli",
path = "..",
)

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

http_archive(
name = "hedron_compile_commands",
sha256 = "ed5aea1dc87856aa2029cb6940a51511557c5cac3dbbcb05a4abd989862c36b4",
strip_prefix = "bazel-compile-commands-extractor-e16062717d9b098c3c2ac95717d2b3e661c50608",
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/e16062717d9b098c3c2ac95717d2b3e661c50608.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 = "33ba2951db87fc2ebdb609b489b84dcd77f417ad2b2ab9d0f469835e991dab11",
strip_prefix = "bazel-toolchain-885e6926f235dbd0fbde2055f5763cb762d8c0ef",
url = "https://github.com/grailbio/bazel-toolchain/archive/885e6926f235dbd0fbde2055f5763cb762d8c0ef.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()
3 changes: 3 additions & 0 deletions test/test.ecsact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
main package test;

component TestComponent {}
17 changes: 17 additions & 0 deletions test/test_codegen_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <string_view>
#include "ecsact/codegen/plugin.h"
#include "ecsact/runtime/dylib.h"

using namespace std::string_view_literals;

auto ecsact_codegen_plugin_name() -> const char* {
return "txt";
}

auto ecsact_codegen_plugin( //
ecsact_package_id package_id,
ecsact_codegen_write_fn_t write_fn
) -> void {
auto test_message = "this is just a test, breathe!"sv;
write_fn(test_message.data(), test_message.size());
}