This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bazel files for building asterius binaries (#888)
Co-authored-by: Yves-Stan Le Cornec <yves.stan.lecornec@tweag.io>
- Loading branch information
Showing
15 changed files
with
562 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# User Configuration | ||
# ------------------ | ||
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host | ||
run --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host | ||
|
||
# We make use of ctx.actions.declare_symlink in bazel/bazel_utils/cabal_filegroup.bzl | ||
build --experimental_allow_unresolved_symlinks | ||
|
||
build --incompatible_enable_cc_toolchain_resolution | ||
|
||
build:ci --repository_cache=~/repo-cache/ | ||
|
||
try-import %workspace%/.bazelrc.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: shell | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
env: | ||
# Bump this number to invalidate the GH actions cache | ||
cache-version: 0 | ||
|
||
jobs: | ||
|
||
shell: | ||
name: bazel-${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
steps: | ||
|
||
- name: checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Mount Bazel cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/repo-cache | ||
key: repo-cache-nixpkgs-${{ env.cache-version }} | ||
|
||
- name: setup-nix | ||
uses: cachix/install-nix-action@v16 | ||
with: | ||
extra_nix_config: | | ||
substituters = https://cache.nixos.org https://hydra.iohk.io | ||
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= | ||
install_url: https://releases.nixos.org/nix/nix-2.3.16/install | ||
|
||
- name: setup-cachix | ||
uses: cachix/cachix-action@v10 | ||
with: | ||
name: asterius | ||
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' | ||
|
||
- name: cachix-watch-store | ||
run: | | ||
cachix watch-store -c9 -j2 asterius & | ||
- name: Bazel build | ||
run: | | ||
nix-shell bazel/nix/bazel_build_shell.nix --pure --run ' | ||
set -euo pipefail | ||
bazel build //asterius:binaries --config=ci | ||
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,6 @@ cabal.project.local | |
|
||
sysroot | ||
|
||
/bazel-* | ||
.bazelrc.local | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
workspace(name = "bazel_asterius") | ||
|
||
# This commit must be the same as the one from bazel/stack.yaml | ||
|
||
HASKELL_BINARYEN_COMMIT = "7d0ea214e47946fc830d332a6e3e1b73f60f61fd" | ||
|
||
###################### | ||
# BAZEL DEPENDENCIES # | ||
###################### | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load( | ||
"@bazel_tools//tools/build_defs/repo:git.bzl", | ||
"git_repository", | ||
"new_git_repository", | ||
) | ||
|
||
git_repository( | ||
name = "rules_haskell", | ||
commit = "26a966abf7328b08c449c682f07d0e00e6f14466", | ||
remote = "https://github.com/tweag/rules_haskell.git", | ||
shallow_since = "1641820378 +0000", | ||
) | ||
|
||
load("@rules_haskell//haskell:repositories.bzl", "rules_haskell_dependencies") | ||
|
||
rules_haskell_dependencies() | ||
|
||
load( | ||
"@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", | ||
"nixpkgs_cc_configure", | ||
"nixpkgs_local_repository", | ||
"nixpkgs_package", | ||
"nixpkgs_python_configure", | ||
"nixpkgs_sh_posix_configure", | ||
) | ||
|
||
# Setup the posix toolchain | ||
http_archive( | ||
name = "rules_sh", | ||
sha256 = "83a065ba6469135a35786eb741e17d50f360ca92ab2897857475ab17c0d29931", | ||
strip_prefix = "rules_sh-0.2.0", | ||
urls = ["https://github.com/tweag/rules_sh/archive/v0.2.0.tar.gz"], | ||
) | ||
|
||
load("@rules_sh//sh:repositories.bzl", "rules_sh_dependencies") | ||
|
||
rules_sh_dependencies() | ||
|
||
##################### | ||
# Setup toolchains # | ||
##################### | ||
|
||
nixpkgs_local_repository( | ||
name = "nixpkgs", | ||
nix_file = "//bazel/nix:bazel_deps.nix", | ||
nix_file_deps = [ | ||
"//nix:sources.nix", | ||
"//nix:binaryen.nix", | ||
"//nix:binaryen.patch", | ||
"//nix:wasi-sdk.nix", | ||
"//nix:sources.json", | ||
"//ghc-toolkit:cbits/ghc_constants.c", | ||
"//nix:ghcconstants.nix", | ||
], | ||
) | ||
|
||
nixpkgs_sh_posix_configure(repository = "@nixpkgs") | ||
|
||
nixpkgs_cc_configure(repository = "@nixpkgs") | ||
|
||
nixpkgs_python_configure(repository = "@nixpkgs") | ||
|
||
load("@rules_haskell//haskell:nixpkgs.bzl", "haskell_register_ghc_nixpkgs") | ||
|
||
haskell_register_ghc_nixpkgs( | ||
attribute_path = "ghc", | ||
repository = "@nixpkgs", | ||
version = "8.10.7", | ||
) | ||
|
||
############################################## | ||
# External dependencies specific to asterius # | ||
############################################## | ||
|
||
# We recover the binaryen C library through nix | ||
nixpkgs_package( | ||
name = "binaryen_dev", | ||
attribute_path = "binaryen", | ||
build_file_content = """ | ||
load("@rules_cc//cc:defs.bzl", "cc_library") | ||
filegroup( | ||
name = "include", | ||
srcs = glob(["include/*.h"]), | ||
visibility = ["//visibility:public"], | ||
) | ||
filegroup( | ||
name = "binaryen", | ||
srcs = glob(["lib/*.so", "lib/*.a"]), | ||
visibility = ["//visibility:public"], | ||
) | ||
cc_library( | ||
name = "binaryen_cc", | ||
srcs = [":binaryen"], | ||
deps = [":binaryen_import"], | ||
hdrs = [":include"], | ||
includes = ["include"], | ||
visibility = ["//visibility:public"], | ||
) | ||
cc_import( | ||
name = "binaryen_import", | ||
hdrs = [":include"], | ||
shared_library = "lib/libbinaryen.so", | ||
visibility = ["//visibility:public"], | ||
) | ||
""", | ||
repository = "@nixpkgs", | ||
) | ||
|
||
load( | ||
"@rules_haskell//haskell:cabal.bzl", | ||
"stack_snapshot", | ||
) | ||
|
||
stack_snapshot( | ||
name = "stackage", | ||
components = { | ||
"ahc-pkg": ["exe"], | ||
}, | ||
local_snapshot = "//:bazel/stack.yaml", | ||
packages = [ | ||
"inline-js-core", | ||
"base", | ||
"binary", | ||
"bytestring", | ||
"containers", | ||
"directory", | ||
"filepath", | ||
"Cabal", | ||
"ghc-prim", | ||
"process", | ||
"stm", | ||
"template-haskell", | ||
"text", | ||
"haskeline", | ||
"exceptions", | ||
|
||
# dependencies from ghc-asterius | ||
# "ahc-bin", | ||
"ahc-pkg", | ||
"ghc-asterius", | ||
"ghc-boot-asterius", | ||
"ghc-boot-th-asterius", | ||
"ghc-heap-asterius", | ||
"ghci-asterius", | ||
"template-haskell-asterius", | ||
], | ||
|
||
# To update the stackage dependencies, run `bazel run @stackage-unpinned//:pin` and | ||
stack_snapshot_json = "//:bazel/stackage_snapshot.json", | ||
) | ||
|
||
# We not use the custom stack snapshot for this in order to work around the following bug. | ||
# https://github.com/tweag/rules_haskell/issues/1676 | ||
new_git_repository( | ||
name = "haskell_binaryen", | ||
build_file_content = """ | ||
load( | ||
"@rules_haskell//haskell:cabal.bzl", | ||
"haskell_cabal_library", | ||
) | ||
load( | ||
"@rules_haskell//haskell:defs.bzl", | ||
"haskell_library", | ||
"haskell_toolchain_library", | ||
) | ||
haskell_toolchain_library(name = "base") | ||
cc_library( | ||
name = "libbinaryen", | ||
srcs = ["cbits/wrappers.c"], | ||
deps = [ | ||
"@binaryen_dev//:binaryen_cc", | ||
], | ||
visibility = ["//visibility:public"] | ||
) | ||
haskell_library( | ||
name = "binaryen", | ||
srcs = glob(["src/**"]), | ||
deps = [ | ||
"libbinaryen", | ||
"base", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
""", | ||
commit = HASKELL_BINARYEN_COMMIT, | ||
remote = "https://github.com/tweag/haskell-binaryen", | ||
shallow_since = "1610373671 +0100", | ||
) | ||
|
||
###################### | ||
# Tools from nixpkgs # | ||
###################### | ||
|
||
[ | ||
nixpkgs_package( | ||
name = pack, | ||
repository = "@nixpkgs", | ||
) | ||
for pack in [ | ||
"hpack", | ||
] | ||
] |
Oops, something went wrong.