Update package. Pack package as nix package
This commit is contained in:
41
nix/ascend-toolkit-setup-hook.sh
Normal file
41
nix/ascend-toolkit-setup-hook.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
# Setup hook for ascend-toolkit
|
||||
# This is sourced when ascend-toolkit is in buildInputs of another derivation
|
||||
addAscendEnv() {
|
||||
local toolkit="${1:?ascend-toolkit path required}"
|
||||
|
||||
# Core environment variables
|
||||
export ASCEND_TOOLKIT_HOME="${toolkit}"
|
||||
export ASCEND_HOME_PATH="${toolkit}"
|
||||
export ASCEND_OPP_PATH="${toolkit}/opp"
|
||||
export ASCEND_AICPU_PATH="${toolkit}"
|
||||
export TOOLCHAIN_HOME="${toolkit}/toolkit"
|
||||
|
||||
# PATH
|
||||
addToSearchPath PATH "${toolkit}/bin"
|
||||
addToSearchPath PATH "${toolkit}/tools/ccec_compiler/bin"
|
||||
addToSearchPath PATH "${toolkit}/tools/profiler/bin"
|
||||
addToSearchPath PATH "${toolkit}/tools/ascend_system_advisor/asys"
|
||||
addToSearchPath PATH "${toolkit}/tools/show_kernel_debug_data"
|
||||
addToSearchPath PATH "${toolkit}/tools/msobjdump"
|
||||
|
||||
# LD_LIBRARY_PATH
|
||||
addToSearchPath LD_LIBRARY_PATH "${toolkit}/lib64"
|
||||
addToSearchPath LD_LIBRARY_PATH "${toolkit}/lib64/plugin/opskernel"
|
||||
addToSearchPath LD_LIBRARY_PATH "${toolkit}/lib64/plugin/nnengine"
|
||||
addToSearchPath LD_LIBRARY_PATH "${toolkit}/opp/built-in/op_impl/ai_core/tbe/op_tiling/lib/linux/x86_64"
|
||||
addToSearchPath LD_LIBRARY_PATH "${toolkit}/tools/aml/lib64"
|
||||
addToSearchPath LD_LIBRARY_PATH "${toolkit}/tools/aml/lib64/plugin"
|
||||
addToSearchPath LD_LIBRARY_PATH "${toolkit}/devlib"
|
||||
|
||||
# PYTHONPATH
|
||||
addToSearchPath PYTHONPATH "${toolkit}/python/site-packages"
|
||||
addToSearchPath PYTHONPATH "${toolkit}/opp/built-in/op_impl/ai_core/tbe"
|
||||
|
||||
# CMAKE_PREFIX_PATH
|
||||
addToSearchPath CMAKE_PREFIX_PATH "${toolkit}/lib64/cmake"
|
||||
addToSearchPath CMAKE_PREFIX_PATH "${toolkit}/toolkit/tools/tikicpulib/lib/cmake"
|
||||
}
|
||||
|
||||
if [ -n "${ascend-toolkit:-}" ]; then
|
||||
addAscendEnv "${ascend-toolkit}"
|
||||
fi
|
||||
78
nix/bisheng-wrapper.sh
Normal file
78
nix/bisheng-wrapper.sh
Normal file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
set -eu -o pipefail
|
||||
|
||||
# Bisheng compiler wrapper - similar to NixOS cc-wrapper
|
||||
# This script injects NIX_CFLAGS_COMPILE and other Nix-managed flags
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# Source flag accumulation from dependencies
|
||||
if [ -z "${NIX_CC_WRAPPER_FLAGS_SET_bisheng:-}" ]; then
|
||||
if [ -f "@out@/nix-support/add-flags.sh" ]; then
|
||||
source @out@/nix-support/add-flags.sh
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build extra flags
|
||||
extraAfter=()
|
||||
extraBefore=()
|
||||
|
||||
# Add sysroot for C standard library headers (critical for bisheng)
|
||||
ASCEND_TOOLKIT_HOME="${ASCEND_TOOLKIT_HOME:-}"
|
||||
if [ -n "$ASCEND_TOOLKIT_HOME" ] && [ -d "$ASCEND_TOOLKIT_HOME/tools/hcc/sysroot" ]; then
|
||||
extraBefore+=("--sysroot=$ASCEND_TOOLKIT_HOME/tools/hcc/sysroot")
|
||||
fi
|
||||
|
||||
# Add NIX_CFLAGS_COMPILE (the main flag we care about)
|
||||
if [ -n "${NIX_CFLAGS_COMPILE_bisheng:-}" ]; then
|
||||
extraAfter+=($NIX_CFLAGS_COMPILE_bisheng)
|
||||
elif [ -n "${NIX_CFLAGS_COMPILE:-}" ]; then
|
||||
extraAfter+=($NIX_CFLAGS_COMPILE)
|
||||
fi
|
||||
|
||||
# Add NIX_CFLAGS_COMPILE_BEFORE if set
|
||||
if [ -n "${NIX_CFLAGS_COMPILE_BEFORE_bisheng:-}" ]; then
|
||||
extraBefore+=($NIX_CFLAGS_COMPILE_BEFORE_bisheng)
|
||||
fi
|
||||
|
||||
# Add linker flags if we're linking
|
||||
if [ -n "${NIX_CFLAGS_LINK_bisheng:-}" ]; then
|
||||
extraAfter+=($NIX_CFLAGS_LINK_bisheng)
|
||||
fi
|
||||
|
||||
# Convert LDFLAGS to -Wl, format
|
||||
if [ -n "${NIX_LDFLAGS_bisheng:-}" ]; then
|
||||
for flag in $NIX_LDFLAGS_bisheng; do
|
||||
extraBefore+=("-Wl,$flag")
|
||||
done
|
||||
fi
|
||||
|
||||
# Source local cflags hook if it exists
|
||||
if [ -f "@out@/nix-support/add-local-cc-cflags-before.sh" ]; then
|
||||
source @out@/nix-support/add-local-cc-cflags-before.sh
|
||||
fi
|
||||
|
||||
# Debug output
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "bisheng wrapper: extra flags before:" >&2
|
||||
printf " %q\n" "${extraBefore[@]}" >&2
|
||||
echo "bisheng wrapper: original flags:" >&2
|
||||
printf " %q\n" "$@" >&2
|
||||
echo "bisheng wrapper: extra flags after:" >&2
|
||||
printf " %q\n" "${extraAfter[@]}" >&2
|
||||
fi
|
||||
|
||||
# Find the real bisheng binary
|
||||
BISHENG_REAL="${BISHENG_REAL:-bisheng.real}"
|
||||
if ! command -v "$BISHENG_REAL" &>/dev/null; then
|
||||
# Try to find bisheng in PATH (should be the real one from toolkit)
|
||||
BISHENG_REAL="$(which bisheng 2>/dev/null || echo "bisheng")"
|
||||
fi
|
||||
|
||||
# Execute the real bisheng compiler with injected flags
|
||||
exec "$BISHENG_REAL" \
|
||||
"${extraBefore[@]+"${extraBefore[@]}"}" \
|
||||
"$@" \
|
||||
"${extraAfter[@]+"${extraAfter[@]}"}"
|
||||
42
nix/bisheng_config_patched.cmake
Normal file
42
nix/bisheng_config_patched.cmake
Normal file
@@ -0,0 +1,42 @@
|
||||
# ----------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
||||
# CANN Open Software License Agreement Version 2.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# ----------------------------------------------------------------------------------------------------------
|
||||
# Patched version: supports CMAKE_C/CXX_COMPILER override via environment variable
|
||||
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSTEM_LOWER_PROCESSOR)
|
||||
if(EXISTS ${ASCEND_CANN_PACKAGE_PATH}/x86_64-linux/ccec_compiler AND SYSTEM_LOWER_PROCESSOR STREQUAL "x86_64")
|
||||
set(ASCENDC_DEVKIT_PATH ${ASCEND_CANN_PACKAGE_PATH}/x86_64-linux)
|
||||
elseif(EXISTS ${ASCEND_CANN_PACKAGE_PATH}/aarch64-linux/ccec_compiler AND SYSTEM_LOWER_PROCESSOR STREQUAL "aarch64")
|
||||
set(ASCENDC_DEVKIT_PATH ${ASCEND_CANN_PACKAGE_PATH}/aarch64-linux)
|
||||
elseif(EXISTS ${ASCEND_CANN_PACKAGE_PATH}/tools/ccec_compiler)
|
||||
set(ASCENDC_DEVKIT_PATH ${ASCEND_CANN_PACKAGE_PATH}/tools)
|
||||
elseif(EXISTS ${ASCEND_CANN_PACKAGE_PATH}/compiler/ccec_compiler)
|
||||
set(ASCENDC_DEVKIT_PATH ${ASCEND_CANN_PACKAGE_PATH}/compiler)
|
||||
else()
|
||||
set(ASCENDC_DEVKIT_PATH ${ASCEND_CANN_PACKAGE_PATH}/ascendc_devkit)
|
||||
endif()
|
||||
|
||||
|
||||
set(CCEC_PATH ${ASCENDC_DEVKIT_PATH}/ccec_compiler/bin)
|
||||
if(NOT "$ENV{CMAKE_C_COMPILER}" STREQUAL "")
|
||||
set(CMAKE_C_COMPILER "$ENV{CMAKE_C_COMPILER}")
|
||||
else()
|
||||
set(CMAKE_C_COMPILER "${CCEC_PATH}/bisheng")
|
||||
endif()
|
||||
if(NOT "$ENV{CMAKE_CXX_COMPILER}" STREQUAL "")
|
||||
set(CMAKE_CXX_COMPILER "$ENV{CMAKE_CXX_COMPILER}")
|
||||
else()
|
||||
set(CMAKE_CXX_COMPILER "${CCEC_PATH}/bisheng")
|
||||
endif()
|
||||
set(CMAKE_LINKER "${CCEC_PATH}/ld.lld")
|
||||
set(CMAKE_AR "${CCEC_PATH}/llvm-ar")
|
||||
set(CMAKE_STRIP "${CCEC_PATH}/llvm-strip")
|
||||
set(CMAKE_OBJCOPY "${CCEC_PATH}/llvm-objcopy")
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_SKIP_RPATH TRUE)
|
||||
Reference in New Issue
Block a user