Skip to content

Commit

Permalink
bazel(checker): make it build and run on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 15, 2021
1 parent decf8ec commit b07c7cd
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 61 deletions.
31 changes: 25 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ nixpkgs_package(
repository = "@nixpkgs",
)

nixpkgs_package(
name = "zlib.dev",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "zlib.out",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "freetype.dev",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "freetype.out",
repository = "@nixpkgs",
)

# Python
nixpkgs_python_configure(
repository = "@nixpkgs",
Expand Down Expand Up @@ -176,11 +196,10 @@ load("@rules_jvm_external//:defs.bzl", "maven_install")

git_repository(
name = "rules_clojure",
commit = "11478580b9bb10e183af6da9bc1acc4d1524927f",
remote = "https://github.com/griffinbank/rules_clojure.git",
commit = "dbcaaa516e8cfcb32e51e80a838cf2be6bf93093",
remote = "https://github.com/stevana/rules_clojure.git",
)


load("@rules_clojure//:repositories.bzl", "rules_clojure_dependencies")
load("@rules_clojure//:toolchains.bzl", "rules_clojure_toolchains")

Expand All @@ -194,10 +213,10 @@ clojure_ws()
# GraalVM
http_archive(
name = "rules_graal",
sha256 = "ba3ece52c0c60acaceb09104a3ddc76c7bba076ae449331f7bc911b382499d3d",
strip_prefix = "rules_graal-d49695e245e0ca224476ec9c5b2ff3db4d0ccfd8",
sha256 = "543dcf9018d3b7c5ac7e73b6ad841b8c79d3e48e6dc0646f2abdc6163de5fc1d",
strip_prefix = "rules_graal-e7cfa9c762ea7e01cad77bb8904c5dab01f7e9a4",
urls = [
"https://github.com/stevana/rules_graal/archive/d49695e245e0ca224476ec9c5b2ff3db4d0ccfd8.zip",
"https://github.com/stevana/rules_graal/archive/e7cfa9c762ea7e01cad77bb8904c5dab01f7e9a4.zip",
],
)

Expand Down
18 changes: 8 additions & 10 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ sources ? import ./nix/sources.nix
, pkgs ? import sources.nixpkgs {}
, nix-build-checker ? true
, nix-build-checker ? false
, nix-build-scheduler ? false }:
with pkgs;

let
# TODO(stevan): remove these workarounds once checker (on both linux and
# macos) and scheduler builds with bazel (on macos).
checker = callPackage ./src/checker/default.nix {};
# TODO(stevan): remove these workarounds once checker and scheduler builds
# with bazel on macos.
checker = callPackage ./src/checker/default.nix {};
scheduler = callPackage ./src/scheduler/default.nix {};
in

Expand All @@ -20,7 +20,7 @@ stdenv.mkDerivation {
phases = [ "installPhase" "installCheckPhase" ];

propagatedBuildInputs = [ z3 ]
++ lib.optional nix-build-checker [ checker ]
++ lib.optional nix-build-checker [ checker ]
++ lib.optional nix-build-scheduler [ scheduler ];

installPhase = ''
Expand All @@ -33,20 +33,18 @@ stdenv.mkDerivation {
${if nix-build-checker then ''
install -D ${checker.out}/bin/detsys-checker $out/bin
'' else ''
# TODO(stevan): uncomment once checker builds with rules_graal
# install -D $src/checker/checker-bin \
# $out/bin/detsys-checker
install -D $src/checker/checker-bin $out/bin/detsys-checker
''
}
${if nix-build-scheduler then ''
install -D ${scheduler.out}/bin/detsys-scheduler $out/bin
'' else ''
install -D $src/scheduler/scheduler-bin \
$out/bin/detsys-scheduler
install -D $src/scheduler/scheduler-bin $out/bin/detsys-scheduler
''
}
install -D $src/ldfi2/ldfi2 \
$out/bin/detsys-ldfi
# TODO(stevan): generator
'';

doInstallCheck = true;
Expand Down
6 changes: 5 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ pkgs.mkShell {

zlib.dev
zlib.out
freetype.dev
pkgconfig # Use `pkg-config --libs zlib` from inside the shell to figure out
# what to pass to GraalVM's native-image.
];
] ++ lib.optionals stdenv.hostPlatform.isDarwin
[ darwin.apple_sdk.frameworks.Foundation
darwin.apple_sdk.frameworks.CoreFoundation
];
}
107 changes: 85 additions & 22 deletions src/checker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("@rules_clojure//:rules.bzl", "clojure_library", "clojure_binary")
load("@rules_clojure//:rules.bzl", "clojure_namespace", "clojure_library", "clojure_binary")
load("@rules_clojure//:toolchains.bzl", "clojure_toolchain")
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_graal//graal:graal.bzl", "graal_binary")

