Skip to content

Commit

Permalink
First version (#1)
Browse files Browse the repository at this point in the history
* Added toolchain and examples

* Final touches for first release

* Update README

* minor fix
  • Loading branch information
jadarve authored May 19, 2022
1 parent 85f8d56 commit ea74671
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SublimeText
*.sublime-project
*.sublime-workspace

# Visual Studio Code
.vscode/

# Vulkan
*.spv

# Bazel
bazel-*

# CLion
.clwb/

local/

# Bazel
bazel-bin
bazel-rules_lua
bazel-out
bazel-testlogs
Empty file added BUILD
Empty file.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# rules_lua
Bazel rules for the Lua programming language

Bazel rules for using the [Lua language](https://www.lua.org/).

## Configuration

Include the following configuration in your project's `WORKSPACE` file.

```python
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "rules_lua",
remote = "https://github.com/jadarve/rules_lua.git",
tag = "v0.0.1"
)

load("@rules_lua//toolchains:repositories.bzl", "lua_repositories")
lua_repositories()
```

## Available targets

### Lua interpreter

It's possible to run the Lua interpreter directly:

```bash
bazel run @rules_lua//toolchains:lua
```

### Lua compiler

The compiler is avaialble as:

```bash
bazel run @rules_lua//toolchains:luac -- <compile options>
```

### Lua C library

Additionally, the C library is available as a dependency as `@rules_lua//cc:lua_cc_library`

## Examples

See the [examples](examples) folder to see how to use the rules.
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
workspace(
name = "rules_lua"
)
9 changes: 9 additions & 0 deletions cc/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
"""

alias(
name = "lua_cc_library",
# TODO: select according to target lua version
actual = "@remote_lua53_repository//:lua_cc_library",
visibility = ["//visibility:public"]
)
11 changes: 11 additions & 0 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
workspace(
name = "rules_lua_examples"
)

local_repository(
name = "rules_lua",
path = ".."
)

load("@rules_lua//toolchains:repositories.bzl", "lua_repositories")
lua_repositories()
14 changes: 14 additions & 0 deletions toolchains/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
"""

alias(
name = "lua",
# FIXME: select according to target lua version
actual = "@remote_lua53_repository//:lua"
)

alias(
name = "luac",
# FIXME: select according to target lua version
actual = "@remote_lua53_repository//:luac"
)
60 changes: 60 additions & 0 deletions toolchains/lua.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
"""

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_binary")

cc_library (
name = "lua_cc_library",
srcs = glob(
["src/*.c", "src/*.h", "src/*.hpp"],
exclude = ["src/lua.c", "src/luac.c"],
),
hdrs = glob(["src/*.h", "src/*.hpp"]),
strip_include_prefix = "src",
linkstatic = True,
local_defines = select({
"@platforms//os:linux": [
"LUA_USE_LINUX"
],
"//conditions:default": [
]
}),
visibility = ["//visibility:public"],
)

cc_binary (
name = "lua",
srcs = ["src/lua.c"],
deps = [
":lua_cc_library"
],
linkstatic = True,
linkopts = select({
"@platforms//os:linux": [
"-lm",
"-ldl"
],
"//conditions:default": [
]
}),
visibility = ["//visibility:public"],
)

cc_binary (
name = "luac",
srcs = ["src/luac.c"],
deps = [
":lua_cc_library"
],
linkstatic = True,
linkopts = select({
"@platforms//os:linux": [
"-lm",
"-ldl"
],
"//conditions:default": [

]
}),
visibility = ["//visibility:public"],
)
30 changes: 30 additions & 0 deletions toolchains/repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
"""

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


def lua_repositories():

maybe (
repo_rule = http_archive,
name = "remote_lua53_repository",
urls = [
"https://www.lua.org/ftp/lua-5.3.6.tar.gz"
],
sha256 = "fc5fd69bb8736323f026672b1b7235da613d7177e72558893a0bdcd320466d60",
strip_prefix = "lua-5.3.6",
build_file = "@rules_lua//toolchains:lua.BUILD",
)

maybe (
repo_rule = http_archive,
name = "remote_lua54_repository",
urls = [
"https://www.lua.org/ftp/lua-5.4.4.tar.gz"
],
sha256 = "164c7849653b80ae67bec4b7473b884bf5cc8d2dca05653475ec2ed27b9ebf61",
strip_prefix = "lua-5.4.4",
build_file = "@rules_lua//toolchains:lua.BUILD",
)

0 comments on commit ea74671

Please sign in to comment.