pull/13171/head
Josh Haberman 6 years ago
parent 9bb0814c48
commit 01ed4ce3d4
  1. 183
      BUILD
  2. 15
      WORKSPACE
  3. 100
      build_defs.bzl
  4. 102
      lua.BUILD

183
BUILD

@ -0,0 +1,183 @@
load(":build_defs.bzl", "lua_cclibrary", "lua_library", "lua_binary")
cc_library(
name = "upb",
srcs = [
"google/protobuf/descriptor.upb.c",
"upb/decode.c",
"upb/def.c",
"upb/encode.c",
"upb/handlers.c",
"upb/handlers-inl.h",
"upb/msg.c",
"upb/msgfactory.c",
"upb/port_def.inc",
"upb/port_undef.inc",
"upb/refcounted.c",
"upb/sink.c",
"upb/structdefs.int.h",
"upb/structs.int.h",
"upb/table.c",
"upb/table.int.h",
"upb/upb.c",
],
hdrs = [
"google/protobuf/descriptor.upb.h",
"upb/decode.h",
"upb/def.h",
"upb/encode.h",
"upb/handlers.h",
"upb/msg.h",
"upb/msgfactory.h",
"upb/refcounted.h",
"upb/sink.h",
"upb/upb.h",
],
)
cc_library(
name = "upb_descriptor",
srcs = [
"upb/descriptor/descriptor.upbdefs.c",
"upb/descriptor/reader.c",
],
hdrs = [
"upb/descriptor/descriptor.upbdefs.h",
"upb/descriptor/reader.h",
],
deps = [":upb"],
)
cc_library(
name = "upb_pb",
srcs = [
"upb/pb/compile_decoder.c",
"upb/pb/decoder.c",
"upb/pb/decoder.int.h",
"upb/pb/encoder.c",
"upb/pb/glue.c",
"upb/pb/textprinter.c",
"upb/pb/varint.c",
"upb/pb/varint.int.h",
],
hdrs = [
"upb/pb/decoder.h",
"upb/pb/encoder.h",
"upb/pb/glue.h",
"upb/pb/textprinter.h",
],
deps = [
":upb",
":upb_descriptor",
],
)
cc_library(
name = "upb_json",
srcs = [
"upb/json/parser.c",
"upb/json/printer.c",
],
hdrs = [
"upb/json/parser.h",
"upb/json/printer.h",
],
deps = [":upb"],
)
lua_cclibrary(
name = "lua/upb_c",
srcs = [
"upb/bindings/lua/def.c",
"upb/bindings/lua/msg.c",
"upb/bindings/lua/upb.c",
],
hdrs = [
"upb/bindings/lua/upb.h",
],
deps = [
"upb",
"upb_pb",
],
)
lua_library(
name = "lua/upb",
base = "upb/bindings/lua",
srcs = [
"upb/bindings/lua/upb.lua"
],
luadeps = [
"lua/upb_c",
],
)
lua_cclibrary(
name = "lua/upb/table_c",
srcs = [
"upb/bindings/lua/upb/table.c",
],
luadeps = [
"lua/upb_c",
],
deps = [
"upb",
],
)
lua_library(
name = "lua/upb/table",
base = "upb/bindings/lua",
srcs = [
"upb/bindings/lua/upb/table.lua",
],
luadeps = [
"lua/upb",
"lua/upb/table_c",
],
)
lua_cclibrary(
name = "lua/upb/pb_c",
srcs = [
"upb/bindings/lua/upb/pb.c",
],
luadeps = [
"lua/upb_c",
],
deps = [
"upb_pb",
],
)
lua_library(
name = "lua/upb/pb",
base = "upb/bindings/lua",
srcs = [
"upb/bindings/lua/upb/pb.lua",
],
luadeps = [
"lua/upb",
"lua/upb/pb_c",
],
)
lua_library(
name = "lua/upbc_lib",
base = "tools",
srcs = [
"tools/dump_cinit.lua",
"tools/make_c_api.lua",
],
luadeps = [
"lua/upb",
]
)
lua_binary(
name = "upbc",
main = "tools/upbc.lua",
luadeps = [
"lua/upbc_lib",
]
)

@ -0,0 +1,15 @@
workspace(name = "upb")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "lua",
build_file = "//:lua.BUILD",
sha256 = "b9e2e4aad6789b3b63a056d442f7b39f0ecfca3ae0f1fc0ae4e9614401b69f4b",
strip_prefix = "lua-5.2.4",
urls = [
"https://mirror.bazel.build/www.lua.org/ftp/lua-5.2.4.tar.gz",
"https://www.lua.org/ftp/lua-5.2.4.tar.gz",
],
)

