mirror of
https://github.com/tweag/asterius.git
synced 2024-10-26 09:21:04 +03:00
WIP: Add bazel build files
This commit is contained in:
parent
e7b823c874
commit
5de2615fa3
6
.bazelrc
Normal file
6
.bazelrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# User Configuration
|
||||||
|
# ------------------
|
||||||
|
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
|
||||||
|
run --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
|
||||||
|
|
||||||
|
try-import %workspace%/.bazelrc.local
|
47
.github/workflows/pipeline.yml
vendored
47
.github/workflows/pipeline.yml
vendored
@ -4,10 +4,52 @@ on:
|
|||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Bump this number to invalidate the GH actions cache
|
||||||
|
cache-version: 0
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
bazel:
|
||||||
|
name: bazel
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu]
|
||||||
|
runs-on: ${{ matrix.os }}-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Mount Bazel cache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/repo-cache
|
||||||
|
key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}
|
||||||
|
- uses: cachix/install-nix-action@v12
|
||||||
|
with:
|
||||||
|
nix_path: nixpkgs=./bazel_utils/nixpkgs/default.nix
|
||||||
|
# - name: Configure
|
||||||
|
# run: |
|
||||||
|
# case ${{ matrix.os }} in
|
||||||
|
# macos) BUILD_CONFIG=macos-nixpkgs;;
|
||||||
|
# ubuntu) BUILD_CONFIG=linux-nixpkgs;;
|
||||||
|
# esac
|
||||||
|
# cat >.bazelrc.local <<EOF
|
||||||
|
# build --config=$BUILD_CONFIG
|
||||||
|
# EOF
|
||||||
|
- name: Build bundle
|
||||||
|
run: |
|
||||||
|
nix-shell bazel_utils/bazel_build_shell.nix --pure --run '
|
||||||
|
set -euo pipefail
|
||||||
|
bazel build //test:asterius_bundle
|
||||||
|
'
|
||||||
|
- name: Upload bundle
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: asterius_bundle.tar.gz
|
||||||
|
path: bazel-bin/test/asterius_bundle.tar.gz
|
||||||
|
|
||||||
boot:
|
boot:
|
||||||
name: boot
|
name: boot
|
||||||
|
if: false
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
@ -65,6 +107,7 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
name: test-${{ matrix.with-pic }}
|
name: test-${{ matrix.with-pic }}
|
||||||
|
if: false
|
||||||
needs: boot
|
needs: boot
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
strategy:
|
strategy:
|
||||||
@ -165,6 +208,7 @@ jobs:
|
|||||||
|
|
||||||
ghc-testsuite:
|
ghc-testsuite:
|
||||||
name: ghc-testsuite
|
name: ghc-testsuite
|
||||||
|
if: false
|
||||||
needs: boot
|
needs: boot
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
@ -212,6 +256,7 @@ jobs:
|
|||||||
|
|
||||||
test-cabal:
|
test-cabal:
|
||||||
name: test-cabal
|
name: test-cabal
|
||||||
|
if: false
|
||||||
needs: boot
|
needs: boot
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
@ -271,6 +316,7 @@ jobs:
|
|||||||
|
|
||||||
image:
|
image:
|
||||||
name: image-${{ matrix.image }}
|
name: image-${{ matrix.image }}
|
||||||
|
if: false
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@ -306,6 +352,7 @@ jobs:
|
|||||||
|
|
||||||
docs:
|
docs:
|
||||||
name: docs
|
name: docs
|
||||||
|
if: false
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
env:
|
env:
|
||||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -19,6 +19,8 @@ package-lock.json
|
|||||||
*.unlinked.bin
|
*.unlinked.bin
|
||||||
*.wasm-toolkit.txt
|
*.wasm-toolkit.txt
|
||||||
|
|
||||||
/test
|
|
||||||
|
|
||||||
/lib
|
/lib
|
||||||
|
|
||||||
|
/bazel-*
|
||||||
|
.bazelrc.local
|
361
WORKSPACE
Normal file
361
WORKSPACE
Normal file
@ -0,0 +1,361 @@
|
|||||||
|
# Give your project a name. :)
|
||||||
|
workspace(name = "bazel_asterius")
|
||||||
|
|
||||||
|
# Load the repository rule to download an http archive.
|
||||||
|
load(
|
||||||
|
"@bazel_tools//tools/build_defs/repo:http.bzl",
|
||||||
|
"http_archive",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@bazel_tools//tools/build_defs/repo:git.bzl",
|
||||||
|
"git_repository",
|
||||||
|
)
|
||||||
|
|
||||||
|
git_repository(
|
||||||
|
name = "rules_haskell",
|
||||||
|
remote = "https://github.com/tweag/rules_haskell.git",
|
||||||
|
branch = "master",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:repositories.bzl",
|
||||||
|
"rules_haskell_dependencies",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Setup all Bazel dependencies required by rules_haskell.
|
||||||
|
rules_haskell_dependencies()
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:toolchain.bzl",
|
||||||
|
"rules_haskell_toolchains",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
|
||||||
|
"nixpkgs_cc_configure",
|
||||||
|
"nixpkgs_git_repository",
|
||||||
|
"nixpkgs_local_repository",
|
||||||
|
"nixpkgs_package",
|
||||||
|
"nixpkgs_python_configure",
|
||||||
|
)
|
||||||
|
|
||||||
|
# External dependencies specific to asterius
|
||||||
|
# Based on the nix environemnt used by Stack
|
||||||
|
nixpkgs_local_repository(
|
||||||
|
name = "nixpkgs2",
|
||||||
|
nix_file = "//nix:bazel_deps.nix",
|
||||||
|
nix_file_deps = ["//nix:default.nix",
|
||||||
|
"//nix:sources.nix",
|
||||||
|
"//nix:binaryenOverlay.nix",
|
||||||
|
"//nix:sources.json"]
|
||||||
|
)
|
||||||
|
|
||||||
|
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 = "lib",
|
||||||
|
srcs = glob(["lib/*.so", "lib/*.a"]),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "binaryen",
|
||||||
|
# srcs = ["@binaryen//:lib"],
|
||||||
|
srcs = [":lib"],
|
||||||
|
hdrs = [":include"],
|
||||||
|
strip_include_prefix = "include",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
# This rule only bundles headers and a library and doesn't compile or link by itself.
|
||||||
|
# We set linkstatic = 1 to quiet to quiet the following warning:
|
||||||
|
#
|
||||||
|
# in linkstatic attribute of cc_library rule @zlib.dev//:zlib:
|
||||||
|
# setting 'linkstatic=1' is recommended if there are no object files.
|
||||||
|
#
|
||||||
|
linkstatic = 1,
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "inline-js-core",
|
||||||
|
urls = ["https://github.com/tweag/inline-js/archive/ef675745e84d23d51c50660d40acf9e684fbb2d6.tar.gz"],
|
||||||
|
sha256 = "8e69f0f9689efc7217488dc5c5cd66ee3b9f0055a2a7fe655890b7cb57173757",
|
||||||
|
strip_prefix = "inline-js-ef675745e84d23d51c50660d40acf9e684fbb2d6/inline-js-core/",
|
||||||
|
build_file_content = """
|
||||||
|
load("@rules_haskell//haskell:cabal.bzl", "haskell_cabal_library")
|
||||||
|
load("@stackage//:packages.bzl", "packages")
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "inline-js-core",
|
||||||
|
version = packages["inline-js-core"].version,
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
deps = packages["inline-js-core"].deps,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
# build_file_content = """
|
||||||
|
# filegroup(name = "inline-js-core", srcs = glob(["inline-js-core/**"]))
|
||||||
|
# """
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# nixpkgs_package(
|
||||||
|
# name = "autoconf",
|
||||||
|
# attribute_path = "autoconf",
|
||||||
|
# repository = "@nixpkgs2",
|
||||||
|
# )
|
||||||
|
|
||||||
|
# Dependencies for the utils/make_package.sh script
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "nix",
|
||||||
|
attribute_path = "nix",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
build_file_content = """
|
||||||
|
exports_files(["bin/nix-shell"], visibility = ["//visibility:public"])
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "cabal",
|
||||||
|
attribute_path = "cabal-install",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "ghc",
|
||||||
|
attribute_path = "ghc",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Fetch a version of nixpkgs from GitHub.
|
||||||
|
# For more information see the documentation of rules_nixpkgs at
|
||||||
|
# https://github.com/tweag/rules_nixpkgs/blob/master/README.md
|
||||||
|
|
||||||
|
# This version of nix contains ghc
|
||||||
|
nixpkgs_git_repository(
|
||||||
|
name = "nixpkgs",
|
||||||
|
revision = "20.09",
|
||||||
|
# sha256 = …
|
||||||
|
)
|
||||||
|
|
||||||
|
[
|
||||||
|
nixpkgs_package(
|
||||||
|
name = pack,
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
for pack in
|
||||||
|
[
|
||||||
|
# "haskellPackages.alex"
|
||||||
|
"bash",
|
||||||
|
# "nix",
|
||||||
|
# "cabal-install",
|
||||||
|
"stack",
|
||||||
|
"autoconf",
|
||||||
|
"automake",
|
||||||
|
# "binaryen",
|
||||||
|
"binutils",
|
||||||
|
# "gcc",
|
||||||
|
# "haskell.compiler.ghc884",
|
||||||
|
"git",
|
||||||
|
# "gmp.dev",
|
||||||
|
# "haskellPackages.happy",
|
||||||
|
# "ncurses.dev",
|
||||||
|
# "nodejs-15_x",
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "staasdsadasdck",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
# https://asterius.netlify.app/building.html#preparing-the-source-tree
|
||||||
|
# Calls the utils/make_packages.py that generates some packages.
|
||||||
|
# Then copy the BUILD files from bazel_build_files to these packages
|
||||||
|
|
||||||
|
load("//:bazel/make_packages_utils.bzl", "make_packages",)
|
||||||
|
|
||||||
|
make_packages(
|
||||||
|
name = "make_packages",
|
||||||
|
nix_shell_binary = "@nix//:bin/nix-shell",
|
||||||
|
nixpkgs = "@nixpkgs",
|
||||||
|
nix_shell_file = "//:nix/bazel-nix-shell.nix",
|
||||||
|
# tools = [],
|
||||||
|
binaries = ["@git//:bin/git", "@stack//:bin/stack", "@autoconf//:bin/autoreconf", "@automake//:bin/aclocal"],
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"stack_snapshot"
|
||||||
|
)
|
||||||
|
|
||||||
|
stack_snapshot(
|
||||||
|
name = "stackage",
|
||||||
|
extra_deps = {
|
||||||
|
"binaryen" : ["@binaryen_dev//:binaryen"]
|
||||||
|
},
|
||||||
|
packages = [
|
||||||
|
"binaryen",
|
||||||
|
"base",
|
||||||
|
"binary",
|
||||||
|
"bytestring",
|
||||||
|
"containers",
|
||||||
|
"directory",
|
||||||
|
"filepath",
|
||||||
|
"Cabal",
|
||||||
|
"ghc-prim",
|
||||||
|
"process",
|
||||||
|
"stm",
|
||||||
|
"template-haskell",
|
||||||
|
"text",
|
||||||
|
],
|
||||||
|
verbose = True,
|
||||||
|
snapshot = "nightly-2020-09-21",
|
||||||
|
vendored_packages = {
|
||||||
|
"inline-js-core": "@inline-js-core//:inline-js-core",
|
||||||
|
}
|
||||||
|
# This uses an unpinned version of stack_snapshot, meaning that stack is invoked on every build.
|
||||||
|
# To switch to pinned stackage dependencies, run `bazel run @stackage-unpinned//:pin` and
|
||||||
|
# uncomment the following line.
|
||||||
|
# stack_snapshot_json = "//:stackage_snapshot.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# nixpkgs_package(
|
||||||
|
# name ="binaryen_hs",
|
||||||
|
# attribute_path = "haskellPackages.binaryen",
|
||||||
|
# repository = "@nixpkgs2",
|
||||||
|
# )
|
||||||
|
|
||||||
|
nixpkgs_cc_configure(
|
||||||
|
repository = "@nixpkgs",
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_python_configure(
|
||||||
|
repository = "@nixpkgs",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:nixpkgs.bzl",
|
||||||
|
"haskell_register_ghc_nixpkgs",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Fetch a GHC binary distribution from nixpkgs and register it as a toolchain.
|
||||||
|
# For more information:
|
||||||
|
# https://api.haskell.build/haskell/nixpkgs.html#haskell_register_ghc_nixpkgs
|
||||||
|
haskell_register_ghc_nixpkgs(
|
||||||
|
repository = "@nixpkgs",
|
||||||
|
attribute_path = "ghc",
|
||||||
|
|
||||||
|
# with @nixpkgs
|
||||||
|
version = "8.8.4",
|
||||||
|
#version = "8.10.4",
|
||||||
|
)
|
||||||
|
|
||||||
|
# For zlib.BUILD.bazel
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "nixpkgs_zlib",
|
||||||
|
attribute_path = "zlib",
|
||||||
|
repository = "@nixpkgs",
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "zlib.dev",
|
||||||
|
build_file = "//:zlib.BUILD.bazel",
|
||||||
|
repository = "@nixpkgs",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# setup rules pkg to export build artifact
|
||||||
|
http_archive(
|
||||||
|
name = "rules_pkg",
|
||||||
|
urls = [
|
||||||
|
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
|
||||||
|
"https://github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
|
||||||
|
],
|
||||||
|
sha256 = "038f1caa773a7e35b3663865ffb003169c6a71dc995e39bf4815792f385d837d",
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
|
||||||
|
rules_pkg_dependencies()
|
||||||
|
|
||||||
|
# Wasi is a runtime dependency for ahc-link
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "wasilibc",
|
||||||
|
attribute_path = "wasi-sdk",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
build_file_content = """
|
||||||
|
filegroup(name = "wasilibc",
|
||||||
|
srcs = glob(["wasi-sdk-12.1g41fa3294474c/**"]),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
exports_files(
|
||||||
|
glob(["wasi-sdk-12.1g41fa3294474c/bin/*"]),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# dependencies for packaging
|
||||||
|
|
||||||
|
# for ldd
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "glibc-bin",
|
||||||
|
attribute_path = "glibc.bin",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "utillinux",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "tar",
|
||||||
|
attribute_path = "gnutar",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "gzip",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "busybox",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
nixpkgs_package(
|
||||||
|
name = "patchelf",
|
||||||
|
repository = "@nixpkgs2",
|
||||||
|
)
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
load("@rules_sh//sh:posix.bzl", "sh_posix_configure")
|
||||||
|
sh_posix_configure()
|
153
asterius/BUILD.bazel
Normal file
153
asterius/BUILD.bazel
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"haskell_cabal_library",
|
||||||
|
"haskell_cabal_binary",
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "asterius_datadir",
|
||||||
|
srcs = [
|
||||||
|
"cabal/config",
|
||||||
|
"libc/fnv.c",
|
||||||
|
"libc/fpstring.c",
|
||||||
|
"libc/fpstring.h",
|
||||||
|
"libc/getRandomBytes.c",
|
||||||
|
"libc/itoa.c",
|
||||||
|
"libc/main.c",
|
||||||
|
"libc/md5.c",
|
||||||
|
"libc/md5.h",
|
||||||
|
"libc/text_cbits.c",
|
||||||
|
"libc/text_cbits.h",
|
||||||
|
"libc/unescape_string.c",
|
||||||
|
"rts/browser/default.mjs",
|
||||||
|
"rts/browser/rts.fs.mjs",
|
||||||
|
"rts/browser/rts.wasi.mjs",
|
||||||
|
"rts/node/default.mjs",
|
||||||
|
"rts/node/rts.fs.mjs",
|
||||||
|
"rts/node/rts.wasi.mjs",
|
||||||
|
"rts/rts.autoapply.mjs",
|
||||||
|
"rts/rts.closuretypes.mjs",
|
||||||
|
"rts/rts.constants.mjs",
|
||||||
|
"rts/rts.eventlog.mjs",
|
||||||
|
"rts/rts.exception.mjs",
|
||||||
|
"rts/rts.exports.mjs",
|
||||||
|
"rts/rts.float.mjs",
|
||||||
|
"rts/rts.funtypes.mjs",
|
||||||
|
"rts/rts.gc.mjs",
|
||||||
|
"rts/rts.heapalloc.mjs",
|
||||||
|
"rts/rts.integer.mjs",
|
||||||
|
"rts/rts.jsval.mjs",
|
||||||
|
"rts/rts.memory.mjs",
|
||||||
|
"rts/rts.memorytrap.mjs",
|
||||||
|
"rts/rts.messages.mjs",
|
||||||
|
"rts/rts.mjs",
|
||||||
|
"rts/rts.modulify.mjs",
|
||||||
|
"rts/rts.reentrancy.mjs",
|
||||||
|
"rts/rts.scheduler.mjs",
|
||||||
|
"rts/rts.setimmediate.mjs",
|
||||||
|
"rts/rts.stablename.mjs",
|
||||||
|
"rts/rts.stableptr.mjs",
|
||||||
|
"rts/rts.staticptr.mjs",
|
||||||
|
"rts/rts.symtable.mjs",
|
||||||
|
"rts/rts.time.mjs",
|
||||||
|
"rts/rts.tracing.mjs",
|
||||||
|
"rts/rts.unicode.mjs",
|
||||||
|
"boot-init.sh",
|
||||||
|
"boot.sh",
|
||||||
|
],
|
||||||
|
visibility = ["//bazel/bazel_build:__pkg__"],
|
||||||
|
)
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "asterius",
|
||||||
|
srcs = glob(["asterius.cabal", "**"]),
|
||||||
|
version = "0.0.1",
|
||||||
|
cabalopts = ["--ghc-option=-j4"],
|
||||||
|
deps = [
|
||||||
|
"//ghc-toolkit",
|
||||||
|
"@make_packages//ghc-asterius",
|
||||||
|
"//wasm-toolkit",
|
||||||
|
"@stackage//:binaryen",
|
||||||
|
"@stackage//:inline-js-core",
|
||||||
|
":asterius-types"
|
||||||
|
|
||||||
|
],
|
||||||
|
visibility = [
|
||||||
|
"//bazel/bazel_build:__pkg__",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "asterius-types",
|
||||||
|
package_name = "asterius",
|
||||||
|
sublibrary_name = "asterius-types",
|
||||||
|
cabalopts = ["--ghc-option=-j4"],
|
||||||
|
srcs = glob(["asterius.cabal", "**"]),
|
||||||
|
version = "0.0.1",
|
||||||
|
deps = [
|
||||||
|
"//ghc-toolkit",
|
||||||
|
"@make_packages//ghc-asterius",
|
||||||
|
"@make_packages//template-haskell-asterius",
|
||||||
|
"@make_packages//ghci-asterius",
|
||||||
|
"@make_packages//ghc-boot-asterius",
|
||||||
|
"//wasm-toolkit",
|
||||||
|
"@stackage//:binaryen",
|
||||||
|
"@stackage//:inline-js-core"
|
||||||
|
],
|
||||||
|
visibility = [
|
||||||
|
"//bazel/bazel_build:__pkg__",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
haskell_cabal_binary(
|
||||||
|
name = "ahc-boot",
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
exe_name = "ahc-boot",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
cabalopts = ["--ghc-option=-j4"],
|
||||||
|
deps = [
|
||||||
|
"//ghc-toolkit",
|
||||||
|
"@make_packages//ghc-asterius",
|
||||||
|
"@make_packages//template-haskell-asterius",
|
||||||
|
"@make_packages//ghci-asterius",
|
||||||
|
"@make_packages//ghc-boot-asterius",
|
||||||
|
"//wasm-toolkit",
|
||||||
|
"@stackage//:binaryen",
|
||||||
|
"@stackage//:inline-js-core",
|
||||||
|
":asterius",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
[
|
||||||
|
haskell_cabal_binary(
|
||||||
|
name = executable,
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
exe_name = executable,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//ghc-toolkit",
|
||||||
|
"@make_packages//ghc-asterius",
|
||||||
|
"@make_packages//template-haskell-asterius",
|
||||||
|
"@make_packages//ghci-asterius",
|
||||||
|
"@make_packages//ghc-boot-asterius",
|
||||||
|
"//wasm-toolkit",
|
||||||
|
"@stackage//:binaryen",
|
||||||
|
"@stackage//:inline-js-core",
|
||||||
|
":asterius"
|
||||||
|
],
|
||||||
|
)
|
||||||
|
for executable in
|
||||||
|
[
|
||||||
|
"Setup-ghc-prim",
|
||||||
|
"ahc",
|
||||||
|
"ahc-cabal",
|
||||||
|
"ahc-dist",
|
||||||
|
"ahc-ld",
|
||||||
|
"ahc-link",
|
||||||
|
"ahc-pkg",
|
||||||
|
"genconstants",
|
||||||
|
"unlit"]
|
||||||
|
]
|
||||||
|
|
||||||
|
exports_files(["boot-init.sh", "boot.sh"])
|
@ -1,23 +1,55 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
cp -r $ASTERIUS_BOOT_LIBS_DIR .
|
set -euo pipefail
|
||||||
|
set -o xtrace
|
||||||
|
echo "from boot.sh"
|
||||||
|
|
||||||
|
#cp -r $ASTERIUS_BOOT_LIBS_DIR .
|
||||||
pushd boot-libs
|
pushd boot-libs
|
||||||
|
echo "pwd after pushd boot-libs"
|
||||||
|
pwd
|
||||||
|
echo "ls after pushd boot-libs"
|
||||||
|
ls
|
||||||
|
|
||||||
pushd ghc-prim
|
pushd ghc-prim
|
||||||
$ASTERIUS_SETUP_GHC_PRIM configure --builddir=$ASTERIUS_TMP_DIR/dist/ghc-prim $ASTERIUS_CONFIGURE_OPTIONS
|
echo "pwd after pushd ghc-prim"
|
||||||
$ASTERIUS_SETUP_GHC_PRIM build -j --builddir=$ASTERIUS_TMP_DIR/dist/ghc-prim
|
pwd
|
||||||
$ASTERIUS_SETUP_GHC_PRIM install --builddir=$ASTERIUS_TMP_DIR/dist/ghc-prim
|
echo "ls after pushd ghc-prim"
|
||||||
|
ls
|
||||||
|
echo "ASTERIUS_SETUP_GHC_PRIM = $ASTERIUS_SETUP_GHC_PRIM"
|
||||||
|
$ASTERIUS_SETUP_GHC_PRIM configure --verbose=3 --builddir=$ASTERIUS_TMP_DIR/dist/ghc-prim $ASTERIUS_CONFIGURE_OPTIONS
|
||||||
|
|
||||||
|
echo "ASTERIUS_SETUP_GHC_PRIM after configure"
|
||||||
|
$ASTERIUS_SETUP_GHC_PRIM build -j --verbose=3 --builddir=$ASTERIUS_TMP_DIR/dist/ghc-prim
|
||||||
|
|
||||||
|
echo "ASTERIUS_SETUP_GHC_PRIM after build"
|
||||||
|
$ASTERIUS_SETUP_GHC_PRIM install --verbose=3 --builddir=$ASTERIUS_TMP_DIR/dist/ghc-prim
|
||||||
|
|
||||||
|
echo "ASTERIUS_SETUP_GHC_PRIM after install"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
echo "before pushd integer-simple"
|
||||||
|
echo "PATH=$PATH"
|
||||||
pushd integer-simple
|
pushd integer-simple
|
||||||
ahc-cabal act-as-setup --build-type=Simple -- configure --builddir=$ASTERIUS_TMP_DIR/dist/integer-simple $ASTERIUS_CONFIGURE_OPTIONS
|
ahc-cabal act-as-setup --build-type=Simple -- configure --builddir=$ASTERIUS_TMP_DIR/dist/integer-simple $ASTERIUS_CONFIGURE_OPTIONS
|
||||||
|
echo "after integer-simple configure"
|
||||||
ahc-cabal act-as-setup --build-type=Simple -- build -j --builddir=$ASTERIUS_TMP_DIR/dist/integer-simple
|
ahc-cabal act-as-setup --build-type=Simple -- build -j --builddir=$ASTERIUS_TMP_DIR/dist/integer-simple
|
||||||
|
echo "after integer-simple build"
|
||||||
ahc-cabal act-as-setup --build-type=Simple -- install --builddir=$ASTERIUS_TMP_DIR/dist/integer-simple
|
ahc-cabal act-as-setup --build-type=Simple -- install --builddir=$ASTERIUS_TMP_DIR/dist/integer-simple
|
||||||
|
echo "after integer-simple install"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
pushd base
|
pushd base
|
||||||
|
echo "after pushd base pwd=$(pwd)"
|
||||||
|
echo "after pushd base ls=$(ls)"
|
||||||
|
echo "ls -l"
|
||||||
|
ls -l
|
||||||
|
echo "ls -l autom4te.cache"
|
||||||
|
chmod -R +w autom4te.cache
|
||||||
|
ls -l autom4te.cache
|
||||||
|
rm -r autom4te.cache
|
||||||
|
|
||||||
autoreconf -i
|
autoreconf -i
|
||||||
ahc-cabal act-as-setup --build-type=Configure -- configure --builddir=$ASTERIUS_TMP_DIR/dist/base -finteger-simple $ASTERIUS_CONFIGURE_OPTIONS
|
ahc-cabal act-as-setup --build-type=Configure -- configure --builddir=$ASTERIUS_TMP_DIR/dist/base -finteger-simple $ASTERIUS_CONFIGURE_OPTIONS
|
||||||
ahc-cabal act-as-setup --build-type=Configure -- build -j --builddir=$ASTERIUS_TMP_DIR/dist/base
|
ahc-cabal act-as-setup --build-type=Configure -- build -j --builddir=$ASTERIUS_TMP_DIR/dist/base
|
||||||
|
40
bazel.md
Normal file
40
bazel.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
|
||||||
|
## Local settings
|
||||||
|
- In `.bazelrc`:
|
||||||
|
|
||||||
|
```
|
||||||
|
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
|
||||||
|
run --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
|
||||||
|
|
||||||
|
build --sandbox_writable_path=/home/stan/.ahc-cabal
|
||||||
|
run --sandbox_writable_path=/home/stan/.ahc-cabal
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
- In `bazel_utils/make_packages_wrapper.sh`:
|
||||||
|
|
||||||
|
```
|
||||||
|
export GIT_SSL_CAINFO="/etc/ssl/certs/ca-certificates.crt"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## WIP
|
||||||
|
This is a WIP, so there is some cleanup to do:
|
||||||
|
|
||||||
|
- Some slight modifications of Asterius source code should be removed.
|
||||||
|
|
||||||
|
- The rules related to the boot process are in the `test` repository.
|
||||||
|
They should be moved out and this directory should be added back to .gitignore
|
||||||
|
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
- Bazel makes calls to calls to `utils/make-packages.py` and `ahc-boot`.
|
||||||
|
It would more fine grained to use Bazel itself instead.
|
||||||
|
|
||||||
|
- Only tested on NixOS.
|
||||||
|
|
||||||
|
- Add rules to export the artifacts.
|
||||||
|
|
||||||
|
- Bazel uses `haskell_cabal_library` and `haskell_cabal_binary` to build the various target. This also could be finer grained.
|
208
bazel/bazel_build/BUILD
Normal file
208
bazel/bazel_build/BUILD
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
load("utils.bzl",
|
||||||
|
"asterius_boot",
|
||||||
|
"ahc_link",
|
||||||
|
)
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:defs.bzl",
|
||||||
|
"haskell_toolchain_library",
|
||||||
|
"haskell_library",
|
||||||
|
"haskell_binary",
|
||||||
|
"haskell_repl",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:toolchain.bzl",
|
||||||
|
"haskell_toolchain",
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_deb")
|
||||||
|
|
||||||
|
load("//bazel/bazel_utils/packaging:packaging.bzl", "package_app", "bundle_apps")
|
||||||
|
|
||||||
|
|
||||||
|
asterius_boot(
|
||||||
|
name = "asterius_boot",
|
||||||
|
srcs = [
|
||||||
|
"//asterius:asterius_datadir",
|
||||||
|
"launch_ahc_boot_from_utils.sh",
|
||||||
|
],
|
||||||
|
tools = [
|
||||||
|
"//ghc-toolkit:ghc-toolkit-datafiles",
|
||||||
|
"@cabal//:bin",
|
||||||
|
"//asterius:ahc",
|
||||||
|
"//asterius:ahc-pkg",
|
||||||
|
"//asterius:ahc-cabal",
|
||||||
|
"//asterius:ahc-dist",
|
||||||
|
"//asterius:ahc-ld",
|
||||||
|
"//asterius:ahc-link",
|
||||||
|
"//asterius:Setup-ghc-prim",
|
||||||
|
"//asterius:ahc-boot",
|
||||||
|
"@ghc//:bin",
|
||||||
|
"@autoconf//:bin",
|
||||||
|
"@automake//:bin",
|
||||||
|
"@bazel_tools//tools/bash/runfiles",
|
||||||
|
|
||||||
|
],
|
||||||
|
asterius_version = "0.0.1",
|
||||||
|
)
|
||||||
|
|
||||||
|
# ahc_link(
|
||||||
|
# name = "test_ahc_link",
|
||||||
|
# srcs = [],
|
||||||
|
# deps = [],
|
||||||
|
# tools = ["//asterius:ahc"],
|
||||||
|
# asterius_boot_rule = ":asterius_boot",
|
||||||
|
# ahc_link_exe = "//asterius:ahc-link",
|
||||||
|
# )
|
||||||
|
|
||||||
|
# pkg_tar(
|
||||||
|
# name = "asterius-output",
|
||||||
|
# strip_prefix = "/src",
|
||||||
|
# srcs = [
|
||||||
|
# ":asterius_boot",
|
||||||
|
# "//asterius:ahc",
|
||||||
|
# "//asterius:ahc-pkg",
|
||||||
|
# "//asterius:ahc-cabal",
|
||||||
|
# "//asterius:ahc-dist",
|
||||||
|
# "//asterius:ahc-ld",
|
||||||
|
# "//asterius:ahc-link",
|
||||||
|
# ],
|
||||||
|
# mode = "0755",
|
||||||
|
# )
|
||||||
|
|
||||||
|
package_app(
|
||||||
|
name = "asterius-out",
|
||||||
|
binary = "//asterius:ahc",
|
||||||
|
resources = [
|
||||||
|
"//bazel/bazel_utils/packaging:package-app.sh",
|
||||||
|
],
|
||||||
|
tags = ["no-cache"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
wasi_apps = [
|
||||||
|
"ar",
|
||||||
|
"clang",
|
||||||
|
"clang-12",
|
||||||
|
"clang-cl",
|
||||||
|
# "clang-format",
|
||||||
|
#"git-clang-format", TODO: add a symlink in bundle ?
|
||||||
|
"ld64.lld",
|
||||||
|
"lld-link",
|
||||||
|
"llvm-cxxfilt",
|
||||||
|
"llvm-nm",
|
||||||
|
"llvm-objdump",
|
||||||
|
"llvm-size",
|
||||||
|
"llvm-strip",
|
||||||
|
"objcopy",
|
||||||
|
"ranlib",
|
||||||
|
"strings",
|
||||||
|
"wasm-ld",
|
||||||
|
"c++filt",
|
||||||
|
"clang++",
|
||||||
|
# "clang-apply-replacements",
|
||||||
|
"clang-cpp",
|
||||||
|
# "clang-tidy",
|
||||||
|
"ld.lld",
|
||||||
|
"lld",
|
||||||
|
"llvm-ar",
|
||||||
|
"llvm-dwarfdump",
|
||||||
|
"llvm-objcopy",
|
||||||
|
"llvm-ranlib",
|
||||||
|
"llvm-strings",
|
||||||
|
"nm",
|
||||||
|
"objdump",
|
||||||
|
"size",
|
||||||
|
"strip"]
|
||||||
|
|
||||||
|
wasi_sdk_version = "12.1g41fa3294474c"
|
||||||
|
[
|
||||||
|
package_app(
|
||||||
|
name = "wasi-sdk-{}".format(app),
|
||||||
|
binary = "@wasilibc//:wasi-sdk-{}/bin/{}".format(wasi_sdk_version, app),
|
||||||
|
resources = [
|
||||||
|
"//bazel/bazel_utils/packaging:package-app.sh",
|
||||||
|
"@wasilibc//:wasilibc",
|
||||||
|
],
|
||||||
|
tags = ["no-cache"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
for app in wasi_apps
|
||||||
|
]
|
||||||
|
|
||||||
|
bundle_apps(
|
||||||
|
name = "wasi_bundle",
|
||||||
|
packaged_apps =\
|
||||||
|
[":wasi-sdk-{}".format(app) for app in wasi_apps],
|
||||||
|
tags = ["no-cache"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
asterius_apps = [
|
||||||
|
"ahc",
|
||||||
|
"ahc-pkg",
|
||||||
|
"ahc-cabal",
|
||||||
|
"ahc-dist",
|
||||||
|
"ahc-ld",
|
||||||
|
"ahc-link",
|
||||||
|
]
|
||||||
|
|
||||||
|
[
|
||||||
|
package_app(
|
||||||
|
name = "asterius-out-{}".format(app),
|
||||||
|
binary = "//asterius:{}".format(app),
|
||||||
|
resources = [
|
||||||
|
"//bazel/bazel_utils/packaging:package-app.sh",
|
||||||
|
"@wasilibc//:wasilibc",
|
||||||
|
],
|
||||||
|
tags = ["no-cache"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
for app in asterius_apps]
|
||||||
|
|
||||||
|
cmds = [
|
||||||
|
"mkdir -p $@/bin",
|
||||||
|
"cp $(location :wasi_bundle) $@/bin",
|
||||||
|
"cd $@/bin",
|
||||||
|
"tar xf wasi_bundle.tar.gz",
|
||||||
|
"rm wasi_bundle.tar.gz",
|
||||||
|
"cd ..",
|
||||||
|
"ln -s bin/resources/wasilibc/wasi-sdk-{}/lib lib".format(wasi_sdk_version),
|
||||||
|
"ln -s bin/resources/wasilibc/wasi-sdk-{}/share share".format(wasi_sdk_version),
|
||||||
|
]
|
||||||
|
|
||||||
|
genrule(
|
||||||
|
name = "extracted_wasi_bundle",
|
||||||
|
outs = ["wasi_folder"],
|
||||||
|
srcs = [":wasi_bundle"],
|
||||||
|
cmd = " && ".join(cmds),
|
||||||
|
)
|
||||||
|
|
||||||
|
genrule(
|
||||||
|
name = "tar_wasi_bundle",
|
||||||
|
srcs = [":extracted_wasi_bundle"],
|
||||||
|
outs = ["tar_wasi_bundle.tar.gz"],
|
||||||
|
cmd = "$(location //bazel/bazel_utils/sh:mktgz) $@ -C \"$(location :extracted_wasi_bundle)\" .",
|
||||||
|
tools = ["//bazel/bazel_utils/sh:mktgz"],
|
||||||
|
)
|
||||||
|
|
||||||
|
bundle_apps(
|
||||||
|
name = "asterius_bundle",
|
||||||
|
packaged_apps =\
|
||||||
|
[":asterius-out-{}".format(app) for app in asterius_apps] \
|
||||||
|
+ [":tar_wasi_bundle",
|
||||||
|
":asterius_boot",
|
||||||
|
":wrappers",
|
||||||
|
"//bazel/bazel_utils/packaging:asterius_bundle.BUILD.bazel",
|
||||||
|
"//bazel/bazel_utils/packaging:wasm_cc_toolchain.bzl",
|
||||||
|
],
|
||||||
|
# + [":wasi-sdk-{}".format(app) for app in wasi_apps],
|
||||||
|
tags = ["no-cache"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "wrappers",
|
||||||
|
srcs = glob(["wrappers/*"])
|
||||||
|
)
|
21
bazel/bazel_build/launch_ahc_boot_from_utils.sh
Executable file
21
bazel/bazel_build/launch_ahc_boot_from_utils.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
set -e
|
||||||
|
|
||||||
|
OUTPUT_DATADIR="$1"
|
||||||
|
|
||||||
|
# setup working directory for ahc-boot
|
||||||
|
export ASTERIUS_DATA_DIR="$(pwd)/asterius"
|
||||||
|
export asterius_datadir=$ASTERIUS_DATA_DIR
|
||||||
|
|
||||||
|
cp -r ghc-toolkit/ghc-libdir $ASTERIUS_DATA_DIR
|
||||||
|
cp -r ghc-toolkit/boot-libs $ASTERIUS_DATA_DIR
|
||||||
|
|
||||||
|
|
||||||
|
# Put dependencies in the PATH
|
||||||
|
for p in $PATH_BZL; do
|
||||||
|
PATH="$(readlink -f $p):$PATH"
|
||||||
|
done
|
||||||
|
|
||||||
|
ahc-boot
|
||||||
|
|
||||||
|
cp -a "$ASTERIUS_DATA_DIR/." "$OUTPUT_DATADIR/"
|
||||||
|
|
127
bazel/bazel_build/utils.bzl
Normal file
127
bazel/bazel_build/utils.bzl
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
load("@bazel_skylib//lib:paths.bzl", "paths")
|
||||||
|
load("@bazel_skylib//lib:new_sets.bzl", "sets")
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:providers.bzl",
|
||||||
|
"HaddockInfo",
|
||||||
|
"HaskellInfo",
|
||||||
|
"HaskellLibraryInfo",
|
||||||
|
"all_dependencies_package_ids",
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||||
|
|
||||||
|
# boot_dir = paths.join(data_dir, ".boot")
|
||||||
|
# boot_env = {"ASTERIUS_BOOT_LIBS_DIR": paths.join(data_dir, "boot-libs"),
|
||||||
|
# "ASTERIUS_SANDBOX_GHC_LIBDIR": paths.join(data_dir, "ghc-libdir"),
|
||||||
|
# "ASTERIUS_LIB_DIR": paths.join(boot_dir,"asterius_lib"),
|
||||||
|
# "ASTERIUS_TMP_DIR": bootTmpDir args,
|
||||||
|
# "ASTERIUS_AHCPKG": ahc_pkg_path,
|
||||||
|
# "ASTERIUS_SETUP_GHC_PRIM": setupGhcPrim,
|
||||||
|
# "ASTERIUS_CONFIGURE_OPTIONS": configureOptions
|
||||||
|
# }
|
||||||
|
|
||||||
|
def paths_of_tools(ctx):
|
||||||
|
path = sets.make()
|
||||||
|
for d in ctx.attr.tools:
|
||||||
|
if HaskellInfo in d and HaskellLibraryInfo not in d:
|
||||||
|
# haskell binary rule
|
||||||
|
for f in d.files.to_list():
|
||||||
|
sets.insert(path, paths.dirname(f.path))
|
||||||
|
|
||||||
|
if d.label.name == "bin":
|
||||||
|
for f in d.files.to_list():
|
||||||
|
sets.insert(path, paths.dirname(f.path))
|
||||||
|
|
||||||
|
path_string = " ".join(sets.to_list(path))
|
||||||
|
|
||||||
|
return {"PATH_BZL": path_string}
|
||||||
|
|
||||||
|
|
||||||
|
def _asterius_boot_impl(ctx):
|
||||||
|
data_dir = ctx.actions.declare_directory(
|
||||||
|
"asterius-{}_data".format(ctx.attr.asterius_version),
|
||||||
|
)
|
||||||
|
|
||||||
|
tools = depset(transitive = [t.files for t in ctx.attr.tools])
|
||||||
|
inputs = depset(transitive = [t.files for t in ctx.attr.srcs])
|
||||||
|
|
||||||
|
cc_toolchain = find_cpp_toolchain(ctx)
|
||||||
|
cc_bin_path = paths.dirname(cc_toolchain.compiler_executable)
|
||||||
|
haskell_toolchain = ctx.toolchains["@rules_haskell//haskell:toolchain"]
|
||||||
|
|
||||||
|
for f in haskell_toolchain.bindir:
|
||||||
|
haskell_bin_path = paths.dirname(f.path)
|
||||||
|
|
||||||
|
ctx.actions.run_shell(
|
||||||
|
tools = tools,
|
||||||
|
inputs = inputs,
|
||||||
|
outputs = [data_dir],
|
||||||
|
command = "PATH={}:{}:$PATH bazel/bazel_build/launch_ahc_boot_from_utils.sh $1".format(cc_bin_path, haskell_bin_path),
|
||||||
|
|
||||||
|
env = paths_of_tools(ctx),
|
||||||
|
arguments = [data_dir.path],
|
||||||
|
)
|
||||||
|
|
||||||
|
# ctx.actions.run_shell(
|
||||||
|
# tools = tools,
|
||||||
|
# inputs = [],
|
||||||
|
# command = "PATH={}:$PATH ln -s $(ahc_pkg field base haddock-html --simple-output) docdir".format(haskell_bin_path),
|
||||||
|
|
||||||
|
# )
|
||||||
|
default_info = DefaultInfo(files = depset([data_dir]))
|
||||||
|
return [default_info]
|
||||||
|
|
||||||
|
asterius_boot = rule(
|
||||||
|
_asterius_boot_impl,
|
||||||
|
attrs = {
|
||||||
|
"srcs": attr.label_list(
|
||||||
|
allow_files = True,
|
||||||
|
doc = "",
|
||||||
|
),
|
||||||
|
"tools": attr.label_list(),
|
||||||
|
"_cc_toolchain": attr.label(
|
||||||
|
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
|
||||||
|
),
|
||||||
|
"asterius_version": attr.string(),
|
||||||
|
},
|
||||||
|
toolchains = [
|
||||||
|
"@rules_haskell//haskell:toolchain",
|
||||||
|
"@bazel_tools//tools/cpp:toolchain_type",
|
||||||
|
] ,
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _ahc_link_impl(ctx):
|
||||||
|
ahc_link_executable = ctx.attr.ahc_link_exe.files
|
||||||
|
asterius_boot_rule = ctx.file.asterius_boot_rule
|
||||||
|
ahc_link_executable_path = ahc_link_executable.to_list()[0]
|
||||||
|
source_files = ctx.attr.srcs
|
||||||
|
output_file = ctx.actions.declare_file(
|
||||||
|
"output_file_name"
|
||||||
|
)
|
||||||
|
tools = depset(direct = [asterius_boot_rule], transitive = [t.files for t in ctx.attr.tools]+[ahc_link_executable])
|
||||||
|
ctx.actions.run(
|
||||||
|
tools = tools,
|
||||||
|
inputs = source_files,
|
||||||
|
outputs = [output_file],
|
||||||
|
executable = ahc_link_executable_path,
|
||||||
|
env = {"asterius_datadir": asterius_boot_rule.path} ,
|
||||||
|
arguments = ["--input-hs"] + [s.path for s in source_files] + ["--browser", "--bundle"],
|
||||||
|
# arguments = ["--input-hs"+" ".join([s.path for s in source_files]) + "--browser --bundle"],
|
||||||
|
)
|
||||||
|
default_info = DefaultInfo(
|
||||||
|
files = depset([output_file])
|
||||||
|
)
|
||||||
|
return [default_info]
|
||||||
|
|
||||||
|
ahc_link = rule(
|
||||||
|
_ahc_link_impl,
|
||||||
|
attrs = {
|
||||||
|
"srcs": attr.label_list(),
|
||||||
|
"deps": attr.label_list(),
|
||||||
|
"tools": attr.label_list(),
|
||||||
|
"asterius_boot_rule": attr.label(allow_single_file = True),
|
||||||
|
"ahc_link_exe": attr.label(),
|
||||||
|
},
|
||||||
|
)
|
4
bazel/bazel_build/wrappers/ahc
Executable file
4
bazel/bazel_build/wrappers/ahc
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source "$(dirname "$0")/setup_env.sh"
|
||||||
|
$bundle_root/ahc "$@"
|
4
bazel/bazel_build/wrappers/ahc-cabal
Executable file
4
bazel/bazel_build/wrappers/ahc-cabal
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source "$(dirname "$0")/setup_env.sh"
|
||||||
|
$bundle_root/ahc-cabal "$@"
|
4
bazel/bazel_build/wrappers/ahc-dist
Executable file
4
bazel/bazel_build/wrappers/ahc-dist
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source "$(dirname "$0")/setup_env.sh"
|
||||||
|
$bundle_root/ahc-dist "$@"
|
5
bazel/bazel_build/wrappers/ahc-ld
Executable file
5
bazel/bazel_build/wrappers/ahc-ld
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source "$(dirname "$0")/setup_env.sh"
|
||||||
|
$bundle_root/ahc-ld "$@"
|
||||||
|
|
4
bazel/bazel_build/wrappers/ahc-link
Executable file
4
bazel/bazel_build/wrappers/ahc-link
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source "$(dirname "$0")/setup_env.sh"
|
||||||
|
$bundle_root/ahc-link "$@"
|
4
bazel/bazel_build/wrappers/ahc-pkg
Executable file
4
bazel/bazel_build/wrappers/ahc-pkg
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source "$(dirname "$0")/setup_env.sh"
|
||||||
|
$bundle_root/ahc-pkg "$@"
|
7
bazel/bazel_build/wrappers/setup_env.sh
Normal file
7
bazel/bazel_build/wrappers/setup_env.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
export asterius_bindir="$(cd "$(dirname "$0")"; pwd)"
|
||||||
|
export bundle_root="$(dirname $(dirname $asterius_bindir))"
|
||||||
|
export asterius_datadir="$bundle_root/asterius-0.0.1_data" # TODO update version automatically.
|
||||||
|
# export WASI_SDK_PATH="$bundle_root/resources/wasilibc/wasi-sdk-12.0/"
|
||||||
|
export WASI_SDK_PATH="$bundle_root"
|
22
bazel/bazel_build_files/BUILD_ghc-asterius
Executable file
22
bazel/bazel_build_files/BUILD_ghc-asterius
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"haskell_cabal_library",
|
||||||
|
)
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "ghc-asterius",
|
||||||
|
# srcs = glob(["ghc-asterius.cabal", "GHCi/**","SizedSeq.hs", "LICENSE"]),
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
version = "8.8.4",
|
||||||
|
cabalopts = ["--ghc-option=-Wall -j8"],
|
||||||
|
deps = [
|
||||||
|
"//ghci-asterius",
|
||||||
|
"//template-haskell-asterius",
|
||||||
|
"//ghc-heap-asterius",
|
||||||
|
"//ghc-boot-th-asterius",
|
||||||
|
"//ghc-boot-asterius",
|
||||||
|
],
|
||||||
|
visibility = [
|
||||||
|
"//visibility:public"
|
||||||
|
]
|
||||||
|
)
|
25
bazel/bazel_build_files/BUILD_ghc-boot-asterius
Executable file
25
bazel/bazel_build_files/BUILD_ghc-boot-asterius
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:defs.bzl",
|
||||||
|
"haskell_toolchain_library",
|
||||||
|
"haskell_library",
|
||||||
|
"haskell_binary",
|
||||||
|
"haskell_repl",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"haskell_cabal_library",
|
||||||
|
)
|
||||||
|
|
||||||
|
haskell_toolchain_library(name = "base")
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "ghc-boot-asterius",
|
||||||
|
srcs = glob(["ghc-boot-asterius.cabal", "GHC/**", "LICENSE"]),
|
||||||
|
version = "8.8.4",
|
||||||
|
cabalopts = ["--ghc-option=-Wall"],
|
||||||
|
deps = [":base", "//ghc-boot-th-asterius"],
|
||||||
|
visibility = [
|
||||||
|
"//visibility:public"
|
||||||
|
]
|
||||||
|
)
|
25
bazel/bazel_build_files/BUILD_ghc-boot-th-asterius
Executable file
25
bazel/bazel_build_files/BUILD_ghc-boot-th-asterius
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:defs.bzl",
|
||||||
|
"haskell_toolchain_library",
|
||||||
|
"haskell_library",
|
||||||
|
"haskell_binary",
|
||||||
|
"haskell_repl",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"haskell_cabal_library",
|
||||||
|
)
|
||||||
|
|
||||||
|
haskell_toolchain_library(name = "base")
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "ghc-boot-th-asterius",
|
||||||
|
srcs = glob(["ghc-boot-th-asterius.cabal", "GHC/**", "LICENSE"]),
|
||||||
|
version = "8.8.4",
|
||||||
|
cabalopts = ["--ghc-option=-Wall"],
|
||||||
|
deps = [":base"],
|
||||||
|
visibility = [
|
||||||
|
"//visibility:public"
|
||||||
|
]
|
||||||
|
)
|
27
bazel/bazel_build_files/BUILD_ghc-heap-asterius
Executable file
27
bazel/bazel_build_files/BUILD_ghc-heap-asterius
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:defs.bzl",
|
||||||
|
"haskell_toolchain_library",
|
||||||
|
"haskell_library",
|
||||||
|
"haskell_binary",
|
||||||
|
"haskell_repl",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"haskell_cabal_library",
|
||||||
|
)
|
||||||
|
|
||||||
|
haskell_toolchain_library(name = "ghc-prim")
|
||||||
|
haskell_toolchain_library(name = "base")
|
||||||
|
haskell_toolchain_library(name = "rts")
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "ghc-heap-asterius",
|
||||||
|
srcs = glob(["ghc-heap-asterius.cabal", "GHC/**", "Setup.hs", "cbits/**", "LICENSE"]),
|
||||||
|
version = "8.8.4",
|
||||||
|
cabalopts = ["--ghc-option=-Wall"],
|
||||||
|
deps = [":base", ":ghc-prim", ":rts"],
|
||||||
|
visibility = [
|
||||||
|
"//visibility:public"
|
||||||
|
]
|
||||||
|
)
|
21
bazel/bazel_build_files/BUILD_ghci-asterius
Executable file
21
bazel/bazel_build_files/BUILD_ghci-asterius
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"haskell_cabal_library",
|
||||||
|
)
|
||||||
|
|
||||||
|
# haskell_toolchain_library(name = "base")
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "ghci-asterius",
|
||||||
|
srcs = glob(["ghci-asterius.cabal", "GHCi/**","SizedSeq.hs", "LICENSE"]),
|
||||||
|
version = "8.8.4",
|
||||||
|
cabalopts = ["--ghc-option=-Wall"],
|
||||||
|
deps = ["//template-haskell-asterius",
|
||||||
|
"//ghc-heap-asterius",
|
||||||
|
"//ghc-boot-th-asterius",
|
||||||
|
"//ghc-boot-asterius",
|
||||||
|
],
|
||||||
|
visibility = [
|
||||||
|
"//visibility:public"
|
||||||
|
]
|
||||||
|
)
|
25
bazel/bazel_build_files/BUILD_template-haskell-asterius
Executable file
25
bazel/bazel_build_files/BUILD_template-haskell-asterius
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:defs.bzl",
|
||||||
|
"haskell_toolchain_library",
|
||||||
|
"haskell_library",
|
||||||
|
"haskell_binary",
|
||||||
|
"haskell_repl",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"haskell_cabal_library",
|
||||||
|
)
|
||||||
|
|
||||||
|
#haskell_toolchain_library(name = "base")
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "template-haskell-asterius",
|
||||||
|
srcs = glob(["template-haskell-asterius.cabal","Setup.hs", "Language/**", "LICENSE"]),
|
||||||
|
version = "2.15.0.0",
|
||||||
|
cabalopts = ["--ghc-option=-Wall"],
|
||||||
|
deps = ["//ghc-boot-th-asterius"],
|
||||||
|
visibility = [
|
||||||
|
"//visibility:public"
|
||||||
|
]
|
||||||
|
)
|
6
bazel/bazel_utils/bazel_build_shell.nix
Normal file
6
bazel/bazel_utils/bazel_build_shell.nix
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{ pkgs ? import ./nixpkgs {} }:
|
||||||
|
with pkgs;
|
||||||
|
mkShell {
|
||||||
|
LANG="C.UTF-8";
|
||||||
|
buildInputs = [gcc cacert git nix bazel_4 ];
|
||||||
|
}
|
14
bazel/bazel_utils/make_packages_nix.py
Normal file
14
bazel/bazel_utils/make_packages_nix.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import importlib
|
||||||
|
make_packages = importlib.import_module("make-packages")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# make_packages.ghc_clean()
|
||||||
|
#make_packages.make_hadrian()
|
||||||
|
make_packages.ghc_configure()
|
||||||
|
make_packages.make_autogen()
|
||||||
|
make_packages.make_ghc_heap_asterius()
|
||||||
|
make_packages.make_ghc_boot_th_asterius()
|
||||||
|
make_packages.make_ghc_boot_asterius()
|
||||||
|
make_packages.make_template_haskell_asterius()
|
||||||
|
make_packages.make_ghci_asterius()
|
||||||
|
make_packages.make_ghc_asterius()
|
10
bazel/bazel_utils/make_packages_wrapper.sh
Executable file
10
bazel/bazel_utils/make_packages_wrapper.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
set -xe
|
||||||
|
|
||||||
|
MAKE_PACKAGE_PATH=$1
|
||||||
|
|
||||||
|
export PATH="$PATH_BZL:$PATH"
|
||||||
|
|
||||||
|
export GIT_SSL_CAINFO="/etc/ssl/certs/ca-certificates.crt"
|
||||||
|
|
||||||
|
# we assume python3 is in the PATH because we use rules_haskell.
|
||||||
|
python3 $MAKE_PACKAGE_PATH
|
9
bazel/bazel_utils/nixpkgs/default.nix
Normal file
9
bazel/bazel_utils/nixpkgs/default.nix
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
let
|
||||||
|
# 2021-02-19
|
||||||
|
sha256 = "1fwl898f6wznkjpwq11brgadz6iff5w5f4lwj2l7ax2rz7r03mnn";
|
||||||
|
rev = "ad4db3f4d8ae54482c63c31c14921cb73953548d";
|
||||||
|
in
|
||||||
|
import (fetchTarball {
|
||||||
|
inherit sha256;
|
||||||
|
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
|
||||||
|
})
|
38
bazel/bazel_utils/packaging/BUILD.bazel
Normal file
38
bazel/bazel_utils/packaging/BUILD.bazel
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# load("@os_info//:os_info.bzl", "is_windows")
|
||||||
|
is_windows = False
|
||||||
|
|
||||||
|
sh_binary(
|
||||||
|
name = "package-app",
|
||||||
|
srcs = ["package-app.sh"],
|
||||||
|
data = [
|
||||||
|
"@gzip//:bin/gzip",
|
||||||
|
"@tar//:bin/tar",
|
||||||
|
"@glibc-bin//:bin/ldd",
|
||||||
|
"@utillinux//:bin/rev",
|
||||||
|
"//bazel/bazel_utils/sh:mktgz",
|
||||||
|
] + (["@patchelf//:bin/patchelf"] if not is_windows else []),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["@bazel_tools//tools/bash/runfiles"],
|
||||||
|
)
|
||||||
|
|
||||||
|
sh_binary(
|
||||||
|
name = "bundle-apps",
|
||||||
|
srcs = ["bundle-apps.sh"],
|
||||||
|
data = [
|
||||||
|
"@gzip//:bin/gzip",
|
||||||
|
"@tar//:bin/tar",
|
||||||
|
"//bazel/bazel_utils/sh:mktgz",
|
||||||
|
],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["@bazel_tools//tools/bash/runfiles"],
|
||||||
|
)
|
||||||
|
|
||||||
|
exports_files([
|
||||||
|
"package-app.sh",
|
||||||
|
"bundel-app.sh",
|
||||||
|
"asterius_bundle.BUILD.bazel",
|
||||||
|
"wasm_cc_toolchain.bzl",
|
||||||
|
])
|
78
bazel/bazel_utils/packaging/asterius_bundle.BUILD.bazel
Normal file
78
bazel/bazel_utils/packaging/asterius_bundle.BUILD.bazel
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
# This BUILD file is used in particular by rules_haskell. In order to import and use the bundle.
|
||||||
|
load("wasm_cc_toolchain.bzl", "cc_toolchain_config")
|
||||||
|
exports_files(glob(["**"]))
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "asterius_binaries",
|
||||||
|
srcs = glob(["bazel_build/wrappers/**"]),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
data = [":local_asterius"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "local_asterius",
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "wasi_files",
|
||||||
|
# srcs = glob(["bin/**", "lib", "share", "resources/wasilibc/**"]),
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_toolchain_config(
|
||||||
|
name = "wasm_cc_toolchain_config_linux_x86_64",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
file_from_wasi_sysroot_include = "//:share/wasi-sysroot/include/__errno.h",
|
||||||
|
file_from_asterius_libs_include = "//:asterius-0.0.1_data/.boot/asterius_lib/include/Cmm.h",
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_toolchain(
|
||||||
|
name = "wasm_cc",
|
||||||
|
toolchain_config = ":wasm_cc_toolchain_config_linux_x86_64",
|
||||||
|
all_files = ":wasi_files",
|
||||||
|
compiler_files = ":wasi_files",
|
||||||
|
ar_files = ":wasi_files",
|
||||||
|
dwp_files = ":wasi_files",
|
||||||
|
linker_files = ":wasi_files",
|
||||||
|
objcopy_files = ":wasi_files",
|
||||||
|
strip_files = ":wasi_files",
|
||||||
|
# libc_top = ":wasi_files",
|
||||||
|
)
|
||||||
|
|
||||||
|
# sh_binary(
|
||||||
|
# name = "ahc_wrapper",
|
||||||
|
# srcs = ["test/wrappers/ahc"],
|
||||||
|
# visibility = ["//visibility:public"],
|
||||||
|
# )
|
||||||
|
|
||||||
|
# sh_binary(
|
||||||
|
# name = "ahc_cabal_wrapper",
|
||||||
|
# srcs = ["test/wrappers/ahc-cabal"],
|
||||||
|
# visibility = ["//visibility:public"],
|
||||||
|
# )
|
||||||
|
|
||||||
|
# sh_binary(
|
||||||
|
# name = "ahc_dist_wrapper",
|
||||||
|
# srcs = ["test/wrappers/ahc-dist"],
|
||||||
|
# visibility = ["//visibility:public"],
|
||||||
|
# )
|
||||||
|
# sh_binary(
|
||||||
|
# name = "ahc_ld_wrapper",
|
||||||
|
# srcs = ["test/wrappers/ahc-ld"],
|
||||||
|
# visibility = ["//visibility:public"],
|
||||||
|
# )
|
||||||
|
# sh_binary(
|
||||||
|
# name = "ahc_link_wrapper",
|
||||||
|
# srcs = ["test/wrappers/ahc-link"],
|
||||||
|
# visibility = ["//visibility:public"],
|
||||||
|
# )
|
||||||
|
|
||||||
|
# sh_binary(
|
||||||
|
# name = "ahc_pkg_wrapper",
|
||||||
|
# srcs = ["test/wrappers/ahc-pkg"],
|
||||||
|
# visibility = ["//visibility:public"],
|
||||||
|
# )
|
145
bazel/bazel_utils/packaging/bundle-apps.sh
Executable file
145
bazel/bazel_utils/packaging/bundle-apps.sh
Executable file
@ -0,0 +1,145 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# Copy-pasted from the Bazel Bash runfiles library v2.
|
||||||
|
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||||
|
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$0.runfiles/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
||||||
|
# --- end runfiles.bash initialization v2 ---
|
||||||
|
|
||||||
|
# Make sure that runfiles and tools are still found after we change directory.
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin)
|
||||||
|
abspath() { python -c 'import os.path, sys; sys.stdout.write(os.path.abspath(sys.argv[1]))' "$@"; }
|
||||||
|
canonicalpath() { python -c 'import os.path, sys; sys.stdout.write(os.path.realpath(sys.argv[1]))' "$@"; }
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
abspath() { realpath -s "$@"; }
|
||||||
|
canonicalpath() { readlink -f "$@"; }
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ -n ${RUNFILES_DIR:-} ]]; then
|
||||||
|
export RUNFILES_DIR=$(abspath $RUNFILES_DIR)
|
||||||
|
fi
|
||||||
|
if [[ -n ${RUNFILES_MANIFEST_FILE:-} ]]; then
|
||||||
|
export RUNFILES_DIR=$(abspath $RUNFILES_MANIFEST_FILE)
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin|Linux)
|
||||||
|
# find tar
|
||||||
|
tar=$(abspath $(rlocation tar/bin/tar))
|
||||||
|
gzip=$(abspath $(rlocation gzip/bin/gzip))
|
||||||
|
mktgz=$(abspath $(rlocation bazel_asterius/bazel/bazel_utils/sh/mktgz))
|
||||||
|
;;
|
||||||
|
CYGWIN*|MINGW*|MSYS*)
|
||||||
|
tar=$(abspath $(rlocation tar/usr/bin/tar.exe))
|
||||||
|
gzip=$(abspath $(rlocation gzip/urs/bin/gzip.exe))
|
||||||
|
mktgz=$(abspath $(rlocation bazel_asterius/bazel/bazel_utils/sh/mktgz.exe))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
set -eou pipefail
|
||||||
|
|
||||||
|
set -x
|
||||||
|
WORKDIR="$(mktemp -d)"
|
||||||
|
trap "rm -rf $WORKDIR" EXIT
|
||||||
|
|
||||||
|
|
||||||
|
OUT=$(abspath $1)
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
# Copy in resources, if any.
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
for res in $*; do
|
||||||
|
if [[ "$res" == *.tar.gz ]]; then
|
||||||
|
# If a resource is a tarball, e.g., because it originates from another
|
||||||
|
# rule we extract it.
|
||||||
|
# $tar xf "$res" --strip-components=3 -C "$WORKDIR"
|
||||||
|
$tar xf "$res" -C "$WORKDIR"
|
||||||
|
else
|
||||||
|
echo "res = $res"
|
||||||
|
cp -aL "$res" "$WORKDIR"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Rename BUILD file.
|
||||||
|
if [ -f "$WORKDIR/asterius_bundle.BUILD.bazel" ]; then
|
||||||
|
mv "$WORKDIR/asterius_bundle.BUILD.bazel" "$WORKDIR/BUILD.bazel"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# build a wasi_sdk_path folder with the right structure,
|
||||||
|
# because we now use the wrapper scripts and not the binaries directly.
|
||||||
|
|
||||||
|
# mkdir -p "$WORKDIR/wasi_sdk_path/bin"
|
||||||
|
# ln -s "../../ressources/wasilibc/wasi-sdk-12.0/bin/git-clang-format" "$WORKDIR/wasi_sdk_path/bin/git-clang-format"
|
||||||
|
# ln -s "../../ar" "$WORKDIR/wasi_sdk_path/bin/ar"
|
||||||
|
# ln -s "../../clang" "$WORKDIR/wasi_sdk_path/bin/clang"
|
||||||
|
# ln -s "../../clang-11" "$WORKDIR/wasi_sdk_path/bin/clang-11"
|
||||||
|
# ln -s "../../clang-cl" "$WORKDIR/wasi_sdk_path/bin/clang-cl"
|
||||||
|
# ln -s "../../clang-format" "$WORKDIR/wasi_sdk_path/bin/clang-format"
|
||||||
|
# ln -s "../../ld64.lld" "$WORKDIR/wasi_sdk_path/bin/ld64.lld"
|
||||||
|
# ln -s "../../lld-link" "$WORKDIR/wasi_sdk_path/bin/lld-link"
|
||||||
|
# ln -s "../../llvn-cxxfilt" "$WORKDIR/wasi_sdk_path/bin/llvm-cxxfilt"
|
||||||
|
# ln -s "../../llvn-nm" "$WORKDIR/wasi_sdk_path/bin/llvm-nm"
|
||||||
|
# ln -s "../../llvn-objdump" "$WORKDIR/wasi_sdk_path/bin/llvm-objdump"
|
||||||
|
# ln -s "../../llvn-size" "$WORKDIR/wasi_sdk_path/bin/llvm-size"
|
||||||
|
# ln -s "../../llvn-strip" "$WORKDIR/wasi_sdk_path/bin/llvm-strip"
|
||||||
|
# ln -s "../../objcopy" "$WORKDIR/wasi_sdk_path/bin/objcopy"
|
||||||
|
# ln -s "../../strings" "$WORKDIR/wasi_sdk_path/bin/strings"
|
||||||
|
# ln -s "../../wasm-ld" "$WORKDIR/wasi_sdk_path/bin/wasm-ld"
|
||||||
|
# ln -s "../../c++filt" "$WORKDIR/wasi_sdk_path/bin/c++filt"
|
||||||
|
# ln -s "../../clang++" "$WORKDIR/wasi_sdk_path/bin/clang++"
|
||||||
|
# ln -s "../../clang-apply-replacements" "$WORKDIR/wasi_sdk_path/bin/clang-apply-replacements"
|
||||||
|
# ln -s "../../clang-cpp" "$WORKDIR/wasi_sdk_path/bin/clang-cpp"
|
||||||
|
# ln -s "../../clang-tidy" "$WORKDIR/wasi_sdk_path/bin/clang-tidy"
|
||||||
|
# ln -s "../../ld.lld" "$WORKDIR/wasi_sdk_path/bin/ld.lld"
|
||||||
|
# ln -s "../../lld" "$WORKDIR/wasi_sdk_path/bin/lld"
|
||||||
|
# ln -s "../../llvm-ar" "$WORKDIR/wasi_sdk_path/bin/llvm-ar"
|
||||||
|
# ln -s "../../llvm-dwarfdump" "$WORKDIR/wasi_sdk_path/bin/llvm-dwarfdump"
|
||||||
|
# ln -s "../../llvm-objcopy" "$WORKDIR/wasi_sdk_path/bin/llvm-objcopy"
|
||||||
|
# ln -s "../../llvm-ranlib" "$WORKDIR/wasi_sdk_path/bin/llvm-ranlib"
|
||||||
|
# ln -s "../../llvm-strings" "$WORKDIR/wasi_sdk_path/bin/llvm-strings"
|
||||||
|
# ln -s "../../nm" "$WORKDIR/wasi_sdk_path/bin/nm"
|
||||||
|
# ln -s "../../objdump" "$WORKDIR/wasi_sdk_path/bin/objdump"
|
||||||
|
# ln -s "../../size" "$WORKDIR/wasi_sdk_path/bin/size"
|
||||||
|
# ln -s "../../strip" "$WORKDIR/wasi_sdk_path/bin/strip"
|
||||||
|
|
||||||
|
# ln -s "../resources/wasilibc/wasi-sdk-12.0/lib" "$WORKDIR/wasi_sdk_path/lib"
|
||||||
|
# ln -s "resources/wasilibc/wasi-sdk-12.0/lib" "$WORKDIR/lib"
|
||||||
|
# ln -s "../resources/wasilibc/wasi-sdk-12.0/share" "$WORKDIR/wasi_sdk_path/share"
|
||||||
|
|
||||||
|
if [ -f "$WORKDIR/wasi_folder/resources/wasilibc/wasi-sdk-12.1g41fa3294474c/lib" ]; then
|
||||||
|
ln -s "wasi_folder/resources/wasilibc/wasi-sdk-12.1g41fa3294474c/lib" "$WORKDIR/lib"
|
||||||
|
# ln -s "wasi_folder/resources/wasilibc/wasi-sdk-12.1g41fa3294474c/lib" "$WORKDIR/bin/lib"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Some of the binaries may need to be in the same folder to work together.
|
||||||
|
# Since all of them need to be called throught the wrapper scripts,
|
||||||
|
# next to each binary, we add symlinks to the wrapper script of the other ones.
|
||||||
|
|
||||||
|
for target_dir_abs in $WORKDIR/bin_*; do
|
||||||
|
target_dir=$(basename $target_dir_abs)
|
||||||
|
echo "target_dir=$target_dir"
|
||||||
|
target=${target_dir:4}
|
||||||
|
echo "target=$target"
|
||||||
|
for src_dir_abs in $WORKDIR/bin_*; do
|
||||||
|
src_dir=$(basename $src_dir_abs)
|
||||||
|
echo "src_dir=$src_dir"
|
||||||
|
src=${src_dir:4}
|
||||||
|
echo "src=$src"
|
||||||
|
if [ $target != $src ]; then
|
||||||
|
ln -s "../$target" "$src_dir_abs/$target"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# $mktgz $OUT -C "$WORKDIR" .
|
||||||
|
$mktgz $OUT -C "$WORKDIR" .
|
254
bazel/bazel_utils/packaging/package-app.sh
Executable file
254
bazel/bazel_utils/packaging/package-app.sh
Executable file
@ -0,0 +1,254 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# package-app <binary> <output file> <resources...>
|
||||||
|
|
||||||
|
# On Linux and MacOS we handle dynamically linked binaries as follows:
|
||||||
|
# 1. Create a temporary directory and lib directory
|
||||||
|
# 2. Copy the binary to the temporary directory
|
||||||
|
# 3. Use platform specific tools to extract names of the
|
||||||
|
# dynamic libraries and copy them to lib directory.
|
||||||
|
# 4. Create a wrapper or patch the binary.
|
||||||
|
# 5. Create tarball out of the temporary directory.
|
||||||
|
# 6. Clean up.
|
||||||
|
|
||||||
|
# On Windows we only handle statically linked binaries
|
||||||
|
# (Haskell binaries are linked statically on Windows) so we
|
||||||
|
# just copy the binary and the resources and create a tarball from that.
|
||||||
|
|
||||||
|
# Copy-pasted from the Bazel Bash runfiles library v2.
|
||||||
|
set -xe
|
||||||
|
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||||
|
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$0.runfiles/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
||||||
|
# --- end runfiles.bash initialization v2 ---
|
||||||
|
|
||||||
|
# Make sure that runfiles and tools are still found after we change directory.
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin)
|
||||||
|
abspath() { python -c 'import os.path, sys; sys.stdout.write(os.path.abspath(sys.argv[1]))' "$@"; }
|
||||||
|
canonicalpath() { python -c 'import os.path, sys; sys.stdout.write(os.path.realpath(sys.argv[1]))' "$@"; }
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
abspath() { realpath -s "$@"; }
|
||||||
|
canonicalpath() { readlink -f "$@"; }
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ -n ${RUNFILES_DIR:-} ]]; then
|
||||||
|
export RUNFILES_DIR=$(abspath $RUNFILES_DIR)
|
||||||
|
fi
|
||||||
|
if [[ -n ${RUNFILES_MANIFEST_FILE:-} ]]; then
|
||||||
|
export RUNFILES_DIR=$(abspath $RUNFILES_MANIFEST_FILE)
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin|Linux)
|
||||||
|
# find tar
|
||||||
|
tar=$(abspath $(rlocation tar/bin/tar))
|
||||||
|
gzip=$(abspath $(rlocation gzip/bin/gzip))
|
||||||
|
mktgz=$(abspath $(rlocation bazel_asterius/bazel/bazel_utils/sh/mktgz))
|
||||||
|
patchelf=$(abspath $(rlocation patchelf/bin/patchelf))
|
||||||
|
ldd=$(abspath $(rlocation glibc-bin/bin/ldd))
|
||||||
|
rev=$(abspath $(rlocation utillinux/bin/rev))
|
||||||
|
;;
|
||||||
|
CYGWIN*|MINGW*|MSYS*)
|
||||||
|
tar=$(abspath $(rlocation tar/usr/bin/tar.exe))
|
||||||
|
gzip=$(abspath $(rlocation gzip/urs/bin/gzip.exe))
|
||||||
|
mktgz=$(abspath $(rlocation bazel_asterius/bazel/bazel_utils/sh/mktgz.exe))
|
||||||
|
ldd=$(abspath $(rlocation glibc-bin/bin/ldd.exe))
|
||||||
|
rev=$(abspath $(rlocation utilslinux/bin/rev.exe))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
set -eou pipefail
|
||||||
|
|
||||||
|
WORKDIR="$(mktemp -d)"
|
||||||
|
trap "rm -rf $WORKDIR" EXIT
|
||||||
|
|
||||||
|
SRC=$(abspath $1)
|
||||||
|
OUT=$(abspath $2)
|
||||||
|
shift 2
|
||||||
|
NAME=$(basename $SRC)
|
||||||
|
mkdir -p $WORKDIR/$NAME/dynlib
|
||||||
|
mkdir -p "$WORKDIR/$NAME/bin_$NAME"
|
||||||
|
export ORIGIN=$(dirname $(canonicalpath $SRC)) # for rpaths relative to binary
|
||||||
|
|
||||||
|
# Copy in resources, if any.
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
mkdir -p $WORKDIR/$NAME/resources
|
||||||
|
for res in $*; do
|
||||||
|
if [[ "$res" == *.tar.gz ]]; then
|
||||||
|
# If a resource is a tarball, e.g., because it originates from another
|
||||||
|
# rule we extract it.
|
||||||
|
$tar xf "$res" --strip-components=1 -C "$WORKDIR/$NAME/resources"
|
||||||
|
else
|
||||||
|
cp -aL "$res" "$WORKDIR/$NAME/resources"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy the binary, patch it, and create a wrapper script if necessary.
|
||||||
|
if [ "$(uname -s)" == "Linux" ]; then
|
||||||
|
binary="$WORKDIR/$NAME/bin_$NAME/$NAME"
|
||||||
|
cp $SRC $binary
|
||||||
|
chmod u+w $binary
|
||||||
|
rpaths_binary=$($patchelf --print-rpath "$binary"|tr ':' ' ')
|
||||||
|
function copy_deps {
|
||||||
|
local from target needed libOK rpaths interpreter
|
||||||
|
from=$1
|
||||||
|
target=$2
|
||||||
|
needed=$($patchelf --print-needed "$from")
|
||||||
|
rpaths="$($patchelf --print-rpath "$from"|tr ':' ' ') $rpaths_binary"
|
||||||
|
|
||||||
|
for lib in $needed; do
|
||||||
|
if [ ! -f "$target/$lib" ]; then
|
||||||
|
libOK=0
|
||||||
|
for rpath in $rpaths; do
|
||||||
|
rpath="$(eval echo $rpath)" # expand variables, e.g. $ORIGIN
|
||||||
|
if [ -e "$rpath/$lib" ]; then
|
||||||
|
libOK=1
|
||||||
|
if [ "$lib" != "ld-linux-x86-64.so.2" ]; then
|
||||||
|
# clear the old rpaths (silence stderr as it always warns
|
||||||
|
# with "working around a Linux kernel bug".
|
||||||
|
cp "$rpath/$lib" "$target/$lib"
|
||||||
|
chmod u+w "$target/$lib"
|
||||||
|
$patchelf --set-rpath '$ORIGIN' "$target/$lib" 2> /dev/null
|
||||||
|
copy_deps "$rpath/$lib" "$target"
|
||||||
|
else
|
||||||
|
cp -f "$rpath/$lib" "$WORKDIR/$NAME/$lib"
|
||||||
|
chmod u+w "$WORKDIR/$NAME/$lib"
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ $libOK -ne 1 ]; then
|
||||||
|
libPath=$($ldd "$from" | grep "$lib" | $rev | cut -d " " -f2 | $rev | xargs)
|
||||||
|
echo "libPath=$libPath"
|
||||||
|
if [ -e "$libPath" ]; then
|
||||||
|
libOK=1
|
||||||
|
if [ "$lib" != "ld-linux-x86-64.so.2" ]; then
|
||||||
|
# clear the old rpaths (silence stderr as it always warns
|
||||||
|
# with "working around a Linux kernel bug".
|
||||||
|
cp "$libPath" "$target/$lib"
|
||||||
|
chmod u+w "$target/$lib"
|
||||||
|
$patchelf --set-rpath '$ORIGIN' "$target/$lib" 2> /dev/null
|
||||||
|
copy_deps "$libPath" "$target"
|
||||||
|
else
|
||||||
|
cp -f "$libPath" "$WORKDIR/$NAME/$lib"
|
||||||
|
chmod u+w "$WORKDIR/$NAME/$lib"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ $libOK -ne 1 ]; then
|
||||||
|
echo "ERROR: Dynamic library $lib for $from not found from RPATH!"
|
||||||
|
echo "RPATH=$rpaths"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy the binary's dynamic library dependencies.
|
||||||
|
copy_deps "$binary" "$WORKDIR/$NAME/dynlib"
|
||||||
|
|
||||||
|
# Workaround for dynamically loaded name service switch libraries
|
||||||
|
(shopt -s nullglob
|
||||||
|
for rpath in $rpaths_binary; do
|
||||||
|
for nss in $rpath/libnss_dns* $rpath/libnss_files* $rpath/libresolv*; do
|
||||||
|
cp -af "$nss" "$WORKDIR/$NAME/dynlib"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
)
|
||||||
|
|
||||||
|
$patchelf --set-rpath '$ORIGIN/dynlib' "$binary"
|
||||||
|
$patchelf --set-interpreter ld-undefined.so "$binary"
|
||||||
|
|
||||||
|
# Link resources directory to lib, as that'll be the actual
|
||||||
|
# binary's location.
|
||||||
|
test -d "$WORKDIR/$NAME/resources" &&
|
||||||
|
ln -s "../resources" "$WORKDIR/$NAME/dynlib/resources"
|
||||||
|
|
||||||
|
# Create the wrapper script
|
||||||
|
wrapper="$WORKDIR/$NAME/$NAME"
|
||||||
|
cat > "$wrapper" <<EOF
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
SOURCE_DIR="\$(cd \$(dirname \$(readlink -f "\$0")); pwd)"
|
||||||
|
LIB_DIR="\$SOURCE_DIR/dynlib"
|
||||||
|
if [ -z "\${LOCALE_ARCHIVE}" -a -f "/usr/lib/locale/locale-archive" ]; then
|
||||||
|
export LOCALE_ARCHIVE="/usr/lib/locale/locale-archive"
|
||||||
|
fi
|
||||||
|
# Execute the wrapped application through the provided dynamic linker
|
||||||
|
exec \$SOURCE_DIR/ld-linux-x86-64.so.2 --library-path "\$LIB_DIR" "\$SOURCE_DIR/bin_$NAME/$NAME" "\$@"
|
||||||
|
EOF
|
||||||
|
chmod a+x "$wrapper"
|
||||||
|
elif [[ "$(uname -s)" == "Darwin" ]]; then
|
||||||
|
cp $SRC $WORKDIR/$NAME/$NAME
|
||||||
|
chmod u+w $WORKDIR/$NAME/$NAME
|
||||||
|
function copy_deps() {
|
||||||
|
local from_original=$(canonicalpath $1)
|
||||||
|
local from_copied=$2
|
||||||
|
local needed="$(/usr/bin/otool -L "$from_copied" | sed -n -e '1d' -e 's/^\s*\([^ ]*\).*$/\1/p')"
|
||||||
|
# Note that it is crucial that we resolve loader_path relative to from_original instead of from_copied
|
||||||
|
loader_path="$(dirname $from_original)"
|
||||||
|
local rpaths="$(/usr/bin/otool -l $from_original | sed -n '/cmd LC_RPATH/{n;n;p;}' | sed -n -e 's/^ *path \([^ ]*\).*$/\1/p' | sed -e "s|@loader_path|$loader_path|")"
|
||||||
|
for lib in $needed; do
|
||||||
|
local libName="$(basename $lib)"
|
||||||
|
if [[ "$libName" == "libSystem.B.dylib" ]]; then
|
||||||
|
/usr/bin/install_name_tool -change "$lib" "/usr/lib/$libName" "$from_copied"
|
||||||
|
elif [ -e "/usr/lib/system/$libName" ]; then
|
||||||
|
/usr/bin/install_name_tool -change "$lib" "/usr/lib/system/$libName" "$from_copied"
|
||||||
|
elif [[ "$lib" == @rpath/* ]]; then
|
||||||
|
libName="${lib#@rpath/}"
|
||||||
|
/usr/bin/install_name_tool -change "$lib" "@rpath/$(basename $libName)" "$from_copied"
|
||||||
|
local to="$WORKDIR/$NAME/dynlib/$(basename $libName)"
|
||||||
|
if [[ ! -f "$to" ]]; then
|
||||||
|
libOK=0
|
||||||
|
for rpath in $rpaths; do
|
||||||
|
if [[ -e "$rpath/$libName" ]]; then
|
||||||
|
libOK=1
|
||||||
|
cp "$rpath/$libName" "$to"
|
||||||
|
chmod 0755 "$to"
|
||||||
|
/usr/bin/install_name_tool -add_rpath "@loader_path/dynlib" "$to"
|
||||||
|
copy_deps "$rpath/$libName" "$to"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ $libOK -ne 1 ]]; then
|
||||||
|
echo "ERROR: Dynamic library $lib for $from_original not found from RPATH!"
|
||||||
|
echo "RPATH=$rpaths"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
/usr/bin/install_name_tool -change "$lib" "@rpath/$libName" "$from_copied"
|
||||||
|
|
||||||
|
local to="$WORKDIR/$NAME/dynlib/$libName"
|
||||||
|
if [ ! -f "$to" ]; then
|
||||||
|
cp "$lib" "$to"
|
||||||
|
chmod 0755 "$to"
|
||||||
|
/usr/bin/install_name_tool -add_rpath "@loader_path/dynlib" "$to"
|
||||||
|
|
||||||
|
# Traverse the library as well to find the closure
|
||||||
|
copy_deps "$lib" "$to"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
# Set the dynamic library load path to the relative lib/ directory.
|
||||||
|
/usr/bin/install_name_tool -add_rpath "@loader_path/dynlib" $WORKDIR/$NAME/$NAME
|
||||||
|
|
||||||
|
# Copy all dynamic library dependencies referred to from our binary
|
||||||
|
copy_deps $SRC $WORKDIR/$NAME/$NAME
|
||||||
|
else
|
||||||
|
cp "$SRC" "$WORKDIR/$NAME/$NAME"
|
||||||
|
fi
|
||||||
|
# cd $WORKDIR && $mktgz $OUT $NAME
|
||||||
|
$mktgz $OUT -C "$WORKDIR/$NAME" .
|
||||||
|
echo "after"
|
||||||
|
ls $OUT
|
110
bazel/bazel_utils/packaging/packaging.bzl
Normal file
110
bazel/bazel_utils/packaging/packaging.bzl
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
"""Packaging of Linux, macOS and Windows binaries into tarballs"""
|
||||||
|
|
||||||
|
# load("@os_info//:os_info.bzl", "is_windows")
|
||||||
|
|
||||||
|
def _bundle_apps_impl(ctx):
|
||||||
|
args = ctx.actions.args()
|
||||||
|
args.add(ctx.outputs.out.path)
|
||||||
|
args.add_all(ctx.attr.packaged_apps, map_each = _get_resource_path)
|
||||||
|
posix_info = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
|
||||||
|
ctx.actions.run(
|
||||||
|
executable = ctx.executable.bundle_apps,
|
||||||
|
outputs = [ctx.outputs.out],
|
||||||
|
inputs = ctx.files.packaged_apps,
|
||||||
|
tools = [],
|
||||||
|
arguments = [args],
|
||||||
|
progress_message = "Packaging " + ctx.attr.name,
|
||||||
|
env = {"PATH": ":".join(posix_info.paths)},
|
||||||
|
)
|
||||||
|
|
||||||
|
def _package_app_impl(ctx):
|
||||||
|
args = ctx.actions.args()
|
||||||
|
args.add(ctx.executable.binary.path)
|
||||||
|
args.add(ctx.outputs.out.path)
|
||||||
|
args.add_all(ctx.attr.resources, map_each = _get_resource_path)
|
||||||
|
posix_info = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
|
||||||
|
ctx.actions.run(
|
||||||
|
executable = ctx.executable.package_app,
|
||||||
|
outputs = [ctx.outputs.out],
|
||||||
|
inputs = ctx.files.resources,
|
||||||
|
# Binaries are passed through tools so that Bazel can make the runfiles
|
||||||
|
# tree available to the action.
|
||||||
|
tools = [ctx.executable.binary],
|
||||||
|
arguments = [args],
|
||||||
|
progress_message = "Packaging " + ctx.attr.name,
|
||||||
|
env = {"PATH": ":".join(posix_info.paths)},
|
||||||
|
)
|
||||||
|
|
||||||
|
def _get_resource_path(r):
|
||||||
|
"""Get the path to use for a resource.
|
||||||
|
If the resource has a single file, it'll be copied to
|
||||||
|
the resource root directory. With multiple files the
|
||||||
|
relative directory structure is preserved.
|
||||||
|
|
||||||
|
This mirrors how rules that produce directories work
|
||||||
|
in Buck.
|
||||||
|
"""
|
||||||
|
files = r.files.to_list()
|
||||||
|
if len(files) > 1:
|
||||||
|
first_file = files[0].path
|
||||||
|
prefix_end = first_file.index(r.label.package)
|
||||||
|
# e.g. package foo/bar,
|
||||||
|
# first file at bazel-out/k8-fastbuild/bleh/foo/bar/baz/quux
|
||||||
|
# return path as bazel-out/k8-fastbuild/bleh/foo/bar.
|
||||||
|
return first_file[0:(prefix_end + len(r.label.package) + len(r.label.workspace_root))]
|
||||||
|
else:
|
||||||
|
return files[0].path
|
||||||
|
|
||||||
|
package_app = rule(
|
||||||
|
implementation = _package_app_impl,
|
||||||
|
attrs = dict({
|
||||||
|
"binary": attr.label(
|
||||||
|
cfg = "target",
|
||||||
|
executable = True,
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
|
"resources": attr.label_list(
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
|
"package_app": attr.label(
|
||||||
|
default = Label("//bazel/bazel_utils/packaging:package-app"),
|
||||||
|
cfg = "host",
|
||||||
|
executable = True,
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
outputs = {
|
||||||
|
"out": "%{name}.tar.gz",
|
||||||
|
},
|
||||||
|
toolchains = ["@rules_sh//sh/posix:toolchain_type"],
|
||||||
|
)
|
||||||
|
"""Package a binary along with its dynamic library dependencies and data dependencies
|
||||||
|
into a tarball. The data dependencies are placed in 'resources' directory.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
bundle_apps = rule(
|
||||||
|
implementation = _bundle_apps_impl,
|
||||||
|
attrs = dict({
|
||||||
|
"packaged_apps": attr.label_list(
|
||||||
|
cfg = "target",
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
|
"bundle_apps": attr.label(
|
||||||
|
default = Label("//bazel/bazel_utils/packaging:bundle-apps"),
|
||||||
|
cfg = "exec",
|
||||||
|
executable = True,
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
outputs = {
|
||||||
|
"out": "%{name}.tar.gz",
|
||||||
|
},
|
||||||
|
toolchains = ["@rules_sh//sh/posix:toolchain_type"],
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
Bundle packages created by the package_app rule into one tarball.
|
||||||
|
"""
|
163
bazel/bazel_utils/packaging/wasm_cc_toolchain.bzl
Normal file
163
bazel/bazel_utils/packaging/wasm_cc_toolchain.bzl
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
load("@bazel_skylib//lib:paths.bzl", "paths")
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
|
||||||
|
"ACTION_NAMES",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
|
||||||
|
"tool_path",
|
||||||
|
"feature",
|
||||||
|
"flag_group",
|
||||||
|
"flag_set",
|
||||||
|
)
|
||||||
|
|
||||||
|
def _impl(ctx):
|
||||||
|
# posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
|
||||||
|
# ar_path = posix.commands["ar"]
|
||||||
|
tool_paths = [
|
||||||
|
tool_path(
|
||||||
|
name = "gcc",
|
||||||
|
path = "bin/clang",
|
||||||
|
),
|
||||||
|
tool_path(
|
||||||
|
name = "ld",
|
||||||
|
path = "bin/wasm-ld",
|
||||||
|
),
|
||||||
|
tool_path(
|
||||||
|
name = "ar",
|
||||||
|
path = "bin/ar",
|
||||||
|
),
|
||||||
|
tool_path(
|
||||||
|
name = "cpp",
|
||||||
|
path = "bin/clang++",
|
||||||
|
),
|
||||||
|
tool_path(
|
||||||
|
name = "gcov",
|
||||||
|
path = "gcov_not_supported.sh",
|
||||||
|
),
|
||||||
|
tool_path(
|
||||||
|
name = "nm",
|
||||||
|
path = "bin/nm",
|
||||||
|
),
|
||||||
|
tool_path(
|
||||||
|
name = "objdump",
|
||||||
|
path = "bin/objdump",
|
||||||
|
),
|
||||||
|
tool_path(
|
||||||
|
name = "strip",
|
||||||
|
path = "bin/strip",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
sysroot = paths.dirname(paths.dirname(ctx.file.file_from_wasi_sysroot_include.path))
|
||||||
|
print("sysroot =", sysroot)
|
||||||
|
asterius_include = paths.dirname(ctx.file.file_from_asterius_libs_include.path)
|
||||||
|
default_flags = feature(
|
||||||
|
name = "default_flags",
|
||||||
|
enabled = True,
|
||||||
|
flag_sets = [
|
||||||
|
flag_set(
|
||||||
|
actions = [
|
||||||
|
#ACTION_NAMES.c_compile,
|
||||||
|
#ACTION_NAMES.cpp_compile,
|
||||||
|
# ACTION_NAMES.linkstamp_compile
|
||||||
|
# ACTION_NAMES.cc_flags_make_variable
|
||||||
|
# ACTION_NAMES.cpp_module_codegen
|
||||||
|
# ACTION_NAMES.cpp_header_parsing
|
||||||
|
# ACTION_NAMES.cpp_module_compile
|
||||||
|
# ACTION_NAMES.assemble
|
||||||
|
# ACTION_NAMES.preprocess_assemble
|
||||||
|
# ACTION_NAMES.llvm_cov
|
||||||
|
# ACTION_NAMES.lto_indexing
|
||||||
|
# ACTION_NAMES.lto_backend
|
||||||
|
# ACTION_NAMES.lto_index_for_executable
|
||||||
|
# ACTION_NAMES.lto_index_for_dynamic_library
|
||||||
|
# ACTION_NAMES.lto_index_for_nodeps_dynamic_library
|
||||||
|
# ACTION_NAMES.cpp_link_executable
|
||||||
|
# ACTION_NAMES.cpp_link_dynamic_library
|
||||||
|
# ACTION_NAMES.cpp_link_nodeps_dynamic_library
|
||||||
|
# ACTION_NAMES.cpp_link_static_library
|
||||||
|
# ACTION_NAMES.strip
|
||||||
|
# ACTION_NAMES.objc_archive
|
||||||
|
# ACTION_NAMES.objc_compile
|
||||||
|
# ACTION_NAMES.objc_executable
|
||||||
|
# ACTION_NAMES.objc_fully_link
|
||||||
|
# ACTION_NAMES.objcpp_compile
|
||||||
|
# ACTION_NAMES.objcpp_executable
|
||||||
|
# ACTION_NAMES.clif_match
|
||||||
|
ACTION_NAMES.assemble,
|
||||||
|
ACTION_NAMES.preprocess_assemble,
|
||||||
|
ACTION_NAMES.linkstamp_compile,
|
||||||
|
ACTION_NAMES.c_compile,
|
||||||
|
ACTION_NAMES.cpp_compile,
|
||||||
|
ACTION_NAMES.cpp_header_parsing,
|
||||||
|
ACTION_NAMES.cpp_module_compile,
|
||||||
|
ACTION_NAMES.cpp_module_codegen,
|
||||||
|
ACTION_NAMES.lto_backend,
|
||||||
|
ACTION_NAMES.clif_match,
|
||||||
|
],
|
||||||
|
flag_groups = [
|
||||||
|
flag_group(
|
||||||
|
flags = [
|
||||||
|
# "-lstdc++",
|
||||||
|
"--sysroot={}".format(sysroot),
|
||||||
|
"-I{}".format(asterius_include),
|
||||||
|
# "-Oz",
|
||||||
|
"-flto",
|
||||||
|
"-no-canonical-prefixes",
|
||||||
|
"-isystem",
|
||||||
|
"{}/lib/clang/12.0.0/include".format(paths.dirname(paths.dirname(sysroot)))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
return cc_common.create_cc_toolchain_config_info(
|
||||||
|
ctx = ctx,
|
||||||
|
toolchain_identifier = "webassembly_bundle",
|
||||||
|
host_system_name = "local",
|
||||||
|
target_system_name = "wasm64",
|
||||||
|
target_cpu = "wasm64",
|
||||||
|
target_libc = "unknown",
|
||||||
|
compiler = "wasi",
|
||||||
|
abi_version = "unknown",
|
||||||
|
abi_libc_version = "unknown",
|
||||||
|
tool_paths = tool_paths,
|
||||||
|
features = [default_flags],
|
||||||
|
builtin_sysroot = sysroot,
|
||||||
|
# cxx_builtin_include_directories = [
|
||||||
|
# "%sysroot%/lib/clang/12.0.0/include",
|
||||||
|
# "lib/clang/12.0.0/include",
|
||||||
|
|
||||||
|
# # "external/asterius_bundle_rules_haskell_ghc_nixpkgs_haskell_toolchain/bin/lib/clang/12.0.0/include/",
|
||||||
|
# # "%package(@asterius_bundle_rules_haskell_ghc_nixpkgs_haskell_toolchain//)%/bin/lib/clang/12.0.0/include",
|
||||||
|
# # "%package(//)%/bin/lib/clang/12.0.0/include",
|
||||||
|
# # "%package(@asterius_bundle_rules_haskell_ghc_nixpkgs_haskell_toolchain//bin/lib/clang/12.0.0/include)%",
|
||||||
|
# # "/home/stan/.cache/bazel/_bazel_stan/3c7d084a53b480b3a5081e4bf80f09ce/external/asterius_bundle_rules_haskell_ghc_nixpkgs_haskell_toolchain/bin/lib/clang/12.0.0/include",
|
||||||
|
|
||||||
|
# ]
|
||||||
|
) #+ [platform_common.ToolchainInfo(name = "dummy_cpp_toolchain")]
|
||||||
|
|
||||||
|
|
||||||
|
cc_toolchain_config = rule(
|
||||||
|
implementation = _impl,
|
||||||
|
attrs = {
|
||||||
|
"file_from_asterius_libs_include": attr.label(
|
||||||
|
mandatory = True,
|
||||||
|
allow_single_file = True,
|
||||||
|
doc = "a file of the asterius libs include folder, to recover the path of this folder",
|
||||||
|
),
|
||||||
|
"file_from_wasi_sysroot_include": attr.label(
|
||||||
|
mandatory = True,
|
||||||
|
allow_single_file = True,
|
||||||
|
doc = "a file from the wasi sysroot include folder, to recover the path of this folder",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
provides = [CcToolchainConfigInfo],
|
||||||
|
# toolchains = [
|
||||||
|
# "@rules_sh//sh/posix:toolchain_type",
|
||||||
|
# ],
|
||||||
|
)
|
23
bazel/bazel_utils/sh/BUILD.bazel
Normal file
23
bazel/bazel_utils/sh/BUILD.bazel
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
exports_files(["test.sh.tpl"])
|
||||||
|
|
||||||
|
sh_binary(
|
||||||
|
name = "mktar",
|
||||||
|
srcs = ["mktar.sh"],
|
||||||
|
data = ["@tar//:bin/tar"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["@bazel_tools//tools/bash/runfiles"],
|
||||||
|
)
|
||||||
|
|
||||||
|
sh_binary(
|
||||||
|
name = "mktgz",
|
||||||
|
srcs = ["mktgz.sh"],
|
||||||
|
data = [
|
||||||
|
"@gzip//:bin/gzip",
|
||||||
|
"@tar//:bin/tar",
|
||||||
|
],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["@bazel_tools//tools/bash/runfiles"],
|
||||||
|
)
|
45
bazel/bazel_utils/sh/mktar.sh
Executable file
45
bazel/bazel_utils/sh/mktar.sh
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# Copy-pasted from the Bazel Bash runfiles library v2.
|
||||||
|
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||||
|
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$0.runfiles/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
||||||
|
# --- end runfiles.bash initialization v2 ---
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
usage() {
|
||||||
|
cat >&2 <<'EOF'
|
||||||
|
usage: mktar OUTPUT ARGS...
|
||||||
|
|
||||||
|
Creates an uncompressed tarball in OUTPUT passing ARGS to tar. The created
|
||||||
|
tarball is reproducible, i.e. it does not contain any timestamps or similar
|
||||||
|
non-deterministic inputs. See https://reproducible-builds.org/docs/archives/
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
trap usage ERR
|
||||||
|
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin|Linux)
|
||||||
|
tar=$(rlocation tar_dev_env/tar)
|
||||||
|
;;
|
||||||
|
CYGWIN*|MINGW*|MSYS*)
|
||||||
|
tar=$(rlocation tar_dev_env/usr/bin/tar.exe)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
$tar cf "$1" "${@:2}" \
|
||||||
|
--owner="0" \
|
||||||
|
--group="0" \
|
||||||
|
--numeric-owner \
|
||||||
|
--mtime="2000-01-01 00:00Z" \
|
||||||
|
--no-acls \
|
||||||
|
--no-xattrs \
|
||||||
|
--no-selinux \
|
||||||
|
--sort="name" \
|
||||||
|
--format=ustar
|
53
bazel/bazel_utils/sh/mktgz.sh
Executable file
53
bazel/bazel_utils/sh/mktgz.sh
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# Copy-pasted from the Bazel Bash runfiles library v2.
|
||||||
|
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||||
|
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$0.runfiles/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
||||||
|
# --- end runfiles.bash initialization v2 ---
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
usage() {
|
||||||
|
cat >&2 <<'EOF'
|
||||||
|
usage: mktgz OUTPUT ARGS...
|
||||||
|
|
||||||
|
Creates a gzip compressed tarball in OUTPUT passing ARGS to tar. The created
|
||||||
|
tarball is reproducible, i.e. it does not contain any timestamps or similar
|
||||||
|
non-deterministic inputs. See https://reproducible-builds.org/docs/archives/
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
trap usage ERR
|
||||||
|
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin|Linux)
|
||||||
|
tar=$(rlocation tar/bin/tar)
|
||||||
|
gzip=$(rlocation gzip/bin/gzip)
|
||||||
|
;;
|
||||||
|
CYGWIN*|MINGW*|MSYS*)
|
||||||
|
tar=$(rlocation tar/usr/bin/tar.exe)
|
||||||
|
gzip=$(rlocation gzip/usr/bin/gzip.exe)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# using posix format to allow for long link names
|
||||||
|
# for reproducibility added pax-option copy-pasted from here:
|
||||||
|
# http://h2.jaguarpaw.co.uk/posts/reproducible-tar/
|
||||||
|
|
||||||
|
$tar c "${@:2}" \
|
||||||
|
--owner="0" \
|
||||||
|
--group="0" \
|
||||||
|
--numeric-owner \
|
||||||
|
--mtime="2000-01-01 00:00Z" \
|
||||||
|
--no-acls \
|
||||||
|
--no-xattrs \
|
||||||
|
--no-selinux \
|
||||||
|
--sort="name" \
|
||||||
|
--format=posix \
|
||||||
|
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime,delete=mtime \
|
||||||
|
| $gzip -n > "$1"
|
70
bazel/bazel_utils/sh/sh.bzl
Normal file
70
bazel/bazel_utils/sh/sh.bzl
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
load("@os_info//:os_info.bzl", "os_name")
|
||||||
|
|
||||||
|
def _sh_inline_script_impl(ctx):
|
||||||
|
cmd = ctx.attr.cmd
|
||||||
|
cmd = ctx.expand_location(cmd, ctx.attr.data)
|
||||||
|
cmd = ctx.expand_make_variables("cmd", cmd, {})
|
||||||
|
ctx.actions.expand_template(
|
||||||
|
template = ctx.file._template,
|
||||||
|
output = ctx.outputs.output,
|
||||||
|
is_executable = True,
|
||||||
|
substitutions = {
|
||||||
|
"%cmd%": cmd,
|
||||||
|
"%os%": os_name,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
runfiles = ctx.runfiles(files = [ctx.outputs.output] + ctx.files.data)
|
||||||
|
for data_dep in ctx.attr.data:
|
||||||
|
runfiles = runfiles.merge(data_dep[DefaultInfo].default_runfiles)
|
||||||
|
|
||||||
|
return DefaultInfo(
|
||||||
|
files = depset([ctx.outputs.output]),
|
||||||
|
runfiles = runfiles,
|
||||||
|
)
|
||||||
|
|
||||||
|
_sh_inline_script = rule(
|
||||||
|
_sh_inline_script_impl,
|
||||||
|
attrs = {
|
||||||
|
"cmd": attr.string(
|
||||||
|
mandatory = True,
|
||||||
|
),
|
||||||
|
"data": attr.label_list(
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
|
"output": attr.output(
|
||||||
|
mandatory = True,
|
||||||
|
),
|
||||||
|
"_template": attr.label(
|
||||||
|
allow_single_file = True,
|
||||||
|
default = "//bazel_tools/sh:test.sh.tpl",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def sh_inline_test(
|
||||||
|
name,
|
||||||
|
cmd,
|
||||||
|
data = [],
|
||||||
|
toolchains = [],
|
||||||
|
**kwargs):
|
||||||
|
testonly = kwargs.pop("testonly", True)
|
||||||
|
_sh_inline_script(
|
||||||
|
name = name + "_script",
|
||||||
|
cmd = cmd,
|
||||||
|
output = name + ".sh",
|
||||||
|
data = data,
|
||||||
|
testonly = testonly,
|
||||||
|
toolchains = toolchains,
|
||||||
|
)
|
||||||
|
native.sh_test(
|
||||||
|
name = name,
|
||||||
|
data = data,
|
||||||
|
deps = ["@bazel_tools//tools/bash/runfiles"],
|
||||||
|
srcs = [name + ".sh"],
|
||||||
|
testonly = testonly,
|
||||||
|
**kwargs
|
||||||
|
)
|
57
bazel/bazel_utils/sh/test.sh.tpl
Executable file
57
bazel/bazel_utils/sh/test.sh.tpl
Executable file
@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copy-pasted from the Bazel Bash runfiles library v2.
|
||||||
|
set +e
|
||||||
|
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||||
|
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$0.runfiles/$f" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||||
|
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
||||||
|
# --- end runfiles.bash initialization v2 ---
|
||||||
|
canonicalize_rlocation() {
|
||||||
|
# Note (MK): This is a fun one: Let’s say $TEST_WORKSPACE is "compatibility"
|
||||||
|
# and the argument points to a target from an external workspace, e.g.,
|
||||||
|
# @daml-sdk-0.0.0//:daml. Then the short path will point to
|
||||||
|
# ../daml-sdk-0.0.0/daml. Putting things together we end up with
|
||||||
|
# compatibility/../daml-sdk-0.0.0/daml. On Linux and MacOS this works
|
||||||
|
# just fine. However, on windows we need to normalize the path
|
||||||
|
# or rlocation will fail to find the path in the manifest file.
|
||||||
|
rlocation $(realpath -L -s -m --relative-to=$PWD $TEST_WORKSPACE/$1)
|
||||||
|
}
|
||||||
|
get_exe() {
|
||||||
|
# Usage: get_exe FILE...
|
||||||
|
#
|
||||||
|
# On Windows: Return the FILE ending on .exe or the first argument.
|
||||||
|
# On Unix: Return the first argument.
|
||||||
|
|
||||||
|
# Note (AH): Bazel `sh_binary` targets produce multiple outputs.
|
||||||
|
# On Unix `script`, and `script.sh`.
|
||||||
|
# On Windows `script`, `script.exe`, and `script.sh`.
|
||||||
|
# Assuming `srcs = ["script.sh"]`.
|
||||||
|
# This is an issue for macros like `client_server_test` which would like
|
||||||
|
# to determine the path to executables such as.
|
||||||
|
# `$$(canonicalize_rlocation $(rootpath {client}))`.
|
||||||
|
# For a `sh_binary` generated `{client}` this fails since `$(rootpath )` is
|
||||||
|
# not applicable to a target with multiple outputs and we have to use
|
||||||
|
# `$(rootpaths )` instead. This happens to work on Unix because the first
|
||||||
|
# item returned by `$(rootpaths )` is correctly executable. However, on
|
||||||
|
# Windows the required `.exe` wrapper is only the second item returned by
|
||||||
|
# `$(rootpaths )` and consequently the obtained `$client` path cannot be
|
||||||
|
# executed on Windows.
|
||||||
|
# See https://github.com/bazelbuild/bazel/issues/11820.
|
||||||
|
if [[ %os% = windows ]]; then
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [[ $arg = *.exe ]]; then
|
||||||
|
echo "$arg"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "$1"
|
||||||
|
else
|
||||||
|
echo "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
set -e
|
||||||
|
%cmd%
|
||||||
|
# vim: ft=sh
|
82
bazel/make_packages_utils.bzl
Normal file
82
bazel/make_packages_utils.bzl
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
load("@bazel_skylib//lib:new_sets.bzl", "sets")
|
||||||
|
load("@bazel_skylib//lib:paths.bzl", "paths")
|
||||||
|
|
||||||
|
def paths_of_tools(repository_ctx):
|
||||||
|
path = sets.make()
|
||||||
|
ld_library_path = sets.make()
|
||||||
|
for label in repository_ctx.attr.binaries:
|
||||||
|
sets.insert(path, str(repository_ctx.path(label).dirname))
|
||||||
|
|
||||||
|
path_string = ":".join(sets.to_list(path))
|
||||||
|
|
||||||
|
print("end path = ", path_string)
|
||||||
|
return {"PATH_BZL": path_string}
|
||||||
|
|
||||||
|
def _make_packages_impl(repository_ctx):
|
||||||
|
|
||||||
|
# bash
|
||||||
|
bash_path = repository_ctx.path(repository_ctx.attr._bash)
|
||||||
|
|
||||||
|
# nix
|
||||||
|
nix_folder = repository_ctx.path(repository_ctx.attr.nix_shell_file).dirname
|
||||||
|
repository_ctx.symlink(nix_folder, "nix")
|
||||||
|
|
||||||
|
utils_folder = "{}/utils".format(nix_folder.dirname)
|
||||||
|
repository_ctx.symlink(utils_folder, "utils")
|
||||||
|
|
||||||
|
nix_shell_executable = repository_ctx.path(repository_ctx.attr.nix_shell_binary)
|
||||||
|
nix_path = repository_ctx.path(repository_ctx.attr.nixpkgs).dirname
|
||||||
|
|
||||||
|
# repository_ctx.symlink("/home/stan/src/asterius/shell.nix", "shell.nix")
|
||||||
|
make_packages_path = repository_ctx.path("utils/make-packages.py")
|
||||||
|
make_packages_wrapper = repository_ctx.path(repository_ctx.attr._make_packages_wrapper)
|
||||||
|
# cmd = "NIX_PATH={} {}".format(nix_path, make_packages_path)
|
||||||
|
|
||||||
|
# set_path_path = repository_ctx.path(repository_ctx.attr._set_path)
|
||||||
|
|
||||||
|
cmd = "{} {}".format(make_packages_wrapper, make_packages_path)
|
||||||
|
|
||||||
|
out = repository_ctx.execute(
|
||||||
|
# [nix_shell_executable, "nix/bazel-nix-shell.nix", "--pure", "--run", cmd],
|
||||||
|
[bash_path, "-v", "-c", cmd],
|
||||||
|
timeout=600,
|
||||||
|
quiet=False,
|
||||||
|
working_directory="",
|
||||||
|
environment = dict(paths_of_tools(repository_ctx), NIX_PATH = str(nix_path))
|
||||||
|
)
|
||||||
|
print("stderr =", out.stderr)
|
||||||
|
print("stdout =", out.stdout)
|
||||||
|
print("return code =", out.return_code)
|
||||||
|
if out.return_code != 0:
|
||||||
|
fail("call to make_packages failed")
|
||||||
|
|
||||||
|
|
||||||
|
build_files_folder = "{}/bazel/bazel_build_files".format(nix_folder.dirname)
|
||||||
|
build_directories = [
|
||||||
|
"ghc-asterius",
|
||||||
|
"ghc-boot-th-asterius",
|
||||||
|
"ghc-boot-asterius",
|
||||||
|
"ghc-heap-asterius",
|
||||||
|
"ghci-asterius",
|
||||||
|
"template-haskell-asterius",
|
||||||
|
]
|
||||||
|
for d in build_directories:
|
||||||
|
repository_ctx.symlink("{}/BUILD_{}".format(build_files_folder, d), "{}/BUILD.bazel".format(d))
|
||||||
|
|
||||||
|
make_packages = repository_rule(
|
||||||
|
implementation=_make_packages_impl,
|
||||||
|
local=False,
|
||||||
|
attrs={
|
||||||
|
"nix_shell_binary": attr.label(allow_single_file = True, mandatory=True),
|
||||||
|
"nixpkgs":attr.label(allow_single_file = True, mandatory=True),
|
||||||
|
"nix_shell_file": attr.label(allow_single_file = True, mandatory=True),
|
||||||
|
"_make_packages_wrapper":attr.label(
|
||||||
|
allow_single_file = True,
|
||||||
|
default = "//:bazel/bazel_utils/make_packages_wrapper.sh"),
|
||||||
|
"_bash": attr.label(
|
||||||
|
allow_single_file = True,
|
||||||
|
default = "@bash//:bin/bash"
|
||||||
|
),
|
||||||
|
"binaries": attr.label_list(),
|
||||||
|
}
|
||||||
|
)
|
1012
ghc-toolkit/BUILD.bazel
Normal file
1012
ghc-toolkit/BUILD.bazel
Normal file
File diff suppressed because it is too large
Load Diff
1
ghc-toolkit/cabal.project.local
Normal file
1
ghc-toolkit/cabal.project.local
Normal file
@ -0,0 +1 @@
|
|||||||
|
ignore-project: False
|
0
ghc-toolkit/configure
vendored
Normal file
0
ghc-toolkit/configure
vendored
Normal file
@ -7,6 +7,7 @@ where
|
|||||||
|
|
||||||
import Paths_ghc_toolkit
|
import Paths_ghc_toolkit
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
import System.Environment
|
||||||
import System.IO.Unsafe
|
import System.IO.Unsafe
|
||||||
|
|
||||||
bootLibsPath :: FilePath
|
bootLibsPath :: FilePath
|
||||||
@ -15,6 +16,18 @@ bootLibsPath = dataDir </> "boot-libs"
|
|||||||
sandboxGhcLibDir :: FilePath
|
sandboxGhcLibDir :: FilePath
|
||||||
sandboxGhcLibDir = dataDir </> "ghc-libdir"
|
sandboxGhcLibDir = dataDir </> "ghc-libdir"
|
||||||
|
|
||||||
|
getDataDirFromEnv = do
|
||||||
|
e <- getEnvironment
|
||||||
|
let l = [(k, v) | (k, v) <- e, k == "ASTERIUS_DATA_DIR"]
|
||||||
|
case l of
|
||||||
|
[] -> do
|
||||||
|
error "tmp no env"
|
||||||
|
datadir <- Paths_ghc_toolkit.getDataDir
|
||||||
|
pure datadir
|
||||||
|
[(_, datadir)] ->
|
||||||
|
pure datadir
|
||||||
|
|
||||||
{-# NOINLINE dataDir #-}
|
{-# NOINLINE dataDir #-}
|
||||||
dataDir :: FilePath
|
dataDir :: FilePath
|
||||||
dataDir = unsafePerformIO getDataDir
|
-- dataDir = unsafePerformIO getDataDir
|
||||||
|
dataDir = unsafePerformIO getDataDirFromEnv
|
||||||
|
46
nix/bazel-nix-shell.nix
Normal file
46
nix/bazel-nix-shell.nix
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
({ sources ? import ./sources.nix { }
|
||||||
|
, pkgs ? import sources.nixpkgs {
|
||||||
|
overlays = [
|
||||||
|
(import ./binaryenOverlay.nix)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}:
|
||||||
|
with pkgs;
|
||||||
|
pkgs.mkShell {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
haskellPackages.alex
|
||||||
|
bash
|
||||||
|
nix
|
||||||
|
cabal-install
|
||||||
|
autoconf
|
||||||
|
automake
|
||||||
|
binaryen
|
||||||
|
binutils
|
||||||
|
gcc
|
||||||
|
haskell.compiler.ghc884
|
||||||
|
git
|
||||||
|
gmp.dev
|
||||||
|
haskellPackages.happy
|
||||||
|
ncurses.dev
|
||||||
|
nodejs-15_x
|
||||||
|
(python39.withPackages (ps: with ps; [
|
||||||
|
recommonmark
|
||||||
|
sphinx
|
||||||
|
]))
|
||||||
|
stack
|
||||||
|
zlib.dev
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
#export SSL_CERT_FILE="/etc/ssl/certs/ca-certificates.crt"
|
||||||
|
#export NIX_SSL_CERT_FILE="/etc/ssl/certs/ca-certificates.crt"
|
||||||
|
|
||||||
|
# One of the two must be enabled for git clone to work (in the utils/make-packages.py)
|
||||||
|
export GIT_SSL_CAINFO="/etc/ssl/certs/ca-certificates.crt"
|
||||||
|
#export GIT_SSL_NO_VERIFY=true
|
||||||
|
|
||||||
|
|
||||||
|
#export NIX_PATH="nixpkgs=/home/stan/test/bazel/workspace_rules/bazel-workspace_rules/external/rules_haskell/nixpkgs"
|
||||||
|
#export NIX_PATH="nixpkgs=/home/stan/src/asterius/nix"
|
||||||
|
'';
|
||||||
|
}){}
|
47
nix/bazel_deps.nix
Normal file
47
nix/bazel_deps.nix
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
({ sources ? import ./sources.nix {}
|
||||||
|
, config
|
||||||
|
, overlays
|
||||||
|
, pkgs ? import sources.nixpkgs {
|
||||||
|
overlays = [
|
||||||
|
(import ./binaryenOverlay.nix)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}:
|
||||||
|
|
||||||
|
with pkgs;
|
||||||
|
let wasi-sdk = stdenv.mkDerivation rec {
|
||||||
|
# wasi-sdk is a runtime dependency of asterius
|
||||||
|
|
||||||
|
name = "wasi-sdk${version}";
|
||||||
|
version = "12.1";
|
||||||
|
src = fetchurl {
|
||||||
|
urls = ["https://github.com/tweag/wasi-sdk/releases/download/210113/wasi-sdk-12.1g41fa3294474c-linux.tar.gz"];
|
||||||
|
sha256 = "0ncyv3c6v9klcws87q206mx0s66yph7yjqrzlkayamkdidcxkg80";
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
unzip
|
||||||
|
autoPatchelfHook
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
stdenv.cc.cc.lib
|
||||||
|
];
|
||||||
|
|
||||||
|
unpackPhase = ''
|
||||||
|
tar xf $src
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out && cp -r * $out/
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "wasi-sdk";
|
||||||
|
platforms = platforms.linux;
|
||||||
|
};
|
||||||
|
}; in
|
||||||
|
(pkgs//{wasi-sdk = wasi-sdk;})
|
||||||
|
)
|
18
nix/binaryenOverlay.nix
Normal file
18
nix/binaryenOverlay.nix
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
self: super:
|
||||||
|
{
|
||||||
|
binaryen = super.binaryen.overrideAttrs (_: {
|
||||||
|
version = "99";
|
||||||
|
src = self.fetchFromGitHub {
|
||||||
|
owner = "WebAssembly";
|
||||||
|
repo = "binaryen";
|
||||||
|
rev = "version_99";
|
||||||
|
sha256 = "1a6ixxm1f8mrr9mn6a0pimajdzsdr4w1qhr92skxq67168vvc1ic";
|
||||||
|
};
|
||||||
|
patches = [
|
||||||
|
(self.fetchpatch {
|
||||||
|
url = "https://patch-diff.githubusercontent.com/raw/WebAssembly/binaryen/pull/3482.patch";
|
||||||
|
sha256 = "0s79qw6dm13ralk12wa00cw7az9gd3jvwp904jm1zrdjg6cjp3wa";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
1
nix/default.nix
Symbolic link
1
nix/default.nix
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
bazel_deps.nix
|
26
nix/sources.json
Normal file
26
nix/sources.json
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"niv": {
|
||||||
|
"branch": "master",
|
||||||
|
"description": "Easy dependency management for Nix projects",
|
||||||
|
"homepage": "https://github.com/nmattia/niv",
|
||||||
|
"owner": "nmattia",
|
||||||
|
"repo": "niv",
|
||||||
|
"rev": "af958e8057f345ee1aca714c1247ef3ba1c15f5e",
|
||||||
|
"sha256": "1qjavxabbrsh73yck5dcq8jggvh3r2jkbr6b5nlz5d9yrqm9255n",
|
||||||
|
"type": "tarball",
|
||||||
|
"url": "https://github.com/nmattia/niv/archive/af958e8057f345ee1aca714c1247ef3ba1c15f5e.tar.gz",
|
||||||
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"branch": "nixpkgs-unstable",
|
||||||
|
"description": "Nix Packages collection",
|
||||||
|
"homepage": "",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "5268ee2ebacbc73875be42d71e60c2b5c1b5a1c7",
|
||||||
|
"sha256": "080fvmg0i6z01h6adddfrjp1bbbjhhqk32ks6ch9gv689645ccfq",
|
||||||
|
"type": "tarball",
|
||||||
|
"url": "https://github.com/NixOS/nixpkgs/archive/5268ee2ebacbc73875be42d71e60c2b5c1b5a1c7.tar.gz",
|
||||||
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
|
}
|
||||||
|
}
|
174
nix/sources.nix
Normal file
174
nix/sources.nix
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
# This file has been generated by Niv.
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
#
|
||||||
|
# The fetchers. fetch_<type> fetches specs of type <type>.
|
||||||
|
#
|
||||||
|
|
||||||
|
fetch_file = pkgs: name: spec:
|
||||||
|
let
|
||||||
|
name' = sanitizeName name + "-src";
|
||||||
|
in
|
||||||
|
if spec.builtin or true then
|
||||||
|
builtins_fetchurl { inherit (spec) url sha256; name = name'; }
|
||||||
|
else
|
||||||
|
pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
|
||||||
|
|
||||||
|
fetch_tarball = pkgs: name: spec:
|
||||||
|
let
|
||||||
|
name' = sanitizeName name + "-src";
|
||||||
|
in
|
||||||
|
if spec.builtin or true then
|
||||||
|
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
|
||||||
|
else
|
||||||
|
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
|
||||||
|
|
||||||
|
fetch_git = name: spec:
|
||||||
|
let
|
||||||
|
ref =
|
||||||
|
if spec ? ref then spec.ref else
|
||||||
|
if spec ? branch then "refs/heads/${spec.branch}" else
|
||||||
|
if spec ? tag then "refs/tags/${spec.tag}" else
|
||||||
|
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
|
||||||
|
in
|
||||||
|
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
|
||||||
|
|
||||||
|
fetch_local = spec: spec.path;
|
||||||
|
|
||||||
|
fetch_builtin-tarball = name: throw
|
||||||
|
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
|
||||||
|
$ niv modify ${name} -a type=tarball -a builtin=true'';
|
||||||
|
|
||||||
|
fetch_builtin-url = name: throw
|
||||||
|
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
|
||||||
|
$ niv modify ${name} -a type=file -a builtin=true'';
|
||||||
|
|
||||||
|
#
|
||||||
|
# Various helpers
|
||||||
|
#
|
||||||
|
|
||||||
|
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
|
||||||
|
sanitizeName = name:
|
||||||
|
(
|
||||||
|
concatMapStrings (s: if builtins.isList s then "-" else s)
|
||||||
|
(
|
||||||
|
builtins.split "[^[:alnum:]+._?=-]+"
|
||||||
|
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The set of packages used when specs are fetched using non-builtins.
|
||||||
|
mkPkgs = sources: system:
|
||||||
|
let
|
||||||
|
sourcesNixpkgs =
|
||||||
|
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
|
||||||
|
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
||||||
|
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
|
||||||
|
in
|
||||||
|
if builtins.hasAttr "nixpkgs" sources
|
||||||
|
then sourcesNixpkgs
|
||||||
|
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
||||||
|
import <nixpkgs> {}
|
||||||
|
else
|
||||||
|
abort
|
||||||
|
''
|
||||||
|
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
||||||
|
add a package called "nixpkgs" to your sources.json.
|
||||||
|
'';
|
||||||
|
|
||||||
|
# The actual fetching function.
|
||||||
|
fetch = pkgs: name: spec:
|
||||||
|
|
||||||
|
if ! builtins.hasAttr "type" spec then
|
||||||
|
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
|
||||||
|
else if spec.type == "file" then fetch_file pkgs name spec
|
||||||
|
else if spec.type == "tarball" then fetch_tarball pkgs name spec
|
||||||
|
else if spec.type == "git" then fetch_git name spec
|
||||||
|
else if spec.type == "local" then fetch_local spec
|
||||||
|
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
|
||||||
|
else if spec.type == "builtin-url" then fetch_builtin-url name
|
||||||
|
else
|
||||||
|
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
|
||||||
|
|
||||||
|
# If the environment variable NIV_OVERRIDE_${name} is set, then use
|
||||||
|
# the path directly as opposed to the fetched source.
|
||||||
|
replace = name: drv:
|
||||||
|
let
|
||||||
|
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
|
||||||
|
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
|
||||||
|
in
|
||||||
|
if ersatz == "" then drv else
|
||||||
|
# this turns the string into an actual Nix path (for both absolute and
|
||||||
|
# relative paths)
|
||||||
|
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
|
||||||
|
|
||||||
|
# Ports of functions for older nix versions
|
||||||
|
|
||||||
|
# a Nix version of mapAttrs if the built-in doesn't exist
|
||||||
|
mapAttrs = builtins.mapAttrs or (
|
||||||
|
f: set: with builtins;
|
||||||
|
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
|
||||||
|
);
|
||||||
|
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
|
||||||
|
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
|
||||||
|
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
|
||||||
|
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
|
||||||
|
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
|
||||||
|
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
|
||||||
|
concatMapStrings = f: list: concatStrings (map f list);
|
||||||
|
concatStrings = builtins.concatStringsSep "";
|
||||||
|
|
||||||
|
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
|
||||||
|
optionalAttrs = cond: as: if cond then as else {};
|
||||||
|
|
||||||
|
# fetchTarball version that is compatible between all the versions of Nix
|
||||||
|
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
|
||||||
|
let
|
||||||
|
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||||
|
in
|
||||||
|
if lessThan nixVersion "1.12" then
|
||||||
|
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
|
||||||
|
else
|
||||||
|
fetchTarball attrs;
|
||||||
|
|
||||||
|
# fetchurl version that is compatible between all the versions of Nix
|
||||||
|
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
|
||||||
|
let
|
||||||
|
inherit (builtins) lessThan nixVersion fetchurl;
|
||||||
|
in
|
||||||
|
if lessThan nixVersion "1.12" then
|
||||||
|
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
|
||||||
|
else
|
||||||
|
fetchurl attrs;
|
||||||
|
|
||||||
|
# Create the final "sources" from the config
|
||||||
|
mkSources = config:
|
||||||
|
mapAttrs (
|
||||||
|
name: spec:
|
||||||
|
if builtins.hasAttr "outPath" spec
|
||||||
|
then abort
|
||||||
|
"The values in sources.json should not have an 'outPath' attribute"
|
||||||
|
else
|
||||||
|
spec // { outPath = replace name (fetch config.pkgs name spec); }
|
||||||
|
) config.sources;
|
||||||
|
|
||||||
|
# The "config" used by the fetchers
|
||||||
|
mkConfig =
|
||||||
|
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
|
||||||
|
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
|
||||||
|
, system ? builtins.currentSystem
|
||||||
|
, pkgs ? mkPkgs sources system
|
||||||
|
}: rec {
|
||||||
|
# The sources, i.e. the attribute set of spec name to spec
|
||||||
|
inherit sources;
|
||||||
|
|
||||||
|
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
|
||||||
|
inherit pkgs;
|
||||||
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
|
35
shell.nix
Normal file
35
shell.nix
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{ sources ? import ./nix/sources.nix { }
|
||||||
|
, pkgs ? import sources.nixpkgs {
|
||||||
|
overlays = [
|
||||||
|
(import ./nix/binaryenOverlay.nix)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}:
|
||||||
|
(pkgs.buildFHSUserEnv {
|
||||||
|
name = "hs-fhs";
|
||||||
|
targetPkgs = ps: (with ps; [
|
||||||
|
haskellPackages.alex
|
||||||
|
autoconf
|
||||||
|
automake
|
||||||
|
binaryen
|
||||||
|
binutils
|
||||||
|
gcc
|
||||||
|
haskell.compiler.ghc884
|
||||||
|
git
|
||||||
|
gmp.dev
|
||||||
|
haskellPackages.happy
|
||||||
|
ncurses.dev
|
||||||
|
nodejs-15_x
|
||||||
|
(python39.withPackages (ps: with ps; [
|
||||||
|
recommonmark
|
||||||
|
sphinx
|
||||||
|
]))
|
||||||
|
stack
|
||||||
|
zlib.dev
|
||||||
|
]);
|
||||||
|
profile = ''
|
||||||
|
export LANG=en_US.utf8
|
||||||
|
unset NIX_SSL_CERT_FILE
|
||||||
|
unset SSL_CERT_FILE
|
||||||
|
'';
|
||||||
|
}).env
|
@ -102,6 +102,7 @@ def patch_hadrian():
|
|||||||
with open(os.path.join(ghc_repo_path, "hadrian", "stack.yaml"),
|
with open(os.path.join(ghc_repo_path, "hadrian", "stack.yaml"),
|
||||||
mode="w") as f:
|
mode="w") as f:
|
||||||
f.write("resolver: lts-16.29\n")
|
f.write("resolver: lts-16.29\n")
|
||||||
|
f.write("dump-logs: all\n")
|
||||||
with open(os.path.join(ghc_repo_path, "hadrian", "src", "Oracles",
|
with open(os.path.join(ghc_repo_path, "hadrian", "src", "Oracles",
|
||||||
"Setting.hs"),
|
"Setting.hs"),
|
||||||
mode="r") as h:
|
mode="r") as h:
|
||||||
@ -121,11 +122,11 @@ def patch_hadrian():
|
|||||||
|
|
||||||
def make_hadrian():
|
def make_hadrian():
|
||||||
patch_hadrian()
|
patch_hadrian()
|
||||||
subprocess.run([hadrian_path, "--version"], cwd=ghc_repo_path, check=True)
|
subprocess.run([hadrian_path, "--version", "--verbose"], cwd=ghc_repo_path, check=True)
|
||||||
|
|
||||||
|
|
||||||
def make_autogen():
|
def make_autogen():
|
||||||
subprocess.run([hadrian_path, "-j"] + ghc_autogen_files +
|
subprocess.run([hadrian_path, "--verbose", "-j"] + ghc_autogen_files +
|
||||||
ghc_pkg_autogen_files,
|
ghc_pkg_autogen_files,
|
||||||
cwd=ghc_repo_path,
|
cwd=ghc_repo_path,
|
||||||
check=True)
|
check=True)
|
||||||
|
37
wasm-toolkit/BUILD.bazel
Normal file
37
wasm-toolkit/BUILD.bazel
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:defs.bzl",
|
||||||
|
"haskell_toolchain_library",
|
||||||
|
"haskell_library",
|
||||||
|
"haskell_binary",
|
||||||
|
"haskell_repl",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@rules_haskell//haskell:cabal.bzl",
|
||||||
|
"haskell_cabal_library",
|
||||||
|
)
|
||||||
|
|
||||||
|
haskell_toolchain_library(name = "binary")
|
||||||
|
haskell_toolchain_library(name = "bytestring")
|
||||||
|
haskell_toolchain_library(name = "directory")
|
||||||
|
haskell_toolchain_library(name = "filepath")
|
||||||
|
haskell_toolchain_library(name = "process")
|
||||||
|
haskell_toolchain_library(name = "base")
|
||||||
|
|
||||||
|
haskell_cabal_library(
|
||||||
|
name = "wasm-toolkit",
|
||||||
|
srcs = glob(["wasm-toolkit.cabal", "src/**", "LICENSE"]),
|
||||||
|
version = "0.0.1",
|
||||||
|
cabalopts = ["--ghc-option=-Wall"],
|
||||||
|
haddock = False,
|
||||||
|
verbose = True,
|
||||||
|
deps = [":base", ":binary", ":bytestring", ":directory", ":filepath", ":process"],
|
||||||
|
visibility = ["//asterius:__pkg__"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# haskell_binary(
|
||||||
|
# name = "bin",
|
||||||
|
# deps = [":base", ":lib-0.1.0.0"],
|
||||||
|
# srcs = ["Main.hs"],
|
||||||
|
# )
|
Loading…
Reference in New Issue
Block a user