Update package. Pack package as nix package

This commit is contained in:
2026-04-11 13:01:37 +00:00
parent 8d8db0e972
commit ca6342eca6
7 changed files with 286 additions and 0 deletions

125
flake.nix Normal file
View File

@@ -0,0 +1,125 @@
{
description = "Ascend CANN Toolkit Nix package";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
fetchAscendToolkit = pkgs.fetchurl {
url = " https://git.amadey.xyz/api/packages/mozart/generic/ascend-toolkit/8.5.0/ascend-toolkit-8.5.0-310p-full.tar.gz";
sha256 = "sha256-VqC+bG0k4eZDuQkTkPKgCvigUQM8QJU6ByVvj77sk+Q=";
};
ascend-toolkit = pkgs.stdenvNoCC.mkDerivation rec {
pname = "ascend-toolkit";
version = "8.5.0";
src = fetchAscendToolkit;
nativeBuildInputs = [
pkgs.patchelf
pkgs.autoPatchelfHook
pkgs.gcc.cc.lib
pkgs.glibc
pkgs.zlib
pkgs.sqlite
];
phases = [ "unpackPhase" "installPhase" "fixupPhase" ];
unpackPhase = ''
mkdir -p src-copy
tar xzf "$src" -C src-copy
'';
installPhase = ''
mkdir -p $out
cp -r src-copy/* $out/
chmod -R u+w $out/
find $out -type f \( -name "bisheng" -o -name "bisheng-tune" \
-o -name "atc" -o -name "atc.bin" -o -name "akt" \
-o -name "ascendc_pack_kernel" -o -name "asc_dumper" \
-o -name "asc_opc" -o -name "msprof" -o -name "ccec" \
-o -name "cce-ld" -o -name "lld" -o -name "llvm-*" \
-o -name "*.so" -o -name "*.so.*" \) -exec chmod +x {} +
find $out/bin -type f -exec chmod +x {} + 2>/dev/null || true
find $out/tools -type f \( -name "*.py" -o -name "*.sh" \) -exec chmod +x {} + 2>/dev/null || true
'';
postFixup = ''
echo "Adding RPATH for toolkit-internal libraries..."
local rpath="$out/lib64:$out/devlib:$out/tools/aml/lib64"
for dir in bin tools/compiler x86_64-linux/bin x86_64-linux/ccec_compiler/bin \
x86_64-linux/bisheng_compiler/bin; do
[ -d "$out/$dir" ] || continue
find "$out/$dir" -type f -executable 2>/dev/null | while IFS= read -r f; do
patchelf --add-rpath "$rpath" --force-rpath "$f" 2>/dev/null || true
done
done
find $out -type f \( -name "*.so" -o -name "*.so.*" \) 2>/dev/null | while IFS= read -r f; do
patchelf --add-rpath "$rpath" --force-rpath "$f" 2>/dev/null || true
done
local bisheng_config="$out/compiler/tikcpp/ascendc_kernel_cmake/legacy_modules/bisheng_config.cmake"
if [ -f "$bisheng_config" ]; then
cp ${./nix/bisheng_config_patched.cmake} "$bisheng_config"
fi
'';
passthru = {
setupHook = pkgs.makeSetupHook
{ name = "ascend-toolkit-setup-hook.sh"; }
./nix/ascend-toolkit-setup-hook.sh;
};
};
bisheng-wrapper = pkgs.stdenv.mkDerivation {
pname = "bisheng-wrapper";
version = "8.5.0";
dontUnpack = true;
nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase = ''
mkdir -p $out/bin $out/nix-support
substituteAll ${./nix/bisheng-wrapper.sh} $out/bin/bisheng
chmod +x $out/bin/bisheng
substituteAll ${./nix/bisheng-wrapper.sh} $out/bin/bisheng-tune
chmod +x $out/bin/bisheng-tune
cat > $out/nix-support/add-flags.sh << 'EOF'
: "''${NIX_CFLAGS_COMPILE_bisheng:=''${NIX_CFLAGS_COMPILE:-}}"
: "''${NIX_CFLAGS_COMPILE_BEFORE_bisheng:=''${NIX_CFLAGS_COMPILE_BEFORE:-}}"
: "''${NIX_CFLAGS_LINK_bisheng:=''${NIX_CFLAGS_LINK:-}}"
: "''${NIX_LDFLAGS_bisheng:=''${NIX_LDFLAGS:-}}"
export NIX_CC_WRAPPER_FLAGS_SET_bisheng=1
EOF
touch $out/nix-support/add-local-cc-cflags-before.sh
'';
meta = with pkgs.lib; {
description = "Wrapper for Huawei Bisheng compiler that injects Nix compilation flags";
license = licenses.mit;
};
};
in
{
packages = {
inherit ascend-toolkit bisheng-wrapper;
default = ascend-toolkit;
};
}
);
}