mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
chore: rewrite continuwuity build
This commit is contained in:
@@ -1,59 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
{
|
|
||||||
perSystem =
|
|
||||||
{
|
|
||||||
self',
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
uwulib = inputs.self.uwulib.init pkgs;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
packages =
|
|
||||||
lib.pipe
|
|
||||||
[
|
|
||||||
# this is the default variant
|
|
||||||
{
|
|
||||||
variantName = "default";
|
|
||||||
commonAttrsArgs.profile = "release";
|
|
||||||
rocksdb = self'.packages.rocksdb;
|
|
||||||
features = { };
|
|
||||||
}
|
|
||||||
# this is the variant with all features enabled (liburing + jemalloc)
|
|
||||||
{
|
|
||||||
variantName = "all-features";
|
|
||||||
commonAttrsArgs.profile = "release";
|
|
||||||
rocksdb = self'.packages.rocksdb.override {
|
|
||||||
enableJemalloc = true;
|
|
||||||
};
|
|
||||||
features = {
|
|
||||||
enabledFeatures = "all";
|
|
||||||
disabledFeatures = uwulib.features.defaultDisabledFeatures ++ [ "bindgen-static" ];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
[
|
|
||||||
(builtins.map (cfg: rec {
|
|
||||||
deps = {
|
|
||||||
name = "continuwuity-${cfg.variantName}-deps";
|
|
||||||
value = uwulib.build.buildDeps {
|
|
||||||
features = uwulib.features.calcFeatures cfg.features;
|
|
||||||
inherit (cfg) commonAttrsArgs rocksdb;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
bin = {
|
|
||||||
name = "continuwuity-${cfg.variantName}-bin";
|
|
||||||
value = uwulib.build.buildPackage {
|
|
||||||
deps = self'.packages.${deps.name};
|
|
||||||
features = uwulib.features.calcFeatures cfg.features;
|
|
||||||
inherit (cfg) commonAttrsArgs rocksdb;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}))
|
|
||||||
(builtins.concatMap builtins.attrValues)
|
|
||||||
builtins.listToAttrs
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
+48
-11
@@ -1,16 +1,53 @@
|
|||||||
|
{ inputs, ... }:
|
||||||
{
|
{
|
||||||
imports = [
|
|
||||||
./continuwuity
|
|
||||||
./rust.nix
|
|
||||||
./uwulib
|
|
||||||
];
|
|
||||||
|
|
||||||
perSystem =
|
perSystem =
|
||||||
{ self', pkgs, ... }:
|
|
||||||
{
|
{
|
||||||
packages = {
|
self',
|
||||||
default = self'.packages.continuwuity-default-bin;
|
pkgs,
|
||||||
rocksdb = pkgs.callPackage ./rocksdb.nix { };
|
lib,
|
||||||
};
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
packages =
|
||||||
|
let
|
||||||
|
crane = self'.packages.crane;
|
||||||
|
src =
|
||||||
|
let
|
||||||
|
# see https://crane.dev/API.html#cranelibfiltercargosources
|
||||||
|
# we need to keep the `web` directory which would be filtered out by the regular source filtering function
|
||||||
|
# https://crane.dev/API.html#cranelibcleancargosource
|
||||||
|
isWebTemplate = path: _type: builtins.match ".*(src/(web|service)|docs).*" path != null;
|
||||||
|
isRust = crane.filterCargoSources;
|
||||||
|
isNix = path: _type: builtins.match ".+/nix.*" path != null;
|
||||||
|
webOrRustNotNix = p: t: !(isNix p t) && (isWebTemplate p t || isRust p t);
|
||||||
|
in
|
||||||
|
lib.cleanSourceWith {
|
||||||
|
src = inputs.self;
|
||||||
|
filter = webOrRustNotNix;
|
||||||
|
name = "source";
|
||||||
|
};
|
||||||
|
|
||||||
|
common = {
|
||||||
|
inherit src;
|
||||||
|
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||||
|
buildInputs = [ pkgs.liburing ];
|
||||||
|
env.LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ];
|
||||||
|
};
|
||||||
|
|
||||||
|
cargoArtifacts = crane.buildDepsOnly common;
|
||||||
|
|
||||||
|
continuwuity = crane.buildPackage (
|
||||||
|
common
|
||||||
|
// {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
doCheck = false;
|
||||||
|
env.LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
default = continuwuity;
|
||||||
|
rocksdb = pkgs.callPackage ./rocksdb.nix { };
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
args@{ pkgs, inputs, ... }:
|
|
||||||
let
|
|
||||||
inherit (pkgs) lib;
|
|
||||||
uwuenv = import ./environment.nix args;
|
|
||||||
selfpkgs = inputs.self.packages.${pkgs.stdenv.system};
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
# basic, very minimal instance of the crane library with a minimal rust toolchain
|
|
||||||
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (_: selfpkgs.build-toolchain);
|
|
||||||
# the checks require more rust toolchain components, hence we have this separate instance of the crane library
|
|
||||||
craneLibForChecks = (inputs.crane.mkLib pkgs).overrideToolchain (_: selfpkgs.dev-toolchain);
|
|
||||||
|
|
||||||
# meta information (name, version, etc) of the rust crate based on the Cargo.toml
|
|
||||||
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = "${inputs.self}/Cargo.toml"; };
|
|
||||||
|
|
||||||
src =
|
|
||||||
let
|
|
||||||
# see https://crane.dev/API.html#cranelibfiltercargosources
|
|
||||||
#
|
|
||||||
# we need to keep the `web` directory which would be filtered out by the regular source filtering function
|
|
||||||
#
|
|
||||||
# https://crane.dev/API.html#cranelibcleancargosource
|
|
||||||
isWebTemplate = path: _type: builtins.match ".*(src/(web|service)|docs).*" path != null;
|
|
||||||
isRust = craneLib.filterCargoSources;
|
|
||||||
isNix = path: _type: builtins.match ".+/nix.*" path != null;
|
|
||||||
webOrRustNotNix = p: t: !(isNix p t) && (isWebTemplate p t || isRust p t);
|
|
||||||
in
|
|
||||||
lib.cleanSourceWith {
|
|
||||||
src = inputs.self;
|
|
||||||
filter = webOrRustNotNix;
|
|
||||||
name = "source";
|
|
||||||
};
|
|
||||||
|
|
||||||
# common attrs that are shared between building continuwuity's deps and the package itself
|
|
||||||
commonAttrs =
|
|
||||||
{
|
|
||||||
profile ? "dev",
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
inherit (crateInfo)
|
|
||||||
pname
|
|
||||||
version
|
|
||||||
;
|
|
||||||
inherit src;
|
|
||||||
|
|
||||||
# this prevents unnecessary rebuilds
|
|
||||||
strictDeps = true;
|
|
||||||
|
|
||||||
dontStrip = profile == "dev" || profile == "test";
|
|
||||||
dontPatchELF = profile == "dev" || profile == "test";
|
|
||||||
|
|
||||||
doCheck = true;
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
|
||||||
# bindgen needs the build platform's libclang. Apparently due to "splicing
|
|
||||||
# weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the
|
|
||||||
# right thing here.
|
|
||||||
pkgs.rustPlatform.bindgenHook
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
makeRocksDBEnv =
|
|
||||||
{ rocksdb }:
|
|
||||||
{
|
|
||||||
ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
|
|
||||||
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
|
|
||||||
};
|
|
||||||
|
|
||||||
# function that builds the continuwuity dependencies derivation
|
|
||||||
buildDeps =
|
|
||||||
{
|
|
||||||
rocksdb,
|
|
||||||
features,
|
|
||||||
commonAttrsArgs,
|
|
||||||
}:
|
|
||||||
craneLib.buildDepsOnly (
|
|
||||||
(commonAttrs commonAttrsArgs)
|
|
||||||
// {
|
|
||||||
env = uwuenv.buildDepsOnlyEnv
|
|
||||||
// (makeRocksDBEnv { inherit rocksdb; })
|
|
||||||
// {
|
|
||||||
# required since we started using unstable reqwest apparently ... otherwise the all-features build will fail
|
|
||||||
RUSTFLAGS = "--cfg reqwest_unstable";
|
|
||||||
};
|
|
||||||
inherit (features) cargoExtraArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
# function that builds the continuwuity package
|
|
||||||
buildPackage =
|
|
||||||
{
|
|
||||||
deps,
|
|
||||||
rocksdb,
|
|
||||||
features,
|
|
||||||
commonAttrsArgs,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
rocksdbEnv = makeRocksDBEnv { inherit rocksdb; };
|
|
||||||
in
|
|
||||||
craneLib.buildPackage (
|
|
||||||
(commonAttrs commonAttrsArgs)
|
|
||||||
// {
|
|
||||||
postFixup = ''
|
|
||||||
patchelf --set-rpath "$(${pkgs.patchelf}/bin/patchelf --print-rpath $out/bin/${crateInfo.pname}):${rocksdb}/lib" $out/bin/${crateInfo.pname}
|
|
||||||
'';
|
|
||||||
cargoArtifacts = deps;
|
|
||||||
doCheck = true;
|
|
||||||
env =
|
|
||||||
uwuenv.buildPackageEnv
|
|
||||||
// rocksdbEnv
|
|
||||||
// {
|
|
||||||
# required since we started using unstable reqwest apparently ... otherwise the all-features build will fail
|
|
||||||
RUSTFLAGS = "--cfg reqwest_unstable";
|
|
||||||
};
|
|
||||||
passthru.env = uwuenv.buildPackageEnv // rocksdbEnv;
|
|
||||||
meta.mainProgram = crateInfo.pname;
|
|
||||||
inherit (features) cargoExtraArgs;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
{
|
|
||||||
flake.uwulib = {
|
|
||||||
init = pkgs: {
|
|
||||||
features = import ./features.nix { inherit pkgs inputs; };
|
|
||||||
environment = import ./environment.nix { inherit pkgs inputs; };
|
|
||||||
build = import ./build.nix { inherit pkgs inputs; };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
args@{ pkgs, inputs, ... }:
|
|
||||||
let
|
|
||||||
uwubuild = import ./build.nix args;
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
buildDepsOnlyEnv = {
|
|
||||||
# https://crane.dev/faq/rebuilds-bindgen.html
|
|
||||||
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
|
|
||||||
CARGO_PROFILE = "release";
|
|
||||||
}
|
|
||||||
// uwubuild.craneLib.mkCrossToolchainEnv (p: pkgs.clangStdenv);
|
|
||||||
|
|
||||||
buildPackageEnv = {
|
|
||||||
GIT_COMMIT_HASH = inputs.self.rev or inputs.self.dirtyRev or "";
|
|
||||||
GIT_COMMIT_HASH_SHORT = inputs.self.shortRev or inputs.self.dirtyShortRev or "";
|
|
||||||
}
|
|
||||||
// buildDepsOnlyEnv;
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
{ pkgs, inputs, ... }:
|
|
||||||
let
|
|
||||||
inherit (pkgs) lib;
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
defaultDisabledFeatures = [
|
|
||||||
# dont include experimental features
|
|
||||||
"experimental"
|
|
||||||
# jemalloc profiling/stats features are expensive and shouldn't
|
|
||||||
# be expected on non-debug builds.
|
|
||||||
"jemalloc_prof"
|
|
||||||
"jemalloc_stats"
|
|
||||||
# this is non-functional on nix for some reason
|
|
||||||
"hardened_malloc"
|
|
||||||
# conduwuit_mods is a development-only hot reload feature
|
|
||||||
"conduwuit_mods"
|
|
||||||
# we don't want to enable this feature set by default but be more specific about it
|
|
||||||
"full"
|
|
||||||
];
|
|
||||||
# We perform default-feature unification in nix, because some of the dependencies
|
|
||||||
# on the nix side depend on feature values.
|
|
||||||
calcFeatures =
|
|
||||||
{
|
|
||||||
tomlPath ? "${inputs.self}/src/main",
|
|
||||||
# either a list of feature names or a string "all" which enables all non-default features
|
|
||||||
enabledFeatures ? [ ],
|
|
||||||
disabledFeatures ? defaultDisabledFeatures,
|
|
||||||
default_features ? true,
|
|
||||||
disable_release_max_log_level ? false,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
# simple helper to get the contents of a Cargo.toml file in a nix format
|
|
||||||
getToml = path: lib.importTOML "${path}/Cargo.toml";
|
|
||||||
|
|
||||||
# get all the features except for the default features
|
|
||||||
allFeatures = lib.pipe tomlPath [
|
|
||||||
getToml
|
|
||||||
(manifest: manifest.features)
|
|
||||||
lib.attrNames
|
|
||||||
(lib.remove "default")
|
|
||||||
];
|
|
||||||
|
|
||||||
# get just the default enabled features
|
|
||||||
allDefaultFeatures = lib.pipe tomlPath [
|
|
||||||
getToml
|
|
||||||
(manifest: manifest.features.default)
|
|
||||||
];
|
|
||||||
|
|
||||||
# depending on the value of enabledFeatures choose just a set or all non-default features
|
|
||||||
#
|
|
||||||
# - [ list of features ] -> choose exactly the features listed
|
|
||||||
# - "all" -> choose all non-default features
|
|
||||||
additionalFeatures = if enabledFeatures == "all" then allFeatures else enabledFeatures;
|
|
||||||
|
|
||||||
# unification with default features (if enabled)
|
|
||||||
features = lib.unique (additionalFeatures ++ lib.optionals default_features allDefaultFeatures);
|
|
||||||
|
|
||||||
# prepare the features that are subtracted from the set
|
|
||||||
disabledFeatures' =
|
|
||||||
disabledFeatures ++ lib.optionals disable_release_max_log_level [ "release_max_log_level" ];
|
|
||||||
|
|
||||||
# construct the final feature set
|
|
||||||
finalFeatures = lib.subtractLists disabledFeatures' features;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
# final feature set, useful for querying it
|
|
||||||
features = finalFeatures;
|
|
||||||
|
|
||||||
# crane flag with the relevant features
|
|
||||||
cargoExtraArgs = builtins.concatStringsSep " " [
|
|
||||||
"--no-default-features"
|
|
||||||
"--locked"
|
|
||||||
(lib.optionalString (finalFeatures != [ ]) "--features")
|
|
||||||
(builtins.concatStringsSep "," finalFeatures)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user