Files
oysteikt 2cf5124f1d
Build and test / check (push) Successful in 43s
Build and test / test (push) Successful in 55s
Build and test / build-static-library (push) Successful in 56s
Build and test / build-dynamic-library (push) Successful in 1m22s
flake.nix: add android cross compiled shared library package
2026-05-11 09:18:55 +09:00

195 lines
4.9 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
};
outputs = { self, nixpkgs, rust-overlay, crane }:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f: lib.genAttrs systems (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
];
};
rust-bin = rust-overlay.lib.mkRustBin { } pkgs.buildPackages;
toolchain = rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" "rust-std" ];
};
in f system pkgs toolchain);
in {
devShells = forAllSystems (system: pkgs: toolchain: {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
toolchain
cargo-edit
pkg-config
sqlite-interactive
];
buildInputs = with pkgs; [
sqlite
];
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
};
});
packages = let
src = builtins.filterSource (path: type: let
baseName = baseNameOf (toString path);
in !(lib.any (b: b) [
(!(lib.cleanSourceFilter path type))
(baseName == ".gitea" && type == "directory")
(baseName == ".envrc" && type == "regular")
(baseName == "flake.lock" && type == "regular")
(baseName == "flake.nix" && type == "regular")
])) ./.;
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in forAllSystems (system: pkgs: _: let
craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.stable.latest.default);
androidPkgs = import nixpkgs {
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"aarch64-unknown-linux-android-ndk-toolchain"
"aarch64-unknown-linux-android-ndk-toolchain-wrapper"
"android-sdk-ndk"
"android-sdk-platform-tools"
"ndk"
"platform-tools"
];
localSystem = system;
crossSystem = lib.systems.examples.aarch64-android-prebuilt;
overlays = [
(import rust-overlay)
];
};
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"sqlite3_ext-0.2.0" = "sha256-DdLEHzheF/OPp4/qMuRSvtw+K6SeFU2+AHdQRu6z1lY=";
};
};
in {
default = self.packages.${system}.tamerye-shared-lib-crane;
tamerye-shared-lib = pkgs.rustPlatform.buildRustPackage {
pname = "tamerye-shared-lib";
version = cargoToml.package.version;
inherit src;
inherit cargoLock;
strictDeps = true;
doCheck = false;
nativeBuildInputs = with pkgs; [
rustfmt
];
};
tamerye-shared-lib-android = androidPkgs.rustPlatform.buildRustPackage {
pname = "tamerye-shared-lib-android";
version = cargoToml.package.version;
inherit src;
inherit cargoLock;
strictDeps = true;
doCheck = false;
nativeBuildInputs = with androidPkgs; [
rustfmt
];
};
tamerye-shared-lib-crane = craneLib.buildPackage {
pname = "tamerye-shared-lib";
version = cargoToml.package.version;
inherit src;
strictDeps = true;
doCheck = false;
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
strictDeps = true;
};
};
tamerye-static-lib-crane = craneLib.buildPackage {
pname = "tamerye-static-lib";
version = cargoToml.package.version;
inherit src;
strictDeps = true;
doCheck = false;
postPatch = ''
'${lib.getExe pkgs.yq-go}' '.lib.crate-type = [ "staticlib" ]' --inplace Cargo.toml
'';
buildInputs = with pkgs; [
sqlite
];
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
strictDeps = true;
buildInputs = with pkgs; [
sqlite
];
};
cargoExtraArgs = lib.escapeShellArgs [ "--features" "static" ];
};
tamerye-tests-crane = craneLib.cargoNextest {
pname = "tamerye-tests";
version = cargoToml.package.version;
inherit src;
strictDeps = true;
buildInputs = with pkgs; [
sqlite
];
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
strictDeps = true;
buildInputs = with pkgs; [
sqlite
];
};
cargoExtraArgs = lib.escapeShellArgs [ "--features" "static" ];
partitions = 1;
partitionType = "count";
cargoNextestPartitionsExtraArgs = "--no-tests=pass";
};
});
};
}