Skip to content
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
21 changes: 21 additions & 0 deletions .github/workflows/prek.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Pre-commit

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
prek:
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: j178/prek-action@1382ad72dea72f9d53832f2bcb65b3e87a947204 # v3.0.1
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ repos:
# Check formatting and lint for starlark code
- repo: https://github.com/keith/pre-commit-buildifier
rev: 6.4.0
# require_serial: parallel batches race to download the buildifier binary on a cold cache
hooks:
- id: buildifier
require_serial: true
- id: buildifier-lint
require_serial: true
# LuaLibrary/FennelLibrary are public API, and luaunit/fennel load //lua/private on purpose
args: ["-warnings=-name-conventions,-bzl-visibility"]
# Enforce that commit messages allow for later changelog generation
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.15.0
Expand Down
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

gazelle_binary(
name = "gazelle_bin",
Expand Down
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolcha
use_repo(toolchains, "zig_sdk")

register_toolchains(
# Registered first so they win over the glibc 2.17 default
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain/...",
"@zig_sdk//libc_aware/toolchain/...",
dev_dependency = True,
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ There are 3 modules in this project
- rules_lua - this folder, containing basic building blocks such as lua libraries, fennel binaries, etc. See
the [docs](/docs) folder for more docs on this
- [luaunit](/luaunit) - rules for using luaunit for unit tests
- [busted](/busted) - rules for using busted for unit
- [busted](/busted) - rules for using busted for unit

See [the example project](/examples) for more advanced usage
16 changes: 16 additions & 0 deletions busted/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ module(
)

bazel_dep(name = "rules_foreign_cc", version = "0.17.0")

# Use the host make, as building it from source runs hundreds of slow autoconf check actions
foreign_cc_tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools", dev_dependency = True)
foreign_cc_tools.make(mode = "system")

bazel_dep(name = "hermetic_cc_toolchain", version = "4.3.0", dev_dependency = True)

toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains", dev_dependency = True)
use_repo(toolchains, "zig_sdk")

register_toolchains(
"@zig_sdk//toolchain/...",
"@zig_sdk//libc_aware/toolchain/...",
dev_dependency = True,
)

bazel_dep(name = "aspect_bazel_lib", version = "2.22.5")
bazel_dep(name = "rules_lua", version = "0.0.0")
local_path_override(
Expand Down
3,782 changes: 561 additions & 3,221 deletions busted/MODULE.bazel.lock

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions busted/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
"""Rules for running busted tests"""

load("@aspect_bazel_lib//lib:paths.bzl", "to_rlocation_path")
load("@rules_lua//lua:defs.bzl", "BASH_RLOCATION_FUNCTION")
load("@rules_lua//lua:providers.bzl", "LuaLibrary")

def busted_test_impl(ctx, srcs):
"""Write a launcher that runs busted on the given test files.

Args:
ctx: rule context
srcs: lua test files

Returns:
list of providers for the test rule
"""
out_executable = ctx.actions.declare_file(ctx.attr.name + "_test")

ctx.actions.write(
Expand Down
2 changes: 1 addition & 1 deletion docs/fennel_providers.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/lua_providers.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolcha
use_repo(toolchains, "zig_sdk")

register_toolchains(
# Registered first so they win over the glibc 2.17 default
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain/...",
"@zig_sdk//libc_aware/toolchain/...",
)
Expand Down
4 changes: 2 additions & 2 deletions examples/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions fennel/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"Public API re-exports"

load(
"//fennel/private:fennel_library.bzl",
_fennel_library = "fennel_library",
)
load(
"//fennel/private:fennel_binary.bzl",
_fennel_binary = "fennel_binary",
)
load(
"//fennel/private:fennel_library.bzl",
_fennel_library = "fennel_library",
)

fennel_library = _fennel_library
fennel_binary = _fennel_binary
8 changes: 5 additions & 3 deletions fennel/private/fennel_binary.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
load("//lua/private:lua_binary.bzl", "BASH_RLOCATION_FUNCTION")
load("//lua:providers.bzl", "LuaLibrary")
load("//fennel:providers.bzl", "FennelLibrary")
"""Implementation of fennel_binary"""

load("@aspect_bazel_lib//lib:paths.bzl", "to_rlocation_path")
load("//fennel:providers.bzl", "FennelLibrary")
load("//lua:providers.bzl", "LuaLibrary")
load("//lua/private:lua_binary.bzl", "BASH_RLOCATION_FUNCTION")

def _fennel_binary_impl(ctx):
out_executable = ctx.actions.declare_file(ctx.attr.name + "_exec")
Expand Down
2 changes: 2 additions & 0 deletions fennel/providers.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Providers for fennel rules"""

FennelLibrary = provider(
doc = "fennel libs",
fields = {
Expand Down
7 changes: 0 additions & 7 deletions fennel/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ May be empty if the target_tool_path points to a locally installed tool binary."
},
)

# Avoid using non-normalized paths (workspace/../other_workspace/path)
def _to_manifest_path(ctx, file):
if file.short_path.startswith("../"):
return "external/" + file.short_path[3:]
else:
return ctx.workspace_name + "/" + file.short_path

def _fennel_toolchain_impl(ctx):
tool_files = ctx.attr.target_tool.files.to_list() + ctx.files.extra_tool_files
target_tool = ctx.attr.target_tool
Expand Down
14 changes: 13 additions & 1 deletion lua/0001-Add-install-target-v5.4.6.patch
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
add 'install' target
add 'install' target and build without readline

diff --git a/makefile b/makefile
index d46e650c..3e710bbf 100644
--- a/makefile
+++ b/makefile
@@ -70,9 +70,9 @@ LOCAL = $(TESTS) $(CWARNS)


# enable Linux goodies
-MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX -DLUA_USE_READLINE
+MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX
MYLDFLAGS= $(LOCAL) -Wl,-E
-MYLIBS= -ldl -lreadline
+MYLIBS= -ldl
Comment on lines +11 to +15

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might cause some problems but this speeds up the build a loooot



CC= gcc
@@ -134,6 +134,12 @@ echo:

$(ALL_O): makefile ltests.h
Expand Down
2 changes: 2 additions & 0 deletions lua/private/lua_binary.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Implementation of lua_binary"""

load("@aspect_bazel_lib//lib:paths.bzl", "to_rlocation_path", _default_location_function = "BASH_RLOCATION_FUNCTION")
load("//lua:providers.bzl", "LuaLibrary")

Expand Down
2 changes: 2 additions & 0 deletions lua/private/lua_library.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Implementation of lua_library"""

load("//lua:providers.bzl", "LuaLibrary")

def _lua_library_impl(ctx):
Expand Down
2 changes: 2 additions & 0 deletions lua/providers.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# FIXME: Most places that take a lualibrary as a dep should also allow taking a ccinfo and have paths set accordingly.

"""Providers for lua rules"""

LuaLibrary = provider(
doc = "Collection of lua files",
fields = {
Expand Down
21 changes: 21 additions & 0 deletions luaunit/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ module(
)

bazel_dep(name = "aspect_bazel_lib", version = "2.22.5")

bazel_dep(name = "rules_foreign_cc", version = "0.17.0", dev_dependency = True)

# Use the host make, as building it from source runs hundreds of slow autoconf check actions
foreign_cc_tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools", dev_dependency = True)
foreign_cc_tools.make(mode = "system")

bazel_dep(name = "hermetic_cc_toolchain", version = "4.3.0", dev_dependency = True)

toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains", dev_dependency = True)
use_repo(toolchains, "zig_sdk")

register_toolchains(
# Registered first so they win over the glibc 2.17 default
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain/...",
"@zig_sdk//libc_aware/toolchain/...",
dev_dependency = True,
)

bazel_dep(name = "rules_lua", version = "0.0.0")
local_path_override(
module_name = "rules_lua",
Expand Down
Loading