Skip to content
Permalink
Browse files
Add Bazel build rules for cloudlibc.
This change adds a couple of publicly visible build targets:

- //src/libc: The C library itself. It depends on separate libraries
  stored in the individual subdirectories
- //src/crt: The C runtime files. This library is currently declared
  incorrectly. The crtbegin.o and crtend.o files should be treated
  differently. This will be fixed later.
- //src/include: The standard C header files. These are stored in a
  filegroup() that may be used by the Bazel toolchain definitions.
- //src/libc/testing:testing_main: The program_main() function for
  executing unit tests. We should eventually move this into a separate
  repository.
  • Loading branch information
EdSchouten committed Jan 5, 2019
1 parent 88c3fcc commit 04a34ca2ead2408dde759395cc370b373ce8ed64
Show file tree
Hide file tree
Showing 75 changed files with 2,527 additions and 0 deletions.
@@ -0,0 +1,4 @@
build --compiler=clang
build --cpu=x86_64-unknown-cloudabi
build --crosstool_top=@org_cloudabi_bazel_toolchains_cloudabi//:toolchain
build --extra_toolchains=@org_cloudabi_bazel_toolchains_cloudabi//:cc-toolchain-x86_64-unknown-cloudabi
@@ -3,3 +3,4 @@
*.rej
.*.swp
/_obj/
/bazel-*
@@ -0,0 +1,11 @@
workspace(name = "org_cloudabi_cloudlibc")

# TODO(ed): Use a toolchain stored in Git.
local_repository(
name = "org_cloudabi_bazel_toolchains_cloudabi",
path = "/home/ed/projects/bazel-toolchains-cloudabi",
)

load("@org_cloudabi_bazel_toolchains_cloudabi//:toolchains.bzl", "toolchains_cloudabi_dependencies")

toolchains_cloudabi_dependencies()
@@ -0,0 +1,7 @@
cc_library(
name = "common",
hdrs = glob(["*.h"]),
include_prefix = "common",
visibility = ["//:__subpackages__"],
deps = ["@org_cloudabi_cloudabi//headers:cloudabi_syscalls"],
)
@@ -0,0 +1,21 @@
# TODO(ed): crtbegin.c and crtend.o should be linked as the first and
# last object files, respectively.
cc_library(
name = "crt",
srcs = [
"crt0.c",
"crtbegin.c",
"crtend.c",
],
copts = [
"-ffreestanding",
"-fno-sanitize=safe-stack",
"-fno-stack-protector",
],
visibility = ["//visibility:public"],
deps = [
"//src/common",
"@org_cloudabi_argdata//:argdata_impl",
"@org_cloudabi_cloudabi//headers:cloudabi_syscalls_info",
],
)
@@ -0,0 +1,5 @@
filegroup(
name = "include",
srcs = glob(["**/*.h"]),
visibility = ["//visibility:public"],
)
@@ -0,0 +1,68 @@
cc_library(
name = "libc",
visibility = ["//visibility:public"],
deps = [
"//src/libc/aeabi",
"//src/libc/arpa/inet",
"//src/libc/assert",
"//src/libc/complex",
"//src/libc/ctype",
"//src/libc/dirent",
"//src/libc/dlfcn",
"//src/libc/errno",
"//src/libc/execinfo",
"//src/libc/fcntl",
"//src/libc/fenv",
"//src/libc/float10",
"//src/libc/fmtmsg",
"//src/libc/fnmatch",
"//src/libc/iconv",
"//src/libc/inttypes",
"//src/libc/langinfo",
"//src/libc/libgen",
"//src/libc/libintl",
"//src/libc/link",
"//src/libc/locale",
"//src/libc/math",
"//src/libc/monetary",
"//src/libc/mqueue",
"//src/libc/net/if",
"//src/libc/netdb",
"//src/libc/netinet/in",
"//src/libc/poll",
"//src/libc/program",
"//src/libc/pthread",
"//src/libc/regex",
"//src/libc/sched",
"//src/libc/search",
"//src/libc/semaphore",
"//src/libc/setjmp",
"//src/libc/signal",
"//src/libc/stack_chk",
"//src/libc/stdatomic",
"//src/libc/stdio",
"//src/libc/stdlib",
"//src/libc/string",
"//src/libc/strings",
"//src/libc/sys/capsicum",
"//src/libc/sys/ioctl",
"//src/libc/sys/mman",
"//src/libc/sys/resource",
"//src/libc/sys/select",
"//src/libc/sys/socket",
"//src/libc/sys/stat",
"//src/libc/sys/time",
"//src/libc/sys/times",
"//src/libc/sys/uio",
"//src/libc/sys/utsname",
"//src/libc/syslog",
"//src/libc/testing",
"//src/libc/threads",
"//src/libc/time",
"//src/libc/uchar",
"//src/libc/unistd",
"//src/libc/uv",
"//src/libc/wchar",
"//src/libc/wctype",
],
)
@@ -0,0 +1,9 @@
cc_library(
name = "aeabi",
srcs = [
"aeabi_impl.h",
"aeabi_unwind_cpp_pr0.c",
"aeabi_unwind_cpp_pr1.c",
],
visibility = ["//src/libc:__pkg__"],
)
@@ -0,0 +1,16 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in [
"argdata_create_fd",
"argdata_create_float",
"argdata_create_int",
"argdata_create_timestamp",
"argdata_print_yaml",
"argdata_reader_pull",
"argdata_serialize",
"argdata_writer_push",
]]
@@ -0,0 +1,30 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

