Skip to content

feat: bzlmodify #148

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 4 commits into from
Sep 19, 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
15 changes: 1 addition & 14 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
build --enable_platform_specific_config
build --incompatible_use_platforms_repo_for_constraints
build --incompatible_enable_cc_toolchain_resolution
build --incompatible_strict_action_env
build --enable_runfiles

build:windows --platforms=//bazel/platforms:windows

build:linux --platforms=//bazel/platforms:linux
build:linux --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux

common:ci --announce_rc
common:ci --disk_cache=~/.cache/bazel-disk-cache
test:ci --test_output=errors
import %workspace%/bazel/common.bazelrc

try-import %workspace%/user.bazelrc
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.3.2
15 changes: 15 additions & 0 deletions .github/workflows/bzlmod-archive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is maintained by ecsact-dev/ecsact_common
# If changes are required please make them there

name: bzlmod archive

on:
release:
types: [published]

jobs:
bzlmod-archive:
uses: ecsact-dev/bazel_registry/.github/workflows/bzlmod-archive.yml@main
secrets: inherit
permissions:
contents: write
27 changes: 14 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
name: CI
# This file is maintained by ecsact-dev/ecsact_common
# If changes are required please make them there

name: main

on:
push:
branches:
- "**"

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: jidicula/[email protected]
with: { clang-format-version: "15" }
with: { clang-format-version: "16" }

test-windows:
runs-on: windows-latest
Expand All @@ -27,9 +26,10 @@ jobs:
/Users/runneradmin/AppData/Local/bazelisk
/Users/runneradmin/.cache/bazel-disk-cache
key: ${{runner.os}}-bazel-cache
- uses: actions/checkout@v3
- run: bazel test --config=ci //...
- run: bazel build --config=ci //...
- uses: actions/checkout@v4
- run: bazelisk build --config=ci //...
- if: ${{ hashfiles('test/MODULE.bazel') != '' }}
run: bazelisk test --config=ci ...
working-directory: test

test-linux:
Expand All @@ -41,7 +41,8 @@ jobs:
~/.cache/bazelisk
~/.cache/bazel-disk-cache
key: ${{runner.os}}-bazel-cache
- uses: actions/checkout@v3
- run: bazel test --config=ci //...
- run: bazel build --config=ci //...
- uses: actions/checkout@v4
- run: bazelisk build --config=ci //...
- if: ${{ hashfiles('test/MODULE.bazel') != '' }}
run: bazelisk test --config=ci ...
working-directory: test
15 changes: 5 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# 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
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cc_library(
deps = [
"@ecsact_runtime//:common",
"@ecsact_runtime//:meta",
"@ecsact_runtime//:codegen_plugin_cc",
"@ecsact_lang_cpp//:support",
"@ecsact_codegen//:plugin",
],
)

Expand Down
11 changes: 11 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module(
name = "ecsact_lang_cpp",
version = "0.1.0",
compatibility_level = 1,
)

bazel_dep(name = "rules_cc", version = "0.0.8")
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 = "ecsact_codegen", version = "0.1.2")
38 changes: 1 addition & 37 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
workspace(name = "ecsact_lang_cpp")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "ecsact_runtime",
sha256 = "35b03aaef0925fda5b5aefb2d6a6e2c9593f31d6414ab157091f9ca26a992da3",
strip_prefix = "ecsact_runtime-0.3.0",
urls = ["https://github.com/ecsact-dev/ecsact_runtime/archive/refs/tags/0.3.0.tar.gz"],
)

http_archive(
name = "ecsact_codegen",
sha256 = "5a1a466dbddbe042c2e5910f3b65ca44a5ffcef5831fdd0c3b2e2863c13cfb31",
strip_prefix = "ecsact_codegen-0.0.2",
urls = ["https://github.com/ecsact-dev/ecsact_codegen/archive/refs/tags/0.0.2.tar.gz"],
)

http_archive(
name = "boost",
sha256 = "4a79c389add7e3d54d0e12c83098d471d24536ba2d6b8593d3a95f151f25eebb",
strip_prefix = "boost-da62319c330d81ef032517cbe13b6f35d97387cb",
urls = ["https://github.com/bazelboost/boost/archive/da62319c330d81ef032517cbe13b6f35d97387cb.zip"],
)

