build: add Bazel Rust workflow
This commit was merged in pull request #2.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -17,6 +17,9 @@ Thumbs.db
|
|||||||
# logs
|
# logs
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
# Bazel convenience symlinks
|
||||||
|
/bazel-*
|
||||||
|
|
||||||
# language package-manager caches and outputs
|
# language package-manager caches and outputs
|
||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
|
|||||||
@@ -34,3 +34,6 @@
|
|||||||
|
|
||||||
- When materializing an external specification, standard, or project-maintained convention, use the upstream source instead of reconstructing it from memory.
|
- When materializing an external specification, standard, or project-maintained convention, use the upstream source instead of reconstructing it from memory.
|
||||||
Preserve local policy separately from copied upstream text.
|
Preserve local policy separately from copied upstream text.
|
||||||
|
- After an explicit squash or rewrite request on a pull request, subsequent pull-request updates still use follow-up commits unless the user explicitly asks for another rewrite.
|
||||||
|
- Starlark top-level rule and extension declarations cannot reference implementation functions before those functions are assigned.
|
||||||
|
Keep executable public interface declarations after their implementation symbols, or validate before committing a top-down rewrite.
|
||||||
|
|||||||
8
MODULE.bazel
Normal file
8
MODULE.bazel
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module(name = "alexion", version = "0.1.0")
|
||||||
|
|
||||||
|
bazel_dep(name = "rules_rust", version = "0.74.0")
|
||||||
|
|
||||||
|
rust = use_extension("//bazel:rust.bzl", "rust")
|
||||||
|
use_repo(rust, "rust")
|
||||||
|
|
||||||
|
register_toolchains("@rust//:rust")
|
||||||
1777
MODULE.bazel.lock
generated
Normal file
1777
MODULE.bazel.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
5
bazel/BUILD
Normal file
5
bazel/BUILD
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
exports_files([
|
||||||
|
"rust.BUILD.template",
|
||||||
|
"rust.bzl",
|
||||||
|
"utils.bzl",
|
||||||
|
])
|
||||||
117
bazel/rust.BUILD.template
Normal file
117
bazel/rust.BUILD.template
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
filegroup(
|
||||||
|
name = "rustc",
|
||||||
|
srcs = ["toolchain/bin/rustc"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "rustdoc",
|
||||||
|
srcs = ["toolchain/bin/rustdoc"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "cargo",
|
||||||
|
srcs = ["toolchain/bin/cargo"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "cargo_clippy",
|
||||||
|
srcs = ["toolchain/bin/cargo-clippy"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "clippy_driver",
|
||||||
|
srcs = ["toolchain/bin/clippy-driver"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "rustfmt",
|
||||||
|
srcs = ["toolchain/bin/rustfmt"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "cc",
|
||||||
|
srcs = ["toolchain/bin/cc"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "rustc_lib",
|
||||||
|
srcs = glob(
|
||||||
|
[
|
||||||
|
"rust/lib/*.so*",
|
||||||
|
"rust/lib/rustlib/{host_triple}/codegen-backends/*.so",
|
||||||
|
"rust/lib/rustlib/{host_triple}/lib/*.so*",
|
||||||
|
"rust/lib/rustlib/{host_triple}/lib/*.rmeta",
|
||||||
|
],
|
||||||
|
allow_empty = True,
|
||||||
|
),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "rust_objcopy",
|
||||||
|
srcs = glob(
|
||||||
|
["rust/lib/rustlib/{host_triple}/bin/rust-objcopy"],
|
||||||
|
allow_empty = True,
|
||||||
|
),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@rules_rust//rust:toolchain.bzl", "rust_stdlib_filegroup")
|
||||||
|
|
||||||
|
rust_stdlib_filegroup(
|
||||||
|
name = "rust_std",
|
||||||
|
srcs = glob(
|
||||||
|
[
|
||||||
|
"rust/lib/rustlib/{host_triple}/lib/*.rlib",
|
||||||
|
"rust/lib/rustlib/{host_triple}/lib/*.rmeta",
|
||||||
|
"rust/lib/rustlib/{host_triple}/lib/*.so*",
|
||||||
|
"rust/lib/rustlib/{host_triple}/lib/*.a",
|
||||||
|
"rust/lib/rustlib/{host_triple}/lib/self-contained/**",
|
||||||
|
],
|
||||||
|
allow_empty = True,
|
||||||
|
),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
|
||||||
|
|
||||||
|
rust_toolchain(
|
||||||
|
name = "toolchain_impl",
|
||||||
|
rust_doc = ":rustdoc",
|
||||||
|
rust_std = ":rust_std",
|
||||||
|
rustc = ":rustc",
|
||||||
|
linker = ":cc",
|
||||||
|
linker_type = "indirect",
|
||||||
|
rust_objcopy = ":rust_objcopy",
|
||||||
|
rustfmt = ":rustfmt",
|
||||||
|
cargo = ":cargo",
|
||||||
|
clippy_driver = ":clippy_driver",
|
||||||
|
cargo_clippy = ":cargo_clippy",
|
||||||
|
rustc_lib = ":rustc_lib",
|
||||||
|
allocator_library = None,
|
||||||
|
global_allocator_library = None,
|
||||||
|
binary_ext = "",
|
||||||
|
staticlib_ext = ".a",
|
||||||
|
dylib_ext = ".so",
|
||||||
|
stdlib_linkflags = ["-ldl", "-lpthread"],
|
||||||
|
default_edition = "2024",
|
||||||
|
exec_triple = "{host_triple}",
|
||||||
|
target_triple = "{host_triple}",
|
||||||
|
version = "{release}",
|
||||||
|
channel = "stable",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
toolchain(
|
||||||
|
name = "rust",
|
||||||
|
toolchain = ":toolchain_impl",
|
||||||
|
toolchain_type = "@rules_rust//rust:toolchain_type",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
51
bazel/rust.bzl
Normal file
51
bazel/rust.bzl
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
load("//bazel:utils.bzl", "execute", "require_env")
|
||||||
|
|
||||||
|
|
||||||
|
def _rust_repository_impl(repository_ctx):
|
||||||
|
root = repository_ctx.path(require_env(repository_ctx, "RUST_TOOLCHAIN_ROOT"))
|
||||||
|
rustc = root.get_child("bin/rustc")
|
||||||
|
|
||||||
|
sysroot = execute(repository_ctx, [str(rustc), "--print", "sysroot"])
|
||||||
|
verbose_version = execute(repository_ctx, [str(rustc), "-vV"])
|
||||||
|
|
||||||
|
host_triple = None
|
||||||
|
release = None
|
||||||
|
for line in verbose_version.splitlines():
|
||||||
|
if line.startswith("host: "):
|
||||||
|
host_triple = line.removeprefix("host: ")
|
||||||
|
if line.startswith("release: "):
|
||||||
|
release = line.removeprefix("release: ")
|
||||||
|
|
||||||
|
if host_triple == None:
|
||||||
|
fail("rustc -vV did not report a host triple")
|
||||||
|
if release == None:
|
||||||
|
fail("rustc -vV did not report a release")
|
||||||
|
|
||||||
|
repository_ctx.symlink(root, "toolchain")
|
||||||
|
repository_ctx.symlink(sysroot, "rust")
|
||||||
|
|
||||||
|
repository_ctx.file("WORKSPACE.bazel", "")
|
||||||
|
repository_ctx.template(
|
||||||
|
"BUILD.bazel",
|
||||||
|
Label("//bazel:rust.BUILD.template"),
|
||||||
|
{
|
||||||
|
"{host_triple}": host_triple,
|
||||||
|
"{release}": release,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
rust_repository = repository_rule(
|
||||||
|
implementation = _rust_repository_impl,
|
||||||
|
local = True,
|
||||||
|
environ = ["RUST_TOOLCHAIN_ROOT"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _rust_impl(module_ctx):
|
||||||
|
rust_repository(name = "rust")
|
||||||
|
|
||||||
|
|
||||||
|
rust = module_extension(
|
||||||
|
implementation = _rust_impl,
|
||||||
|
)
|
||||||
12
bazel/utils.bzl
Normal file
12
bazel/utils.bzl
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
def require_env(repository_ctx, variable):
|
||||||
|
value = repository_ctx.os.environ.get(variable)
|
||||||
|
if not value:
|
||||||
|
fail("{} must be set.".format(variable))
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def execute(repository_ctx, arguments):
|
||||||
|
result = repository_ctx.execute(arguments)
|
||||||
|
if result.return_code != 0:
|
||||||
|
fail("command failed: {}\n{}".format(" ".join(arguments), result.stderr))
|
||||||
|
return result.stdout.strip()
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
modules.network.ssh.hostKeys.sopsFile = ../../secrets/neogaia.yaml;
|
modules.network.ssh.hostKeys.sopsFile = ../../secrets/neogaia.yaml;
|
||||||
modules.network.ssh.userKey.sopsFile = ../../secrets/neogaia.yaml;
|
modules.network.ssh.userKey.sopsFile = ../../secrets/neogaia.yaml;
|
||||||
|
|
||||||
|
modules.monorepo.enable = true;
|
||||||
modules.shell.herdr.enable = true;
|
modules.shell.herdr.enable = true;
|
||||||
modules.agents.tools.gitea-axi.enable = true;
|
modules.agents.tools.gitea-axi.enable = true;
|
||||||
modules.agents.pi.enable = true;
|
modules.agents.pi.enable = true;
|
||||||
|
|||||||
@@ -120,7 +120,6 @@ in
|
|||||||
modules.shell.tmux.enable = lib.mkDefault true;
|
modules.shell.tmux.enable = lib.mkDefault true;
|
||||||
modules.shell.nvim.enable = lib.mkDefault true;
|
modules.shell.nvim.enable = lib.mkDefault true;
|
||||||
modules.shell.git.enable = lib.mkDefault true;
|
modules.shell.git.enable = lib.mkDefault true;
|
||||||
modules.shell.direnv.enable = lib.mkDefault true;
|
|
||||||
modules.shell.yazi.enable = lib.mkDefault true;
|
modules.shell.yazi.enable = lib.mkDefault true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
17
configs/nixos/modules/monorepo.nix
Normal file
17
configs/nixos/modules/monorepo.nix
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
# Tools for developing this monorepo.
|
||||||
|
let
|
||||||
|
cfg = config.modules.monorepo;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.modules.monorepo.enable = lib.mkEnableOption "tools for developing this monorepo";
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
modules.shell.bazel.enable = true;
|
||||||
|
modules.shell.rust.enable = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
18
configs/nixos/modules/shell/bazel.nix
Normal file
18
configs/nixos/modules/shell/bazel.nix
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
# Bazel for the primary user's shell environment.
|
||||||
|
let
|
||||||
|
cfg = config.modules.shell.bazel;
|
||||||
|
user = config.user.name;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.modules.shell.bazel.enable = lib.mkEnableOption "Bazel for the primary user's shell environment";
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
home-manager.users.${user}.home.packages = [ pkgs.bazel ];
|
||||||
|
};
|
||||||
|
}
|
||||||
35
configs/nixos/modules/shell/rust.nix
Normal file
35
configs/nixos/modules/shell/rust.nix
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
# Rust tools for the primary user's shell environment.
|
||||||
|
let
|
||||||
|
cfg = config.modules.shell.rust;
|
||||||
|
user = config.user.name;
|
||||||
|
toolchain = pkgs.symlinkJoin {
|
||||||
|
name = "rust-toolchain";
|
||||||
|
paths = with pkgs; [
|
||||||
|
cargo
|
||||||
|
clippy
|
||||||
|
gcc
|
||||||
|
rustc
|
||||||
|
rustfmt
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.modules.shell.rust.enable = lib.mkEnableOption "Rust tools for the primary user's shell environment";
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
home-manager.users.${user} = {
|
||||||
|
home.packages = [
|
||||||
|
toolchain
|
||||||
|
pkgs.rust-analyzer
|
||||||
|
];
|
||||||
|
|
||||||
|
home.sessionVariables.RUST_TOOLCHAIN_ROOT = "${toolchain}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -55,12 +55,14 @@
|
|||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# TODO: deprecate / remove
|
||||||
# Agent-ergonomic CLI for Gitea, with a home-manager module for the agent context.
|
# Agent-ergonomic CLI for Gitea, with a home-manager module for the agent context.
|
||||||
gitea-axi = {
|
gitea-axi = {
|
||||||
url = "git+https://git.alexion.dev/alexion/gitea-axi";
|
url = "git+https://git.alexion.dev/alexion/gitea-axi";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# TODO: deprecate / remove
|
||||||
# Personal agent skills, packaged as per-skill derivations with a home-manager module.
|
# Personal agent skills, packaged as per-skill derivations with a home-manager module.
|
||||||
skills = {
|
skills = {
|
||||||
url = "git+https://git.alexion.dev/alexion/skills";
|
url = "git+https://git.alexion.dev/alexion/skills";
|
||||||
|
|||||||
13
src/machoke/BUILD
Normal file
13
src/machoke/BUILD
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
|
||||||
|
|
||||||
|
rust_library(
|
||||||
|
name = "machoke_lib",
|
||||||
|
crate_name = "machoke",
|
||||||
|
srcs = ["lib.rs"],
|
||||||
|
)
|
||||||
|
|
||||||
|
rust_binary(
|
||||||
|
name = "machoke",
|
||||||
|
srcs = ["main.rs"],
|
||||||
|
deps = [":machoke_lib"],
|
||||||
|
)
|
||||||
7
src/machoke/Cargo.lock
generated
Normal file
7
src/machoke/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "machoke"
|
||||||
|
version = "0.1.0"
|
||||||
13
src/machoke/Cargo.toml
Normal file
13
src/machoke/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "machoke"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "lib.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "machoke"
|
||||||
|
path = "main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
3
src/machoke/lib.rs
Normal file
3
src/machoke/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub fn greeting() -> &'static str {
|
||||||
|
"Hello from machoke"
|
||||||
|
}
|
||||||
3
src/machoke/main.rs
Normal file
3
src/machoke/main.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("{}", machoke::greeting());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user