-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../core/.bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["**"]), | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
bzl_library( | ||
name = "nodejs", | ||
srcs = ["//:nodejs.bzl"], | ||
deps = [ | ||
"@rules_nixpkgs_core//:nixpkgs", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module( | ||
name = "rules_nixpkgs_nodejs", | ||
version = "0.8.1", | ||
) | ||
|
||
bazel_dep(name = "rules_nixpkgs_core", version = "0.8.1") | ||
# TODO: the version of `rules_nodejs` on BCR is quite old | ||
# bazel_dep(name = "rules_nodejs", version = "5.4.0") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# NOTE: temporary boilerplate for compatibility with `WORKSPACE` setup! | ||
# TODO: remove when migration to `bzlmod` is complete | ||
|
||
### generic dependencies for rendering documentation | ||
|
||
local_repository( | ||
name = "io_tweag_rules_nixpkgs", | ||
path = "../..", | ||
) | ||
|
||
load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies") | ||
|
||
rules_nixpkgs_dependencies() | ||
|
||
load("@rules_nixpkgs_core//docs:dependencies_1.bzl", "docs_dependencies_1") | ||
|
||
docs_dependencies_1() | ||
|
||
load("@rules_nixpkgs_core//docs:dependencies_2.bzl", "docs_dependencies_2") | ||
|
||
docs_dependencies_2() | ||
|
||
### end generic dependencies for rendering documentation | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "build_bazel_rules_nodejs", | ||
sha256 = "2b2004784358655f334925e7eadc7ba80f701144363df949b3293e1ae7a2fb7b", | ||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.4.0/rules_nodejs-5.4.0.tar.gz"], | ||
) | ||
|
||
load("//:nodejs.bzl", "nixpkgs_nodejs_configure") | ||
|
||
nixpkgs_nodejs_configure(repository = "@nixpkgs") | ||
|
||
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies") | ||
|
||
build_bazel_rules_nodejs_dependencies() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# load("@rules_nixpkgs_core//docs:stardoc.bzl", "generate_documentation") | ||
# | ||
# generate_documentation( | ||
# name = "README.md", | ||
# input = "//:nodejs.bzl", | ||
# symbol_names = ["nixpkgs_nodejs_configure"], | ||
# deps = ["//:nodejs"], | ||
# ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
load("@rules_nixpkgs_core//:nixpkgs.bzl", "nixpkgs_package") | ||
load("@rules_nixpkgs_core//:util.bzl", "ensure_constraints") | ||
|
||
_nodejs_nix_content = """\ | ||
let | ||
pkgs = import <nixpkgs> {{ config = {{}}; overlays = []; }}; | ||
nodejs = pkgs.{attribute_path}; | ||
in | ||
pkgs.buildEnv {{ | ||
extraOutputsToInstall = ["out" "bin" "lib"]; | ||
name = "bazel-nodejs-toolchain"; | ||
paths = [ nodejs ]; | ||
postBuild = '' | ||
touch $out/ROOT | ||
cat <<EOF > $out/BUILD | ||
filegroup( | ||
name = "nodejs", | ||
srcs = ["bin/node"], | ||
visibility = ["//visibility:public"], | ||
) | ||
load("@rules_nodejs//nodejs:toolchain.bzl", "node_toolchain") | ||
node_toolchain( | ||
name = "nodejs_nix_impl", | ||
target_tool = ":nodejs", | ||
visibility = ["//visibility:public"], | ||
) | ||
EOF | ||
''; | ||
}} | ||
""" | ||
|
||
_nodejs_nix_toolchain = """ | ||
toolchain( | ||
name = "nodejs_nix", | ||
toolchain = "@{toolchain_repo}//:nodejs_nix_impl", | ||
toolchain_type = "@rules_nodejs//nodejs:toolchain_type", | ||
exec_compatible_with = {exec_constraints}, | ||
target_compatible_with = {target_constraints}, | ||
) | ||
""" | ||
|
||
def _nixpkgs_nodejs_toolchain_impl(repository_ctx): | ||
exec_constraints, target_constraints = ensure_constraints(repository_ctx) | ||
repository_ctx.file( | ||
"BUILD.bazel", | ||
executable = False, | ||
content = _nodejs_nix_toolchain.format( | ||
toolchain_repo = repository_ctx.attr.toolchain_repo, | ||
exec_constraints = exec_constraints, | ||
target_constraints = target_constraints, | ||
), | ||
) | ||
|
||
_nixpkgs_nodejs_toolchain = repository_rule( | ||
_nixpkgs_nodejs_toolchain_impl, | ||
attrs = { | ||
"toolchain_repo": attr.string(), | ||
"exec_constraints": attr.string_list(), | ||
"target_constraints": attr.string_list(), | ||
}, | ||
) | ||
|
||
def nixpkgs_nodejs_configure( | ||
name = "nixpkgs_nodejs", | ||
attribute_path = "nodejs", | ||
repository = None, | ||
repositories = {}, | ||
nix_file = None, | ||
nix_file_content = None, | ||
nix_file_deps = None, | ||
nixopts = [], | ||
fail_not_supported = True, | ||
quiet = False, | ||
exec_constraints = None, | ||
target_constraints = None, | ||
): | ||
if attribute_path == None: | ||
fail("'attribute_path' is required.", "attribute_path") | ||
|
||
if not nix_file and not nix_file_content: | ||
nix_file_content = _nodejs_nix_content.format( | ||
attribute_path = attribute_path, | ||
) | ||
|
||
nixpkgs_package( | ||
name = name, | ||
repository = repository, | ||
repositories = repositories, | ||
nix_file = nix_file, | ||
nix_file_deps = nix_file_deps, | ||
nix_file_content = nix_file_content, | ||
nixopts = nixopts, | ||
fail_not_supported = fail_not_supported, | ||
quiet = quiet, | ||
) | ||
|
||
_nixpkgs_nodejs_toolchain( | ||
name = "{}_toolchain".format(name), | ||
toolchain_repo = name, | ||
exec_constraints = exec_constraints, | ||
target_constraints = target_constraints, | ||
) | ||
|
||
native.register_toolchains("@{}_toolchain//:nodejs_nix".format(name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") | ||
|
||
package(default_testonly = 1) | ||
|
||
nodejs_binary( | ||
name = "nodejs-test", | ||
entry_point = ":nodejs-test.js", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function main() { | ||
console.log("Hello world"); | ||
} | ||
|
||
main() |