load("@boost//:index.bzl", "boost_http_archives")

boost_http_archives()

http_archive(
name = "com_google_googletest",
sha256 = "d4cb2430eb82495a49a24310a609b99726726bf126c2fbfa92fd04c14f6a3b31",
strip_prefix = "googletest-d1a0039b97291dd1dc14f123b906bb7622ffe07c",
url = "https://github.com/google/googletest/archive/d1a0039b97291dd1dc14f123b906bb7622ffe07c.zip",
)

http_archive(
name = "hedron_compile_commands",
sha256 = "9d1ce53443747dd574a309fbe6774d1cfc94d20abdb7e7de1bb337f9437761bb",
Expand All @@ -60,9 +26,7 @@ load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")

llvm_toolchain(
name = "llvm_toolchain",
cxx_standard = {"linux": "c++20"},
distribution = "clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04.tar.xz",
llvm_version = "15.0.6",
llvm_version = "16.0.4",
)

load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
Expand Down
20 changes: 20 additions & 0 deletions bazel/common.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
startup --windows_enable_symlinks
common --enable_bzlmod
common --registry=https://raw.githubusercontent.com/ecsact-dev/bazel_registry/main
common --registry=https://raw.githubusercontent.com/bazelboost/registry/main
common --registry=https://bcr.bazel.build
build --enable_platform_specific_config
build --incompatible_use_platforms_repo_for_constraints
build --incompatible_enable_cc_toolchain_resolution
build --incompatible_strict_action_env
build --enable_runfiles
build --noincompatible_remove_rule_name_parameter
query --noincompatible_remove_rule_name_parameter

# Temporary until https://github.com/grailbio/bazel-toolchain/pull/198 is merged
build:linux --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux

common:ci --announce_rc
common:ci --verbose_failures
common:ci --keep_going
common:ci --disk_cache=~/.cache/bazel-disk-cache
16 changes: 13 additions & 3 deletions bazel/copts.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
copts = select({
"@bazel_tools//tools/cpp:msvc": ["/std:c++latest", "/Zc:preprocessor", "/permissive-"],
"//conditions:default": ["-std=c++20"],
load("@bazel_skylib//lib:selects.bzl", "selects")

# Ecsact repositories currently only support clang and cl
copts = selects.with_or({
("@rules_cc//cc/compiler:clang"): [
"-std=c++2b",
"-fexperimental-library",
],
("@rules_cc//cc/compiler:msvc-cl", "@rules_cc//cc/compiler:clang-cl"): [
"/std:c++latest",
"/permissive-",
"/Zc:preprocessor",
],
})
19 changes: 0 additions & 19 deletions bazel/platforms/BUILD.bazel

This file was deleted.

97 changes: 97 additions & 0 deletions codegen_plugin.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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")

def _cc_ecsact_codegen_plugin_impl(ctx):
plugin = None
files = ctx.attr.cc_binary[DefaultInfo].files

for file in files.to_list():
if file.extension == "so":
plugin = file
if file.extension == "dll":
plugin = file

return [
EcsactCodegenPluginInfo(
output_extension = ctx.attr.output_extension,
plugin = plugin,
data = [plugin],
),
]

_cc_ecsact_codegen_plugin = rule(
implementation = _cc_ecsact_codegen_plugin_impl,
attrs = {
"cc_binary": attr.label(mandatory = True),
"output_extension": attr.string(mandatory = True),
},
)

_generated_src = """
#include "ecsact/codegen/plugin.h"

const char* ecsact_codegen_plugin_name() {{
return "{output_extension}";
}}
"""

def _cc_ecsact_codegen_plugin_src_impl(ctx):
output_cc_src = ctx.actions.declare_file("{}.plugin_name.cc".format(ctx.attr.name))
ctx.actions.write(
output = output_cc_src,
content = _generated_src.format(output_extension = ctx.attr.output_extension),
)

return [
DefaultInfo(files = depset([output_cc_src])),
]

_cc_ecsact_codegen_plugin_src = rule(
implementation = _cc_ecsact_codegen_plugin_src_impl,
attrs = {
"output_extension": attr.string(mandatory = True),
},
)

def cc_ecsact_codegen_plugin(name = None, srcs = [], deps = [], defines = [], no_validate_test = False, output_extension = None, **kwargs):
"""Create ecsact codegen plugin with C++

NOTE: ecsact_codegen_plugin_name() is automatically generated for you based
on the `output_extension` attribute.

Args:
name: Passed to underling cc_binary
srcs: Passed to underling cc_binary
deps: Passed to underling cc_binary
defines: Passed to underling cc_binary
output_extension: File extension the plugin writes to
no_validate_test: Don't create plugin validation test (not recommended)
**kwargs: Passed to underling cc_binary
"""
cc_binary(
name = "{}_bin".format(name),
srcs = srcs + [
"@ecsact_runtime//dylib:dylib.cc",
":{}__pn".format(name),
],
deps = deps + [
"@ecsact_runtime//:dylib",
"@ecsact_runtime//dylib:meta",
"@ecsact_codegen//:plugin",
],
defines = defines + ["ECSACT_META_API_LOAD_AT_RUNTIME"],
linkshared = True,
**kwargs
)

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

_cc_ecsact_codegen_plugin(
name = name,
cc_binary = ":{}_bin".format(name),
output_extension = output_extension,
)
15 changes: 10 additions & 5 deletions cog.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
post_bump_hooks = [
"git push",
"git push origin {{version}}",
"gh release create {{version}} --generate-notes --latest -t {{version}} --verify-tag",
]
pre_bump_hooks = [
# Ecsact pre 1.0.0 the 0.X.0 is our 'major' version
"buildozer 'set version {{version}}' 'set compatibility_level {{version.minor}}' //MODULE.bazel:%module",
]

post_bump_hooks = [
"git push",
"git push origin {{version}}",
"gh release create {{version}} --generate-notes --latest -t {{version}} --verify-tag",
]
2 changes: 1 addition & 1 deletion cpp_header_codegen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//bazel:copts.bzl", "copts")
load("@ecsact_codegen//:codegen_plugin.bzl", "cc_ecsact_codegen_plugin")
load("//:codegen_plugin.bzl", "cc_ecsact_codegen_plugin")

package(default_visibility = ["//visibility:public"])

Expand Down
4 changes: 2 additions & 2 deletions cpp_header_codegen/cpp_header_codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <string>
#include <cassert>
#include "ecsact/runtime/meta.hh"
#include "ecsact/codegen_plugin.h"
#include "ecsact/codegen_plugin.hh"
#include "ecsact/codegen/plugin.h"
#include "ecsact/codegen/plugin.hh"
#include "ecsact/lang-support/lang-cc.hh"

constexpr auto GENERATED_FILE_DISCLAIMER = R"(// GENERATED FILE - DO NOT EDIT
Expand Down
2 changes: 1 addition & 1 deletion cpp_meta_header_codegen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//bazel:copts.bzl", "copts")
load("@ecsact_codegen//:codegen_plugin.bzl", "cc_ecsact_codegen_plugin")
load("//:codegen_plugin.bzl", "cc_ecsact_codegen_plugin")

package(default_visibility = ["//visibility:public"])

Expand Down
4 changes: 2 additions & 2 deletions cpp_meta_header_codegen/cpp_meta_header_codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <tuple>
#include <map>
#include "ecsact/runtime/meta.hh"
#include "ecsact/codegen_plugin.h"
#include "ecsact/codegen_plugin.hh"
#include "ecsact/codegen/plugin.h"
#include "ecsact/codegen/plugin.hh"
#include "ecsact/lang-support/lang-cc.hh"
#include "ecsact/cpp_codegen_plugin_util.hh"

Expand Down
2 changes: 1 addition & 1 deletion cpp_systems_header_codegen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//bazel:copts.bzl", "copts")
load("@ecsact_codegen//:codegen_plugin.bzl", "cc_ecsact_codegen_plugin")
load("//:codegen_plugin.bzl", "cc_ecsact_codegen_plugin")

package(default_visibility = ["//visibility:public"])

Expand Down
Loading