cc_library(
name = "inet",
srcs = [
"htonl.c",
"htons.c",
"inet_aton.c",
"inet_ntop.c",
"inet_pton.c",
"ntohl.c",
"ntohs.c",
],
visibility = ["//src/libc:__pkg__"],
deps = ["//src/common"],
)

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in [
"htonl",
"htons",
"inet_aton",
"inet_ntop",
"inet_pton",
"ntohl",
"ntohs",
]]
@@ -0,0 +1,13 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

cc_library(
name = "assert",
srcs = ["assertion_failed.c"],
visibility = ["//src/libc:__pkg__"],
)

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in ["assert"]]
@@ -0,0 +1,20 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

cc_library(
name = "complex",
srcs = [
"cimag.c",
"cimagf.c",
"cimagl.c",
"creal.c",
"crealf.c",
"creall.c",
],
visibility = ["//src/libc:__pkg__"],
)

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in ["complex"]]
@@ -0,0 +1,45 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

cc_library(
name = "ctype",
srcs = [
"ctype_impl.h",
"isalnum.c",
"isalnum_l.c",
"isalpha.c",
"isalpha_l.c",
"isascii.c",
"isblank.c",
"isblank_l.c",
"iscntrl.c",
"iscntrl_l.c",
"isdigit.c",
"isdigit_l.c",
"isgraph.c",
"isgraph_l.c",
"islower.c",
"islower_l.c",
"isprint.c",
"isprint_l.c",
"ispunct.c",
"ispunct_l.c",
"isspace.c",
"isspace_l.c",
"isupper.c",
"isupper_l.c",
"isxdigit.c",
"isxdigit_l.c",
"tolower.c",
"tolower_l.c",
"toupper.c",
"toupper_l.c",
],
visibility = ["//src/libc:__pkg__"],
deps = ["//src/common"],
)

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in ["ctype"]]
@@ -0,0 +1,37 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

cc_library(
name = "dirent",
srcs = [
"alphasort.c",
"closedir.c",
"dirent_impl.h",
"dirfd.c",
"fdclosedir.c",
"fdopendir.c",
"opendirat.c",
"readdir.c",
"rewinddir.c",
"scandirat.c",
"seekdir.c",
"telldir.c",
"versionsort.c",
],
visibility = ["//src/libc:__pkg__"],
deps = ["//src/common"],
)

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in [
"alphasort",
"dirfd",
"fdopendir",
"opendirat",
"rewinddir",
"scandirat",
"seekdir",
"versionsort",
]]
@@ -0,0 +1,14 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

cc_library(
name = "dlfcn",
srcs = ["dladdr.c"],
visibility = ["//src/libc:__pkg__"],
deps = ["//src/common"],
)

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in ["dladdr"]]
@@ -0,0 +1,6 @@
cc_library(
name = "errno",
srcs = ["errno.c"],
visibility = ["//src/libc:__pkg__"],
deps = ["@org_cloudabi_cloudabi//headers:cloudabi_types"],
)
@@ -0,0 +1,22 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

cc_library(
name = "execinfo",
srcs = [
"backtrace.c",
"backtrace_symbols.c",
"backtrace_symbols_fd.c",
"execinfo_impl.h",
],
visibility = ["//src/libc:__pkg__"],
)

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in [
"backtrace",
"backtrace_symbols",
"backtrace_symbols_fd",
]]
@@ -0,0 +1,24 @@
load("@org_cloudabi_bazel_toolchains_cloudabi//:cc.bzl", "cc_test_cloudabi")

cc_library(
name = "fcntl",
srcs = [
"fcntl.c",
"openat.c",
"posix_fadvise.c",
"posix_fallocate.c",
],
visibility = ["//src/libc:__pkg__"],
deps = ["//src/common"],
)

[cc_test_cloudabi(
name = test + "_test",
srcs = [test + "_test.c"],
deps = ["//src/libc/testing:testing_main"],
) for test in [
"fcntl",
"openat",
"posix_fadvise",
"posix_fallocate",
]]

0 comments on commit 04a34ca

Please sign in to comment.