Compare commits
1 commit
main
...
add-bazel-
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 06cc34dc1c |
3
templates/c++-bazel/.bazelignore
Normal file
3
templates/c++-bazel/.bazelignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
.pre-commit-config.yaml
|
||||
result
|
||||
.direnv
|
6
templates/c++-bazel/.bazelrc
Normal file
6
templates/c++-bazel/.bazelrc
Normal file
|
@ -0,0 +1,6 @@
|
|||
# rule_nixpkgs' specific configuration
|
||||
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
|
||||
build --crosstool_top=@nixpkgs_config_cc//:toolchain
|
||||
|
||||
# Use C++20
|
||||
build:linux --cxxopt=-std=c++20
|
23
templates/c++-bazel/.clang-format
Normal file
23
templates/c++-bazel/.clang-format
Normal file
|
@ -0,0 +1,23 @@
|
|||
# vim: ft=yaml
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
---
|
||||
Language: Cpp
|
||||
# Force pointers to the type for C++.
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
|
||||
# Short functions should not be on a single line, unless empty
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
|
||||
# Make them level
|
||||
AccessModifierOffset: -4
|
||||
|
||||
# It makes more sense this way
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeTernaryOperators: true
|
||||
|
||||
# Aesthetic
|
||||
AlignOperands: AlignAfterOperator
|
||||
---
|
5
templates/c++-bazel/.envrc
Normal file
5
templates/c++-bazel/.envrc
Normal file
|
@ -0,0 +1,5 @@
|
|||
if ! has nix_direnv_version || ! nix_direnv_version 3.0.0; then
|
||||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.0/direnvrc" "sha256-21TMnI2xWX7HkSTjFFri2UaohXVj854mgvWapWrxRXg="
|
||||
fi
|
||||
|
||||
use flake
|
6
templates/c++-bazel/.gitignore
vendored
Normal file
6
templates/c++-bazel/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Bazel build directories
|
||||
/bazel-*/
|
||||
|
||||
# Nix generated files
|
||||
/.pre-commit-config.yaml
|
||||
/result
|
31
templates/c++-bazel/.woodpecker/check.yml
Normal file
31
templates/c++-bazel/.woodpecker/check.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
labels:
|
||||
backend: local
|
||||
|
||||
steps:
|
||||
- name: pre-commit check
|
||||
image: bash
|
||||
commands:
|
||||
- nix develop --command pre-commit run --all
|
||||
|
||||
- name: nix flake check
|
||||
image: bash
|
||||
commands:
|
||||
- nix flake check
|
||||
|
||||
- name: notifiy
|
||||
image: bash
|
||||
environment:
|
||||
ADDRESS:
|
||||
from_secret: matrix_homeserver
|
||||
ROOM:
|
||||
from_secret: matrix_roomid
|
||||
USER:
|
||||
from_secret: matrix_username
|
||||
PASS:
|
||||
from_secret: matrix_password
|
||||
commands:
|
||||
- nix run github:ambroisie/matrix-notifier
|
||||
when:
|
||||
status:
|
||||
- failure
|
||||
- success
|
0
templates/c++-bazel/BUILD
Normal file
0
templates/c++-bazel/BUILD
Normal file
48
templates/c++-bazel/WORKSPACE
Normal file
48
templates/c++-bazel/WORKSPACE
Normal file
|
@ -0,0 +1,48 @@
|
|||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
http_archive(
|
||||
name = "io_tweag_rules_nixpkgs",
|
||||
sha256 = "980edfceef2e59e1122d9be6c52413bc298435f0a3d452532b8a48d7562ffd67",
|
||||
strip_prefix = "rules_nixpkgs-0.10.0",
|
||||
urls = ["https://github.com/tweag/rules_nixpkgs/releases/download/v0.10.0/rules_nixpkgs-0.10.0.tar.gz"],
|
||||
)
|
||||
|
||||
load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")
|
||||
|
||||
# load everything that rules_nixpkgs rules need to work
|
||||
rules_nixpkgs_dependencies()
|
||||
|
||||
load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_cc_configure", "nixpkgs_local_repository")
|
||||
|
||||
# Define nixpkgs version using the flakes lock file.
|
||||
nixpkgs_local_repository(
|
||||
name = "nixpkgs",
|
||||
nix_file_deps = ["//:flake.lock"],
|
||||
nix_flake_lock_file = "//:flake.lock",
|
||||
)
|
||||
|
||||
nixpkgs_cc_configure(
|
||||
name = "nixpkgs_config_cc",
|
||||
repository = "@nixpkgs",
|
||||
)
|
||||
|
||||
# load rules_cc
|
||||
http_archive(
|
||||
name = "rules_cc",
|
||||
sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
|
||||
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz"],
|
||||
)
|
||||
|
||||
load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains")
|
||||
|
||||
rules_cc_dependencies()
|
||||
|
||||
rules_cc_toolchains()
|
||||
|
||||
# Load dependencies
|
||||
http_archive(
|
||||
name = "com_google_googletest",
|
||||
sha256 = "8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7",
|
||||
strip_prefix = "googletest-1.14.0",
|
||||
urls = ["https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz"],
|
||||
)
|
143
templates/c++-bazel/flake.lock
Normal file
143
templates/c++-bazel/flake.lock
Normal file
|
@ -0,0 +1,143 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1673956053,
|
||||
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"futils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"ref": "main",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"pre-commit-hooks",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1660459072,
|
||||
"narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1698134075,
|
||||
"narHash": "sha256-foCD+nuKzfh49bIoiCBur4+Fx1nozo+4C/6k8BYk4sg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "8efd5d1e283604f75a808a20e6cde0ef313d07d4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-stable": {
|
||||
"locked": {
|
||||
"lastModified": 1685801374,
|
||||
"narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-23.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pre-commit-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-utils": [
|
||||
"futils"
|
||||
],
|
||||
"gitignore": "gitignore",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"nixpkgs-stable": "nixpkgs-stable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1698227354,
|
||||
"narHash": "sha256-Fi5H9jbaQLmLw9qBi/mkR33CoFjNbobo5xWdX4tKz1Q=",
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "bd38df3d508dfcdff52cd243d297f218ed2257bf",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"ref": "master",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"futils": "futils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pre-commit-hooks": "pre-commit-hooks"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
126
templates/c++-bazel/flake.nix
Normal file
126
templates/c++-bazel/flake.nix
Normal file
|
@ -0,0 +1,126 @@
|
|||
{
|
||||
description = "A C++ project";
|
||||
|
||||
inputs = {
|
||||
futils = {
|
||||
type = "github";
|
||||
owner = "numtide";
|
||||
repo = "flake-utils";
|
||||
ref = "main";
|
||||
};
|
||||
|
||||
nixpkgs = {
|
||||
type = "github";
|
||||
owner = "NixOS";
|
||||
repo = "nixpkgs";
|
||||
ref = "nixos-unstable";
|
||||
};
|
||||
|
||||
pre-commit-hooks = {
|
||||
type = "github";
|
||||
owner = "cachix";
|
||||
repo = "pre-commit-hooks.nix";
|
||||
ref = "master";
|
||||
inputs = {
|
||||
flake-utils.follows = "futils";
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, futils, nixpkgs, pre-commit-hooks }:
|
||||
{
|
||||
overlays = {
|
||||
default = final: _prev: {
|
||||
project = with final; buildBazelPackage {
|
||||
pname = "project";
|
||||
version = "0.0.0";
|
||||
|
||||
src = self;
|
||||
|
||||
inherit (pkgs) bazel;
|
||||
|
||||
fetchAttrs = {
|
||||
# Fixed output derivation hash after bazel fetch.
|
||||
# This varies per platform, probably from the JDK pulled in being part
|
||||
# of the output derivation ? Is there a more robust way to do this ?
|
||||
# (Hashes extracted from the ofborg build logs)
|
||||
sha256 = let inherit (stdenv.hostPlatform) system; in {
|
||||
x86_64-linux = "${lib.fakeHash}";
|
||||
}.${system} or (throw "No hash for system: ${system}");
|
||||
|
||||
|
||||
# Use WORKSPACE file to fetch `rule_cc`
|
||||
removeRulesCC = false;
|
||||
};
|
||||
|
||||
buildAttrs = {
|
||||
installPhase = ''
|
||||
mkdir -p "$out/bin"
|
||||
|
||||
install bazel-bin/src/project "$out/bin"
|
||||
'';
|
||||
};
|
||||
|
||||
doCheck = true;
|
||||
|
||||
meta = with lib; {
|
||||
description = "A C++ project";
|
||||
homepage = "https://gitea.belanyi.fr/ambroisie/project";
|
||||
license = licenses.mit;
|
||||
maintainers = with maintainers; [ ambroisie ];
|
||||
platforms = platforms.unix;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
} // futils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
self.overlays.default
|
||||
];
|
||||
};
|
||||
|
||||
pre-commit = pre-commit-hooks.lib.${system}.run {
|
||||
src = self;
|
||||
|
||||
hooks = {
|
||||
nixpkgs-fmt = {
|
||||
enable = true;
|
||||
};
|
||||
|
||||
clang-format = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
checks = {
|
||||
inherit (self.packages.${system}) project;
|
||||
|
||||
inherit pre-commit;
|
||||
};
|
||||
|
||||
devShells = {
|
||||
default = pkgs.mkShellNoCC {
|
||||
inputsFrom = with self.packages.${system}; [
|
||||
project
|
||||
];
|
||||
|
||||
packages = with pkgs; [
|
||||
clang-tools
|
||||
];
|
||||
|
||||
inherit (pre-commit) shellHook;
|
||||
};
|
||||
};
|
||||
|
||||
packages = futils.lib.flattenTree {
|
||||
default = pkgs.project;
|
||||
inherit (pkgs) project;
|
||||
};
|
||||
});
|
||||
}
|
6
templates/c++-bazel/src/BUILD
Normal file
6
templates/c++-bazel/src/BUILD
Normal file
|
@ -0,0 +1,6 @@
|
|||
cc_binary(
|
||||
name = "project",
|
||||
srcs = [
|
||||
"main.cc",
|
||||
],
|
||||
)
|
5
templates/c++-bazel/src/main.cc
Normal file
5
templates/c++-bazel/src/main.cc
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World!\n";
|
||||
}
|
10
templates/c++-bazel/tests/unit/BUILD
Normal file
10
templates/c++-bazel/tests/unit/BUILD
Normal file
|
@ -0,0 +1,10 @@
|
|||
cc_test(
|
||||
name = "dummy_test",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"dummy_test.cc",
|
||||
],
|
||||
deps = [
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
5
templates/c++-bazel/tests/unit/dummy_test.cc
Normal file
5
templates/c++-bazel/tests/unit/dummy_test.cc
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(misc, passing) {
|
||||
ASSERT_EQ(1, 1);
|
||||
}
|
Loading…
Reference in a new issue