From d99b53b80006588ccfb75adcbcf0c303c3b1933f Mon Sep 17 00:00:00 2001 From: pengcheng888 <1033693766@qq.com> Date: Fri, 18 Jul 2025 17:32:14 +0800 Subject: [PATCH] issue/335- add the path of INFINI_ROOT and improve the one-click installation. --- README.md | 15 +++++++++++++-- scripts/install.sh | 8 ++++++++ xmake.lua | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 scripts/install.sh diff --git a/README.md b/README.md index 6783e4123..079123dda 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,23 @@ API 定义以及使用方式详见 [`InfiniCore文档`](https://github.com/Infin ### 一键安装 -在 `script/` 目录中提供了 `install.py` 安装脚本。使用方式如下: +在 `script/` 目录中提供了 `install` 安装脚本。使用方式如下: +linux 系统:在`terminal`中执行 +```shell +cd InfiniCore +source scripts/install.sh [XMAKE_CONFIG_FLAGS] +# 例如 +# source scripts/install.sh 配置 CPU(默认配置) +# source scripts/install.sh --nv-gpu=true --cuda=$CUDA_HOME 配置 英伟达 加速卡 +``` +windows 系统:在`CMD`中执行 ```shell cd InfiniCore - python scripts/install.py [XMAKE_CONFIG_FLAGS] +# 例如 +# python scripts/install.py 配置 CPU(默认配置) +# python scripts/install.py --nv-gpu=true --cuda=\""%CUDA_HOME%"\" 配置 英伟达 加速卡 ``` 参数 `XMAKE_CONFIG_FLAGS` 是 xmake 构建配置,可配置下列可选项: diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 000000000..b18a21884 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +python scripts/install.py ${@:1} + +if [ -z "${INFINI_ROOT}" ]; then + sleep 1 + . ~/.bashrc +fi diff --git a/xmake.lua b/xmake.lua index a4b195532..4e03b7cf0 100644 --- a/xmake.lua +++ b/xmake.lua @@ -18,6 +18,38 @@ if is_plat("windows") then add_cxflags("/utf-8", {force = true}) end +-- 添加INFINI_ROOT环境变量 +on_config(function() + function Check_INFINI_ROOT() + if is_plat("windows") then + return + end + + -- .bashrc文件中是否有INFINI_ROOT + local marker = "# INFINI_ROOT configuration (auto-added by xmake.lua).\n" + local bashrc_path = path.join(os.getenv("HOME"), ".bashrc") + if io.readfile(bashrc_path):find(marker, 1, true) then + return + end + + -- 向.bashrc文件中添加 INFINI_ROOT + local INFINI_ROOT = path.join(os.getenv("HOME"), ".infini") + print(string.format("INFINI_ROOT not set!!! New INFINI_ROOT: %s\n", INFINI_ROOT)) + local file = io.open(bashrc_path, "a") + if file then + file:write("\n") + file:write(marker) + file:write(string.format("export INFINI_ROOT=%s\n",INFINI_ROOT)) + file:write(string.format("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INFINI_ROOT/lib\n")) + file:flush() + file:close() + else + print(string.format("could not open file: %s\n",bashrc_path)) + end + end + Check_INFINI_ROOT() +end) + -- CPU option("cpu") set_default(true)