feat(nix): refactor Flake and Migrate Android Support (#1280)

This commit is contained in:
Mg Pig
2025-08-24 00:53:42 +08:00
committed by GitHub
parent 78004de5e5
commit 9304d3b227
7 changed files with 206 additions and 298 deletions

114
flake.nix
View File

@@ -10,47 +10,101 @@
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
config = {
licenseAccepted = true;
allowUnfree = true;
};
};
rustVersion = "1.89.0";
rust = pkgs.rust-bin.stable.${rustVersion}.default.override{
extensions = [ "rust-src" "rust-analyzer" ];
makeRust =
features:
pkgs.rust-bin.stable.${rustVersion}.default.override {
extensions = [
"rust-src"
"rust-analyzer"
]
++ (if builtins.elem "android" features then android.rust.extensions else [ ]);
targets = if builtins.elem "android" features then android.rust.targets else [ ];
};
android = import ./android.nix {
inherit pkgs system nixpkgs;
};
makeShell =
features:
let
hasFeature = feature: builtins.elem feature features;
withFeature = feature: pkgList: if hasFeature feature then pkgList else [ ];
flattenPaths = xs: builtins.concatLists (map (p: if builtins.isList p then p else [ p ]) xs);
rust = makeRust features;
in
pkgs.mkShell (rec {
nativeBuildInputs =
with pkgs;
(
[
rust
protobuf
clang
pkg-config
bridge-utils # for three node test
]
++ (withFeature "web" [
nodejs_22
pnpm
])
++ (withFeature "android" android.packages)
);
buildInputs = with pkgs; ([
zstd
openssl
libclang
llvmPackages.libclang
libsoup_3
webkitgtk_4_1
]);
RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.clang}/resource-root/include";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (flattenPaths (buildInputs ++ nativeBuildInputs));
ZSTD_SYS_USE_PKG_CONFIG = true;
KCP_SYS_EXTRA_HEADER_PATH = "${pkgs.libclang.lib}/lib/clang/19/include:${pkgs.glibc.dev}/include";
}
// (if hasFeature "android" then android.envVars else { }));
in
{
devShells.default = pkgs.mkShell rec {
nativeBuildInputs = with pkgs; [
rust
protobuf
clang
pkg-config
# web
nodejs_22
pnpm
devShells = {
default = makeShell [ ];
core = makeShell [ ];
web = makeShell [ "web" ];
gui = makeShell [ "gui" ];
android = makeShell [
"android"
"web"
];
buildInputs = with pkgs; [
zstd
openssl
libclang
llvmPackages.libclang
# gui
webkitgtk_4_1
libsoup_3
full = makeShell [
"web"
"gui"
"android"
];
RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.clang}/resource-root/include";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (buildInputs ++ nativeBuildInputs);
ZSTD_SYS_USE_PKG_CONFIG = true;
KCP_SYS_EXTRA_HEADER_PATH = "${pkgs.libclang.lib}/lib/clang/19/include:${pkgs.glibc.dev}/include";
};
}
);