From 3213dd135d383486555ca22a018e0d7201370cb7 Mon Sep 17 00:00:00 2001 From: Stevan Andjelkovic Date: Wed, 3 Feb 2021 17:09:04 +0100 Subject: [PATCH] bazel: add initial nix support --- .bazelrc | 8 +++++-- WORKSPACE | 39 +++++++++++++++++++++++++++++-- gazelle-ws.bzl | 38 ++++++++++++++++++++---------- src/debugger/internal/BUILD.bazel | 16 +++++++++---- src/executor/BUILD.bazel | 7 ------ src/executor/executor_test.go | 2 +- src/lib/BUILD.bazel | 2 +- src/logger/BUILD.bazel | 14 ++++------- 8 files changed, 87 insertions(+), 39 deletions(-) diff --git a/.bazelrc b/.bazelrc index e0337fcc..2470f0d4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,2 +1,6 @@ -build --action_env=GOPRIVATE=github.com/symbiont-io -run --action_env=GOPRIVATE=github.com/symbiont-io \ No newline at end of file +build --action_env=GOPRIVATE=github.com/symbiont-io \ + --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host \ + --crosstool_top=@local_config_cc//:toolchain +run --action_env=GOPRIVATE=github.com/symbiont-io \ + --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host \ + --crosstool_top=@local_config_cc//:toolchain \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE index 2eab40dd..7eb4fa5c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -2,6 +2,39 @@ workspace(name = "detsys_workspace") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +# Nix +http_archive( + name = "io_tweag_rules_nixpkgs", + strip_prefix = "rules_nixpkgs-0.7.0", + urls = ["https://github.com/tweag/rules_nixpkgs/archive/v0.7.0.tar.gz"], +) + +load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies") +rules_nixpkgs_dependencies() + +load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", + "nixpkgs_cc_configure", + "nixpkgs_git_repository", + "nixpkgs_package", + "nixpkgs_python_configure", +) + +# Same revision as we pinned with niv in nix/sources.json. For ticket to add +# niv support, see https://github.com/tweag/rules_nixpkgs/issues/127 . +nixpkgs_git_repository( + name = "nixpkgs", + revision = "cf7475d2061ac3ada4b226571a4a1bb91420b578", + sha256 = "a68da1275af117cf314305aeb86cc9f1cacfa68c8b984efd68ac473d3e4bf6f3" +) + +nixpkgs_cc_configure(repository = "@nixpkgs//:default.nix") + +nixpkgs_python_configure( + python3_attribute_path = "python3", + repository = "@nixpkgs//:default.nix", +) + +# Golang http_archive( name = "io_bazel_rules_go", sha256 = "6f111c57fd50baf5b8ee9d63024874dd2a014b069426156c55adbf6d3d22cb7b", @@ -24,6 +57,10 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") +# Use go from nixpkgs. +load("@io_tweag_rules_nixpkgs//nixpkgs:toolchains/go.bzl", "nixpkgs_go_configure") +nixpkgs_go_configure(repository = "@nixpkgs//:default.nix") + go_rules_dependencies() # gazelle will put stuff here @@ -33,6 +70,4 @@ load("//:gazelle-ws.bzl", "gazelle_ws") # gazelle:repository_macro gazelle-ws.bzl%gazelle_ws gazelle_ws() -go_register_toolchains(version = "1.15.5") - gazelle_dependencies() diff --git a/gazelle-ws.bzl b/gazelle-ws.bzl index 28dc2d46..fc97554e 100644 --- a/gazelle-ws.bzl +++ b/gazelle-ws.bzl @@ -25,6 +25,13 @@ def gazelle_ws(): sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=", version = "v0.0.0-20151022065526-2efee857e7cf", ) + go_repository( + name = "com_github_andreyvit_diff", + importpath = "github.com/andreyvit/diff", + sum = "h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=", + version = "v0.0.0-20170406064948-c7f18ee00883", + ) + go_repository( name = "com_github_apache_thrift", importpath = "github.com/apache/thrift", @@ -827,8 +834,8 @@ def gazelle_ws(): go_repository( name = "com_github_mattn_go_runewidth", importpath = "github.com/mattn/go-runewidth", - sum = "h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=", - version = "v0.0.4", + sum = "h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=", + version = "v0.0.9", ) go_repository( name = "com_github_mattn_go_sqlite3", @@ -1178,6 +1185,13 @@ def gazelle_ws(): sum = "h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=", version = "v0.0.0-20170313163322-e2103e2c3529", ) + go_repository( + name = "com_github_sergi_go_diff", + importpath = "github.com/sergi/go-diff", + sum = "h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=", + version = "v1.1.0", + ) + go_repository( name = "com_github_shopify_sarama", importpath = "github.com/Shopify/sarama", @@ -1400,8 +1414,8 @@ def gazelle_ws(): go_repository( name = "in_gopkg_check_v1", importpath = "gopkg.in/check.v1", - sum = "h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=", - version = "v1.0.0-20180628173108-788fd7840127", + sum = "h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=", + version = "v1.0.0-20190902080502-41f04d3bba15", ) go_repository( name = "in_gopkg_cheggaaa_pb_v1", @@ -1461,8 +1475,8 @@ def gazelle_ws(): go_repository( name = "in_gopkg_yaml_v2", importpath = "gopkg.in/yaml.v2", - sum = "h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=", - version = "v2.2.2", + sum = "h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=", + version = "v2.2.4", ) go_repository( name = "io_etcd_go_bbolt", @@ -1579,14 +1593,14 @@ def gazelle_ws(): go_repository( name = "org_golang_x_sys", importpath = "golang.org/x/sys", - sum = "h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=", - version = "v0.0.0-20190412213103-97732733099d", + sum = "h1:XtNJkfEjb4zR3q20BBBcYUykVOEMgZeIUOpBPfNYgxg=", + version = "v0.0.0-20201017003518-b09fb700fbb7", ) go_repository( name = "org_golang_x_text", importpath = "golang.org/x/text", - sum = "h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=", - version = "v0.3.0", + sum = "h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=", + version = "v0.3.3", ) go_repository( name = "org_golang_x_time", @@ -1598,8 +1612,8 @@ def gazelle_ws(): go_repository( name = "org_golang_x_tools", importpath = "golang.org/x/tools", - sum = "h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=", - version = "v0.0.0-20191029190741-b9c20aec41a5", + sum = "h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=", + version = "v0.0.0-20180917221912-90fa682c2a6e", ) go_repository( name = "org_golang_x_xerrors", diff --git a/src/debugger/internal/BUILD.bazel b/src/debugger/internal/BUILD.bazel index 7995a056..86f6d11a 100644 --- a/src/debugger/internal/BUILD.bazel +++ b/src/debugger/internal/BUILD.bazel @@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "internal", - srcs = ["debugger.go"], + srcs = [ + "debugger.go", + "sequence.go", + ], importpath = "github.com/symbiont-io/detsys-testkit/src/debugger/internal", visibility = ["//src/debugger:__subpackages__"], deps = [ @@ -10,13 +13,18 @@ go_library( "@com_github_evanphx_json_patch//:json-patch", "@com_github_mattn_go_sqlite3//:go-sqlite3", "@com_github_nsf_jsondiff//:jsondiff", - "@com_github_andreyvit_diff//:diff", ], ) go_test( name = "internal_test", - srcs = ["debugger_test.go" "sequence_test.go"], + srcs = [ + "debugger_test.go", + "sequence_test.go", + ], embed = [":internal"], - deps = ["//src/lib"], + deps = [ + "//src/lib", + "@com_github_andreyvit_diff//:diff", + ], ) diff --git a/src/executor/BUILD.bazel b/src/executor/BUILD.bazel index d62569c8..ad8b6495 100644 --- a/src/executor/BUILD.bazel +++ b/src/executor/BUILD.bazel @@ -12,18 +12,11 @@ go_library( deps = [ "//src/lib", "@com_github_evanphx_json_patch//:json-patch", - "@com_github_mattn_go_sqlite3//:go-sqlite3", "@org_uber_go_zap//:zap", "@org_uber_go_zap//zapcore", ], ) -go_test( - name = "lib_test", - srcs = ["executor_test.go"], - embed = [":executor"], -) - go_test( name = "executor_test", srcs = ["executor_test.go"], diff --git a/src/executor/executor_test.go b/src/executor/executor_test.go index 8ec666d2..f2f76891 100644 --- a/src/executor/executor_test.go +++ b/src/executor/executor_test.go @@ -170,7 +170,7 @@ func TestSchedulerContractFault(t *testing.T) { func TestSchedulerContractOutput(t *testing.T) { output := []lib.OutEvent{ lib.OutEvent{ - To: "client:0", + To: lib.Singleton("client:0"), Args: &lib.ClientResponse{ Id: 0, Response: Value{1}, diff --git a/src/lib/BUILD.bazel b/src/lib/BUILD.bazel index 5555c8de..c14c3e1f 100644 --- a/src/lib/BUILD.bazel +++ b/src/lib/BUILD.bazel @@ -9,8 +9,8 @@ go_library( "ldfi.go", "lib.go", "marshaler.go", - "topology.go", "scheduler.go", + "topology.go", "util.go", ], importpath = "github.com/symbiont-io/detsys-testkit/src/lib", diff --git a/src/logger/BUILD.bazel b/src/logger/BUILD.bazel index 102f083d..f510a183 100644 --- a/src/logger/BUILD.bazel +++ b/src/logger/BUILD.bazel @@ -1,17 +1,11 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") - -go_binary( - name = "logger", - embed = [":logger_lib"], - visibility = ["//visibility:public"], -) +load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "logger_lib", - srcs = ["main.go"], + srcs = ["lib.go"], importpath = "github.com/symbiont-io/detsys-testkit/src/logger", visibility = ["//visibility:private"], deps = [ - "@com_github_mattn_go_sqlite3//:go-sqlite3", + "//src/lib", ], -) \ No newline at end of file +)