feat: support build tabby on windows (#948)
* feat: update config to support build on windows * resolve comment * update release.yml * resolve commentr0.7
parent
e9d78233a0
commit
3d3f1761ad
|
|
@ -26,7 +26,7 @@ jobs:
|
||||||
container: ${{ matrix.container }}
|
container: ${{ matrix.container }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
binary: [aarch64-apple-darwin, x86_64-manylinux2014, x86_64-manylinux2014-cuda117]
|
binary: [aarch64-apple-darwin, x86_64-manylinux2014, x86_64-manylinux2014-cuda117, x86_64-pc-windows-msvc]
|
||||||
include:
|
include:
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
target: aarch64-apple-darwin
|
target: aarch64-apple-darwin
|
||||||
|
|
@ -40,6 +40,11 @@ jobs:
|
||||||
binary: x86_64-manylinux2014-cuda117
|
binary: x86_64-manylinux2014-cuda117
|
||||||
container: sameli/manylinux2014_x86_64_cuda_11.7
|
container: sameli/manylinux2014_x86_64_cuda_11.7
|
||||||
build_args: --features cuda
|
build_args: --features cuda
|
||||||
|
- os: windows-latest
|
||||||
|
target: x86_64-pc-windows-msvc
|
||||||
|
binary: x86_64-pc-windows-msvc
|
||||||
|
ext: .exe
|
||||||
|
build_args: --features cuda
|
||||||
|
|
||||||
env:
|
env:
|
||||||
SCCACHE_GHA_ENABLED: true
|
SCCACHE_GHA_ENABLED: true
|
||||||
|
|
@ -77,20 +82,34 @@ jobs:
|
||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
~/.cargo/git
|
~/.cargo/git
|
||||||
|
|
||||||
- run: bash ./ci/prepare_build_environment.sh
|
- name: Prepare build environment for macOS & Linux
|
||||||
|
run: bash ./ci/prepare_build_environment.sh
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
|
||||||
|
- name: Prepare build environment for Windows
|
||||||
|
run: ./ci/prepare_build_environment.ps1
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
|
||||||
|
- name: Install CUDA toolkit for Windows
|
||||||
|
uses: Jimver/cuda-toolkit@v0.2.11
|
||||||
|
with:
|
||||||
|
cuda: '11.7.1'
|
||||||
|
method: 'network'
|
||||||
|
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]'
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
|
||||||
- name: Bulid release binary
|
- name: Bulid release binary
|
||||||
run: cargo build ${{ matrix.build_args }} --release --target ${{ matrix.target }} --package tabby
|
run: cargo build ${{ matrix.build_args }} --release --target ${{ matrix.target }} --package tabby
|
||||||
|
|
||||||
- name: Rename release binary
|
- name: Rename release binary
|
||||||
run: mv target/${{ matrix.target }}/release/tabby tabby_${{ matrix.binary }}
|
run: mv target/${{ matrix.target }}/release/tabby${{ matrix.ext }} tabby_${{ matrix.binary }}${{ matrix.ext }}
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
retention-days: 3
|
retention-days: 3
|
||||||
name: tabby_${{ matrix.binary }}
|
name: tabby_${{ matrix.binary }}${{ matrix.ext }}
|
||||||
path: tabby_${{ matrix.binary }}
|
path: tabby_${{ matrix.binary }}${{ matrix.ext }}
|
||||||
|
|
||||||
pre-release:
|
pre-release:
|
||||||
if: github.event_name == 'push'
|
if: github.event_name == 'push'
|
||||||
|
|
|
||||||
|
|
@ -3641,6 +3641,7 @@ dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"filenamify",
|
"filenamify",
|
||||||
"glob",
|
"glob",
|
||||||
|
"home",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
choco install --yes protoc
|
||||||
|
|
@ -10,11 +10,16 @@ fn main() {
|
||||||
"Please init submodules with `git submodule update --init --recursive` and try again"
|
"Please init submodules with `git submodule update --init --recursive` and try again"
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=cc/*.h");
|
println!("cargo:rerun-if-changed=include/engine.h");
|
||||||
println!("cargo:rerun-if-changed=cc/*.cc");
|
println!("cargo:rerun-if-changed=src/engine.cc");
|
||||||
println!("cargo:rustc-link-lib=llama");
|
println!("cargo:rustc-link-lib=llama");
|
||||||
println!("cargo:rustc-link-lib=ggml_static");
|
println!("cargo:rustc-link-lib=ggml_static");
|
||||||
|
|
||||||
|
build_llama_cpp();
|
||||||
|
build_cxx_binding();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_llama_cpp() {
|
||||||
let mut config = Config::new("llama.cpp");
|
let mut config = Config::new("llama.cpp");
|
||||||
if cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
config.define("LLAMA_METAL", "ON");
|
config.define("LLAMA_METAL", "ON");
|
||||||
|
|
@ -26,9 +31,16 @@ fn main() {
|
||||||
if cfg!(feature = "cuda") {
|
if cfg!(feature = "cuda") {
|
||||||
config.define("LLAMA_CUBLAS", "ON");
|
config.define("LLAMA_CUBLAS", "ON");
|
||||||
config.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON");
|
config.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON");
|
||||||
println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64");
|
if cfg!(target_os = "windows") {
|
||||||
|
let Ok(cuda_path) = env::var("CUDA_PATH") else {
|
||||||
|
panic!("CUDA_PATH is not set");
|
||||||
|
};
|
||||||
|
println!(r"cargo:rustc-link-search=native={}\lib\x64", cuda_path);
|
||||||
|
} else {
|
||||||
|
println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64");
|
||||||
|
println!("cargo:rustc-link-lib=culibos");
|
||||||
|
}
|
||||||
println!("cargo:rustc-link-lib=cudart");
|
println!("cargo:rustc-link-lib=cudart");
|
||||||
println!("cargo:rustc-link-lib=culibos");
|
|
||||||
println!("cargo:rustc-link-lib=cublas");
|
println!("cargo:rustc-link-lib=cublas");
|
||||||
println!("cargo:rustc-link-lib=cublasLt");
|
println!("cargo:rustc-link-lib=cublasLt");
|
||||||
}
|
}
|
||||||
|
|
@ -69,9 +81,26 @@ fn main() {
|
||||||
println!("cargo:rustc-link-lib=hipblas");
|
println!("cargo:rustc-link-lib=hipblas");
|
||||||
}
|
}
|
||||||
|
|
||||||
let dst = config.build();
|
// By default, this value is automatically inferred from Rust’s compilation profile.
|
||||||
println!("cargo:rustc-link-search=native={}/build", dst.display());
|
// For Windows platform, we always build llama.cpp in release mode.
|
||||||
|
// See https://github.com/TabbyML/tabby/pull/948 for more details.
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
config.profile("Release");
|
||||||
|
}
|
||||||
|
|
||||||
|
let dst = config.build();
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
println!(
|
||||||
|
r"cargo:rustc-link-search=native={}\build\{}",
|
||||||
|
dst.display(),
|
||||||
|
config.get_profile()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!("cargo:rustc-link-search=native={}/build", dst.display());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_cxx_binding() {
|
||||||
cxx_build::bridge("src/lib.rs")
|
cxx_build::bridge("src/lib.rs")
|
||||||
.file("src/engine.cc")
|
.file("src/engine.cc")
|
||||||
.flag_if_supported("-Iinclude")
|
.flag_if_supported("-Iinclude")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
#include "engine.h"
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
@ -9,6 +7,7 @@
|
||||||
#include <ggml.h>
|
#include <ggml.h>
|
||||||
#include <llama.h>
|
#include <llama.h>
|
||||||
|
|
||||||
|
#include "llama-cpp-bindings/include/engine.h"
|
||||||
#include "llama-cpp-bindings/src/lib.rs.h"
|
#include "llama-cpp-bindings/src/lib.rs.h"
|
||||||
|
|
||||||
namespace llama {
|
namespace llama {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
filenamify = "0.1.0"
|
filenamify = "0.1.0"
|
||||||
|
home = "0.5.5"
|
||||||
lazy_static = { workspace = true }
|
lazy_static = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serdeconv = { workspace = true }
|
serdeconv = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ lazy_static! {
|
||||||
static ref TABBY_ROOT: Mutex<Cell<PathBuf>> = {
|
static ref TABBY_ROOT: Mutex<Cell<PathBuf>> = {
|
||||||
Mutex::new(Cell::new(match env::var("TABBY_ROOT") {
|
Mutex::new(Cell::new(match env::var("TABBY_ROOT") {
|
||||||
Ok(x) => PathBuf::from(x),
|
Ok(x) => PathBuf::from(x),
|
||||||
Err(_) => PathBuf::from(env::var("HOME").unwrap()).join(".tabby"),
|
Err(_) => home::home_dir().unwrap().join(".tabby"),
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue