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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ scripts/sgemm_baseline_*.csv
*.tmp
.env
private/

# Nix
**/.direnv
**/result
101 changes: 101 additions & 0 deletions flake.lock

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

32 changes: 32 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
description = "Rust-native framework for Edge AI CV inference";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/master";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
import-tree = {
url = "github:vic/import-tree";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};

outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
imports = [
(inputs.import-tree [ ./rust.nix ])
];
};
}
105 changes: 105 additions & 0 deletions rust.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{ inputs, ... }: {
perSystem =
{
pkgs,
lib,
self',
system,
...
}:
let
isLinux = pkgs.stdenv.isLinux;
isDarwin = pkgs.stdenv.isDarwin;
isAarch64 = pkgs.stdenv.hostPlatform.isAarch64;
isX86_64 = pkgs.stdenv.hostPlatform.isx86_64;

craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (
p:
p.rust-bin.stable.latest.default.override {
extensions = [
"rust-analyzer"
"rust-src"
"rustfmt"
"clippy"
];
}
);

commonArgs = {
inherit (craneLib.crateNameFromCargoToml { cargoToml = ./Cargo.toml; }) version;

# This should be filtered, but there are a lot of useful extensions for tests
src = ./.;
strictDeps = true;

nativeBuildInputs =
with pkgs;
[
pkg-config
protobuf
rustPlatform.bindgenHook
]
++ lib.optionals isLinux [
linuxHeaders
];

buildInputs = lib.optionals isLinux [
pkgs.openblas
# TODO : mkl, armpl
];

env = {
PROTOC = "${pkgs.protobuf}/bin/protoc";
OPENBLAS_DIR = lib.optionalString isLinux "${pkgs.openblas}";
};
};
in
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;

overlays = [
inputs.rust-overlay.overlays.default
];
};

checks =
let
testFeatures = [
"blas"
"gpu"
"native-camera"
]
++ lib.optionals isDarwin [
"metal-backend"
]
++ lib.optionals (isLinux && isAarch64) [
"rknn"
# "armpl"
]
++ lib.optionals (isLinux && isX86_64) [
# "mkl"
];

mkTest = feature: {
name = "test-${feature}";
value = craneLib.cargoTest (
commonArgs
// {
pname = "yscv-${feature}";
cargoExtraArgs = "--workspace --features ${feature}";

cargoArtifacts = null;
}
);
};
in
builtins.listToAttrs (map mkTest testFeatures);

devShells.default = craneLib.devShell {
inherit (commonArgs) env;

packages = commonArgs.buildInputs ++ commonArgs.nativeBuildInputs;
};
};
}