Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bazel_dep(name = "rules_nodejs", version = "6.3.5")
bazel_dep(name = "rules_oci", version = "2.0.1")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_python", version = "0.40.0")
bazel_dep(name = "rules_rust", version = "0.63.0")
bazel_dep(name = "rules_mypy", version = "0.29.0")
bazel_dep(name = "rules_python_gazelle_plugin", version = "0.35.0")
bazel_dep(name = "rules_shell", version = "0.4.1")
Expand Down Expand Up @@ -179,7 +180,10 @@ use_repo(
# https://github.com/aspect-build/rules_ts/tree/main/e2e/bzlmod

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
node.toolchain(node_version = "20.18.0")
node.toolchain(
include_headers = True,
node_version = "20.18.0",
)
use_repo(node, "nodejs_toolchains")

pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm")
Expand Down Expand Up @@ -277,3 +281,20 @@ oci.pull(
tag = "latest",
)
use_repo(oci, "distroless_base", "distroless_base_linux_amd64", "distroless_base_linux_arm64", "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")

#########################
# Support for Rust, see https://github.com/bazelbuild/rules_rust
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2024",
versions = ["1.89.0"],
)

crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
crate.from_cargo(
name = "crate_index",
# TODO: we should have a Cargo.toml file in the repository root
cargo_lockfile = "//npm_packages/napi:Cargo.lock",
manifests = ["//npm_packages/napi:Cargo.toml"],
)
use_repo(crate, "crate_index")
1 change: 1 addition & 0 deletions nodejs_apps/typescript/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ts_project(
declaration = True,
tsconfig = {},
deps = [
":node_modules/@bazel-examples/napi",
":node_modules/@bazel-examples/one",
":node_modules/@bazel-examples/shared",
":node_modules/@types/node",
Expand Down
1 change: 1 addition & 0 deletions nodejs_apps/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"inspirational-quotes": "2.0.1",
"@bazel-examples/one": "workspace:*",
"@bazel-examples/shared": "workspace:*",
"@bazel-examples/napi": "workspace:*",
"@types/node": "18.11.9",
"star-wars-quotes": "1.0.2"
}
Expand Down
3 changes: 3 additions & 0 deletions nodejs_apps/typescript/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { platform, arch } from 'node:os';
import { one } from '@bazel-examples/one';
import { shared } from '@bazel-examples/shared';
import { rust, c } from '@bazel-examples/napi';
import { getRandomQuote } from 'inspirational-quotes';
import * as quotes from 'star-wars-quotes';

shared();
one();
console.log(getRandomQuote());
console.log(quotes());
console.log(rust.hello('NodeJS'));
console.log('C code does math: 1 + 2 = ' + c.add(1, 2));
console.log('Platform: ' + platform());
console.log('Architecture: ' + arch());
11 changes: 11 additions & 0 deletions npm_packages/napi/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = ["//npm_packages/napi/src:tsc"],
)
260 changes: 260 additions & 0 deletions npm_packages/napi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions npm_packages/napi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "bazel-examples-napi"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
napi = "3.1.0"
napi-derive = "3.1.0"

[build-dependencies]
napi-build = "2"

[profile.release]
lto = true
strip = "symbols"
Loading