clojure_toolchain(
name = "clojure_toolchain_def",
Expand All @@ -20,26 +22,87 @@ java_library(
name = "lockfix",
srcs = ["java/src/lockfix/LockFix.java"],
deps = ["@maven//:org_clojure_clojure"],
visibility = ["//src/checker:__subpackages__"],
)

#clojure_library(
# name = "checker-lib",
# srcs = glob([
# "src/**/*.clj",
# ]),
# deps = [
# "@maven//:elle_elle",
# "@maven//:spootnik_unilog",
# "@maven//:me_raynes_fs",
# "@maven//:seancorfield_next_jdbc",
# "@maven//:org_xerial_sqlite_jdbc",
# "@maven//:metosin_jsonista",
# ":lockfix",
# ]
#)
#
#clojure_binary(
# name = "checker",
# main = "checker.core",
# deps = [":checker-lib"],
#)
# TODO(stevan): figure out how or if we can depending on these cc libraries in
# the graal_binary so we don't have to pass the paths explicitly.
cc_library(
name = "zlib",
srcs = ["@zlib.out//:lib"],
hdrs = ["@zlib.dev//:include"],
strip_include_prefix = "/include",
linkstatic=1,
)

cc_library(
name = "freetype",
#srcs = ["@freetype.out//:lib"],
#hdrs = ["@freetype.dev//:include/freetype"],
strip_include_prefix = "/include/freetype",
linkstatic=1,
)

clojure_library(
name = "checker-lib",
srcs = ["//src/checker/src/checker:checker-ns"],
aot = ["checker.core"],
javacopts = [
"-Djava.awt.headless=true",
],
compiledeps = [":zlib", ":freetype", "@rules_clojure//src/rules_clojure:jar"],
)

graal_binary(
name = "checker",
deps = [":checker-lib"],
reflection_configuration = "native-image/reflection-config.json",
jni_configuration = "native-image/jni-config.json",
main_class = "checker.core",
initialize_at_build_time = [
"org.sqlite.JDBC",
"org.sqlite.core.DB$ProgressObserver",
"org.sqlite.core.DB",
"org.sqlite.core.NativeDB",
"org.sqlite.ProgressHandler",
"org.sqlite.Function",
"org.sqlite.Function$Aggregate",
"org.sqlite.Function$Window",
],

graal_extra_args = [
# TODO(stevan): figure out how a better way to get these paths:
"-H:CCompilerOption=-L/nix/store/7bgshg2z70fpcc7adxfag1lgf45yamxh-zlib-1.2.11/lib",
"-H:CLibraryPath=/nix/store/06ymz7xipyybjn1pmxcpn3zzbm1bxk50-freetype-2.10.4/lib",
"-H:+ReportExceptionStackTraces",
"-H:IncludeResources='db/.*|static/.*|templates/.*|.*.yml|.*.xml|.*/org/sqlite/.*|org/sqlite/.*'",
"-J-Dclojure.spec.skip-macros=true",
"-J-Dclojure.compiler.direct-linking=true",
"-J-Dfile.encoding=UTF-8",
"-J-Djava.awt.headless=true",
"-J-Dclojure.tools.logging.factory=clojure.tools.logging.impl/slf4j-factory",
"--initialize-at-build-time",
"--initialize-at-run-time=sun.font.SunFontManager",
"--initialize-at-run-time=sun.font.StrikeCache",
"--initialize-at-run-time=sun.font.SunLayoutEngine",
"--initialize-at-run-time=sun.font.FontManagerNativeLibrary",
"--initialize-at-run-time=javax.imageio.ImageTypeSpecifier",
"--initialize-at-run-time=sun.java2d.SurfaceData",
"--initialize-at-run-time=com.sun.imageio.plugins.jpeg.JPEG$JCS",
"--initialize-at-run-time=sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher",
"--initialize-at-run-time=sun.awt.X11GraphicsConfig",
"--initialize-at-run-time=sun.awt.X11.MotifDnDConstants",
"--initialize-at-run-time=sun.java2d.xr.XRBackendNative",
"--initialize-at-run-time=sun.awt.X11.XWM",
"--initialize-at-run-time=sun.awt.X11.XSelection",
"--initialize-at-run-time=sun.awt.X11.XDnDConstants",
"--initialize-at-run-time=sun.awt.X11.WindowPropertyGetter",
"--initialize-at-run-time=sun.awt.X11InputMethodBase",
"--initialize-at-run-time=sun.awt.X11.XWindow",
"--report-unsupported-elements-at-runtime",
"--allow-incomplete-classpath",
"--verbose",
"--no-fallback",
"--no-server",
],
)
20 changes: 20 additions & 0 deletions src/checker/src/checker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@rules_clojure//:rules.bzl", "clojure_namespace")

clojure_namespace(
name = "checker-ns",
srcs = {"core.clj": "/checker/core.clj",
"db.clj": "/checker/db.clj",
"json.clj": "/checker/json.clj",
},
deps = [
"@maven//:elle_elle",
"@maven//:spootnik_unilog",
"@maven//:me_raynes_fs",
"@maven//:seancorfield_next_jdbc",
"@maven//:org_clojure_clojure",
"@maven//:org_xerial_sqlite_jdbc",
"@maven//:metosin_jsonista",
"//src/checker:lockfix",
],
visibility = ["//src/checker:__subpackages__"],
)
1 change: 1 addition & 0 deletions src/debugger/cmd/detsys-debug/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_binary(
name = "detsys-debug",
embed = [":detsys-debug_lib"],
gotags = ["json1"],
visibility = ["//visibility:public"],
)

Expand Down
42 changes: 20 additions & 22 deletions src/scheduler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ load("@rules_clojure//:toolchains.bzl", "clojure_toolchain")
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_graal//graal:graal.bzl", "graal_binary")

java_library(
name = "lockfix",
srcs = ["java/src/lockfix/LockFix.java"],
deps = ["@maven//:org_clojure_clojure"],
visibility = ["//src/scheduler:__subpackages__"],
)

clojure_toolchain(
name = "clojure_toolchain_def",
classpath = [
Expand All @@ -25,27 +18,30 @@ toolchain(
toolchain_type = "@rules_clojure//:toolchain",
)

java_library(
name = "lockfix",
srcs = ["java/src/lockfix/LockFix.java"],
deps = ["@maven//:org_clojure_clojure"],
visibility = ["//src/scheduler:__subpackages__"],
)

cc_library(
name = "zlib",
srcs = ["@zlib.out//:lib"],
hdrs = ["@zlib.dev//:include"],
strip_include_prefix = "/include",
linkstatic=1,
)

clojure_library(
name = "scheduler-lib",
srcs = ["//src/scheduler/src/scheduler:scheduler-ns"],
aot = ["scheduler.core"],
compiledeps = [":zlib", "@rules_clojure//src/rules_clojure:jar"],
)

clojure_binary(
name = "scheduler",
deps = [":scheduler-lib"],
main_class = "scheduler.core",
)

#cc_library(
#name = "zlib",
#srcs = ["@zlib//:lib"],
#hdrs = ["@zlib//:include"],
#strip_include_prefix = "/include",
#)

graal_binary(
name = "scheduler-native",
name = "scheduler",
deps = [":scheduler-lib"],
reflection_configuration = "native-image/reflection-config.json",
jni_configuration = "native-image/jni-config.json",
Expand All @@ -61,7 +57,9 @@ graal_binary(
"org.sqlite.Function$Window",
],
graal_extra_args = [
# TODO(stevan): figure out how a better way to get this path:
# TODO(stevan): figure out how a better way to get the following path.
# I think the problem is that $location doesn't work inside
# graal_extra_args.
"-H:CCompilerOption=-L/nix/store/7bgshg2z70fpcc7adxfag1lgf45yamxh-zlib-1.2.11/lib",
"-H:+ReportExceptionStackTraces",
"-H:-CheckToolchain", # Needed for MacOS.
Expand Down

0 comments on commit b07c7cd

Please sign in to comment.