@ -0,0 +1,100 @@
shell_find_runfiles = """
# --- begin runfiles.bash initialization ---
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
set -euo pipefail
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
if [[ -f "$0.runfiles_manifest" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
export RUNFILES_DIR="$0.runfiles"
fi
fi
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
else
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
exit 1
fi
# --- end runfiles.bash initialization ---
"""
def _librule(name):
return name + "_lib"
def lua_cclibrary(name, srcs, hdrs = [], deps = [], luadeps = []):
lib_rule = name + "_lib"
so_rule = "lib" + name + ".so"
so_file = _remove_prefix(name, "lua/") + ".so"
native.cc_library(
name = _librule(name),
hdrs = hdrs,
srcs = srcs,
deps = deps + [_librule(dep) for dep in luadeps] + ["@lua//:liblua_headers"],
)
native.cc_binary(
name = so_rule,
linkshared = True,
deps = [_librule(name)],
)
native.genrule(
name = name + "_copy",
srcs = [":" + so_rule],
outs = [so_file],
cmd = "cp $< $@",
)
native.filegroup(
name = name,
data = [so_file],
)
def _remove_prefix(str, prefix):
if not str.startswith(prefix):
fail("%s doesn't start with %s" % (str, prefix))
return str[len(prefix):]
def lua_library(name, srcs, base, luadeps = []):
outs = [_remove_prefix(src, base + "/") for src in srcs]
native.genrule(
name = name + "_copy",
srcs = srcs,
outs = outs,
cmd = "cp $(SRCS) $(@D)",
)
native.filegroup(
name = name,
data = outs + luadeps,
)
def lua_binary(name, main, luadeps=[]):
script = name + ".sh"
script_contents = (shell_find_runfiles + """
BASE=$(dirname $(rlocation upb/upb_c.so))
export LUA_CPATH="$BASE/?.so"
export LUA_PATH="$BASE/?.lua"
$(rlocation lua/lua) $(rlocation upb/tools/upbc.lua) "$@"
""").replace("$", "$$")
print(native.repository_name())
native.genrule(
name = "gen_" + name,
outs = [script],
cmd = "(cat <<'HEREDOC'\n%s\nHEREDOC\n) > $@" % script_contents,
)
native.sh_binary(
name = name,
srcs = [script],
data = ["@lua//:lua", "@bazel_tools//tools/bash/runfiles", main] + luadeps,
)

@ -0,0 +1,102 @@
package(
default_visibility = ["//visibility:public"],
)
cc_library(
name = "liblua_headers",
defines = ["LUA_USE_LINUX"],
hdrs = [
"src/lauxlib.h",
"src/lua.h",
"src/lua.hpp",
"src/luaconf.h",
"src/lualib.h",
],
includes = ["src"],
)
cc_library(
name = "liblua",
srcs = [
"src/lapi.c",
"src/lapi.h",
"src/lauxlib.c",
"src/lauxlib.h",
"src/lbaselib.c",
"src/lbitlib.c",
"src/lcode.c",
"src/lcode.h",
"src/lcorolib.c",
"src/lctype.c",
"src/lctype.h",
"src/ldblib.c",
"src/ldebug.c",
"src/ldebug.h",
"src/ldo.c",
"src/ldo.h",
"src/ldump.c",
"src/lfunc.c",
"src/lfunc.h",
"src/lgc.c",
"src/lgc.h",
"src/linit.c",
"src/liolib.c",
"src/llex.c",
"src/llex.h",
"src/llimits.h",
"src/lmathlib.c",
"src/lmem.c",
"src/lmem.h",
"src/loadlib.c",
"src/lobject.c",
"src/lobject.h",
"src/lopcodes.c",
"src/lopcodes.h",
"src/loslib.c",
"src/lparser.c",
"src/lparser.h",
"src/lstate.c",
"src/lstate.h",
"src/lstring.c",
"src/lstring.h",
"src/lstrlib.c",
"src/ltable.c",
"src/ltable.h",
"src/ltablib.c",
"src/ltm.c",
"src/ltm.h",
"src/lundump.c",
"src/lundump.h",
"src/lvm.c",
"src/lvm.h",
"src/lzio.c",
"src/lzio.h",
],
defines = ["LUA_USE_LINUX"],
hdrs = [
"src/lauxlib.h",
"src/lua.h",
"src/lua.hpp",
"src/luaconf.h",
"src/lualib.h",
],
includes = ["src"],
linkopts = [
"-lm",
"-ldl",
],
)
cc_binary(
name = "lua",
srcs = [
"src/lua.c",
],
deps = [
":liblua",
],
linkopts = [
"-lreadline",
"-rdynamic",
],
)
Loading…
Cancel
Save