Skip to content

Commit

Permalink
Merge pull request #36 from tweag/fd/simpler-rules
Browse files Browse the repository at this point in the history
Simplify clodl implementation
  • Loading branch information
facundominguez committed Dec 14, 2020
2 parents 21faa17 + 60959e7 commit 8c50fde
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 347 deletions.
72 changes: 42 additions & 30 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,81 +1,85 @@
package(default_visibility = ["//visibility:public"])

load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load(
"@rules_haskell//haskell:defs.bzl",
"haskell_binary",
"haskell_test",
"haskell_toolchain_library",
)
load(
"@io_tweag_clodl//clodl:clodl.bzl",
"library_closure",
"binary_closure",
"library_closure",
)
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

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

cc_library(
name = "bootstrap-bz",
srcs = ["src/main/cc/bootstrap.c"],
copts = ["-std=c99"],
deps = [
"@rules_haskell_ghc_nixpkgs//:include",
"@openjdk//:include",
"@rules_haskell_ghc_nixpkgs//:include",
],
)

cc_binary(
name = "libbootstrap.so",
deps = ["bootstrap-bz"],
linkshared = 1,
deps = ["bootstrap-bz"],
)

java_library(
name = "base-jar",
srcs = glob(["src/main/java/**/*.java"]),
)


haskell_toolchain_library(name = "base")

haskell_binary(
name = "hello-hs",
testonly = True,
linkstatic = False,
srcs = ["src/test/haskell/hello/Main.hs"],
compiler_flags = [
"-threaded",
"-pie",
"-optl-Wl,--dynamic-list=main-symbol-list.ld",
],
extra_srcs = ["main-symbol-list.ld"],
deps = [":base"],
linkstatic = False,
src_strip_prefix = "src/test/haskell/hello",
deps = [":base"],
)

library_closure(
name = "clotest",
testonly = True,
srcs = ["hello-hs", "libbootstrap.so"],
srcs = [
"hello-hs",
"libbootstrap.so",
],
excludes = [
"ld-linux-x86-64\.so.*",
"libgcc_s\.so.*",
"libc\.so.*",
"libdl\.so.*",
"libm\.so.*",
"libpthread\.so.*",
"ld-linux-x86-64\\.so.*",
"libgcc_s\\.so.*",
"libc\\.so.*",
"libdl\\.so.*",
"libm\\.so.*",
"libpthread\\.so.*",
],
outzip = "closure.zip",
)

binary_closure(
name = "clotestbin",
testonly = True,
src = "hello-hs",
excludes = [
"ld-linux-x86-64\.so.*",
"libgcc_s\.so.*",
"libc\.so.*",
"libdl\.so.*",
"libm\.so.*",
"libpthread\.so.*",
"ld-linux-x86-64\\.so.*",
"libgcc_s\\.so.*",
"libc\\.so.*",
"libdl\\.so.*",
"libm\\.so.*",
"libpthread\\.so.*",
],
)

Expand All @@ -89,16 +93,16 @@ java_binary(

cc_library(
name = "lib-cc",
srcs = ["src/test/cc/hello/lib.c"],
testonly = True,
srcs = ["src/test/cc/hello/lib.c"],
)

cc_binary(
name = "libhello-cc.so",
testonly = True,
srcs = ["src/test/cc/hello/main.c"],
deps = ["lib-cc"],
linkshared = 1,
testonly = True,
deps = ["lib-cc"],
)

binary_closure(
Expand All @@ -109,9 +113,9 @@ binary_closure(

cc_binary(
name = "libhello-cc-norunfiles.so",
testonly = True,
srcs = ["src/test/cc/hello/main.c"],
linkshared = 1,
testonly = True,
)

binary_closure(
Expand All @@ -122,10 +126,13 @@ binary_closure(

cc_binary(
name = "hello-cc-pie",
srcs = ["src/test/cc/hello/main.c"],
linkopts = ["-pie", "-Wl,--dynamic-list=main-symbol-list.ld"],
deps = ["main-symbol-list.ld"],
testonly = True,
srcs = ["src/test/cc/hello/main.c"],
linkopts = [
"-pie",
"-Wl,--dynamic-list=main-symbol-list.ld",
],
deps = ["main-symbol-list.ld"],
)

binary_closure(
Expand All @@ -138,3 +145,8 @@ sh_binary(
name = "deps",
srcs = ["src/main/bash/deps.sh"],
)

buildifier(
name = "buildifier",
lint_mode = "warn",
)
87 changes: 62 additions & 25 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,8 @@ http_archive(
urls = ["https://github.com/tweag/rules_haskell/archive/6604b8c19701a64986e98d475959ff2a2e8a1379.tar.gz"],
)

http_archive(
name = "org_nixos_patchelf",
build_file_content = """
cc_binary(
name = "patchelf",
srcs = ["src/patchelf.cc", "src/elf.h"],
copts = ["-DPAGESIZE=4096", '-DPACKAGE_STRING=\\\\"patchelf\\\\"'],
visibility = [ "//visibility:public" ],
)
""",
strip_prefix = "patchelf-1fa4d36fead44333528cbee4b5c04c207ce77ca4",
urls = ["https://github.com/NixOS/patchelf/archive/1fa4d36fead44333528cbee4b5c04c207ce77ca4.tar.gz"],
)

load("@rules_haskell//haskell:repositories.bzl", "haskell_repositories")

haskell_repositories()

load(
Expand Down Expand Up @@ -55,16 +42,6 @@ filegroup(

haskell_register_ghc_nixpkgs(
attribute_path = "haskell.compiler.ghc8102",
locale_archive = "@glibc_locales//:locale-archive",
repositories = {"nixpkgs": "@nixpkgs"},
version = "8.10.2",
compiler_flags = [
"-Werror",
"-Wall",
"-Wcompat",
"-Wincomplete-record-updates",
"-Wredundant-constraints",
],
build_file_content = """
package(default_visibility = [ "//visibility:public" ])
Expand All @@ -79,6 +56,16 @@ cc_library(
strip_include_prefix = glob(["lib/ghc-*/include"], exclude_directories=0)[0],
)
""",
compiler_flags = [
"-Werror",
"-Wall",
"-Wcompat",
"-Wincomplete-record-updates",
"-Wredundant-constraints",
],
locale_archive = "@glibc_locales//:locale-archive",
repositories = {"nixpkgs": "@nixpkgs"},
version = "8.10.2",
)

nixpkgs_package(
Expand All @@ -95,12 +82,62 @@ cc_library(
repository = "@nixpkgs",
)


http_archive(
name = "io_bazel_stardoc",
strip_prefix = "stardoc-0.4.0",
urls = ["https://github.com/bazelbuild/stardoc/archive/0.4.0.tar.gz"],
)

load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

##################################################################
# buildifier setup
##################################################################

# buildifier is written in Go and hence needs rules_go to be built.
# See https://github.com/bazelbuild/rules_go for the up to date setup instructions.
http_archive(
name = "io_bazel_rules_go",
sha256 = "d1ffd055969c8f8d431e2d439813e42326961d0942bdf734d2c95dc30c369566",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.24.5/rules_go-v0.24.5.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.24.5/rules_go-v0.24.5.tar.gz",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains()

http_archive(
name = "bazel_gazelle",
sha256 = "b85f48fa105c4403326e9525ad2b2cc437babaa6e15a3fc0b1dbab0ab064bc7c",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-master",
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

http_archive(
name = "com_github_bazelbuild_buildtools",
strip_prefix = "buildtools-master",
url = "https://github.com/bazelbuild/buildtools/archive/master.zip",
)

0 comments on commit 8c50fde

Please sign in to comment.