Skip to content
Open
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
54 changes: 50 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,57 @@ architecture-specific assumptions.
from analysis).
- `reports/` — research findings and comparative analysis.

## Prerequisites
## Development environment

Install [Bazelisk](https://github.com/bazelbuild/bazelisk). It selects the
Bazel version pinned in `.bazelversion`. Commands are run from the repository
root. Optimized mode is enabled by default in `.bazelrc`.
Nix support is optional. The Bazel project and its configuration do not depend
on Nix, so use whichever setup suits your platform and workflow. Commands are
run from the repository root. Optimized mode is enabled by default in
`.bazelrc`.

### With Nix

Install [Nix](https://nixos.org/download/) with flakes enabled, then enter the
pinned development shell:

```bash
nix develop
bazel build //...
bazel test //...
```

The shell supports `x86_64-linux`, `x86_64-darwin` (Intel macOS), and
`aarch64-darwin` (Apple Silicon). It provides Bazelisk, Clang/LLVM,
`clangd`, `clang-format`, `clang-tidy`, Buildifier, and common build tools.
The `bazel` command in this shell is a wrapper around Bazelisk that passes
`--repo_env=CC=clang --repo_env=CXX=clang++`. This makes Bazel's local C++
toolchain configuration select the Nix-provided Clang; exported `CC` and
`CXX` alone are not sufficient to guarantee that Bazel does so.

To enter the shell automatically when changing into the repository, optionally
use [direnv](https://direnv.net/). After enabling direnv in your shell, create
a local `.envrc` containing `use flake` and run `direnv allow`. `.envrc` is a
local convenience file and should not be committed unless the project chooses
to standardize it.

### Without Nix

Install [Bazelisk](https://github.com/bazelbuild/bazelisk), which selects the
Bazel version pinned in `.bazelversion`. Also install a C++17-capable compiler
(such as Clang or GCC); install Clang/LLVM tools including `clangd`,
`clang-format`, and `clang-tidy` for editor tooling and linting; and install
[Buildifier](https://github.com/bazelbuild/buildtools) when formatting Bazel
files. Then use the same commands:

```bash
bazel build //...
bazel test //...
```

Nix improves the developer experience without replacing this path: pinned tool
versions provide reproducible development environments, easier onboarding, and
controlled toolchain updates. It does not make results identical everywhere:
platform-specific toolchains, CPU architectures, and benchmark measurements
may still differ between machines.

## C++ editor tooling

Expand Down
24 changes: 24 additions & 0 deletions flake.lock

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

65 changes: 65 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
description = "Optional reproducible development environment for memcopy-bench";

inputs.nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst";

outputs = { nixpkgs, ... }:
let
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f:
nixpkgs.lib.genAttrs supportedSystems (system: f (import nixpkgs { inherit system; }));
in
{
devShells = forAllSystems (pkgs:
let
# Bazel's local C++ toolchain is configured by a repository rule. Pass
# the compiler through --repo_env so configuration is tracked and does
# not rely solely on CC/CXX inherited from the development shell.
bazel = pkgs.writeShellApplication {
name = "bazel";
runtimeInputs = [ pkgs.bazelisk ];
text = ''
args=()
compiler_env_added=false

for arg in "$@"; do
args+=("$arg")
if ! "$compiler_env_added"; then
case "$arg" in
aquery|build|coverage|cquery|fetch|query|run|sync|test)
args+=(--repo_env=CC=clang --repo_env=CXX=clang++)
compiler_env_added=true
;;
esac
fi
done

exec bazelisk "''${args[@]}"
'';
};
in
{
default = pkgs.mkShell {
packages = [
bazel
pkgs.buildifier
pkgs.clang-tools
pkgs.llvmPackages.clang
pkgs.git
pkgs.gnumake
];

# These also make editor tools and commands run outside Bazel select
# the pinned Clang. The bazel wrapper above handles Bazel itself.
CC = "clang";
CXX = "clang++";
};
});

formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
};
}