Switch to sccache (#154)
* fix fmt * fix * fix test * fix clippy * switch to sc cache * fix * update * update * update * fix * add test * remove clippy * update * disable incremental * update * simplyadd-tracing
parent
0000312460
commit
b8309d98cc
|
|
@ -8,15 +8,27 @@ on:
|
||||||
branches: ["main" ]
|
branches: ["main" ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-commit:
|
tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v3
|
with:
|
||||||
- uses: pre-commit/action@v3.0.0
|
submodules: recursive
|
||||||
|
- uses: actions/setup-python@v3
|
||||||
|
- uses: pre-commit/action@v3.0.0
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
target: ${{ matrix.target }}
|
||||||
|
components: rustfmt, clippy
|
||||||
|
|
||||||
|
- name: Cargo fmt
|
||||||
|
run: cargo fmt --check
|
||||||
|
|
||||||
release-docker:
|
release-docker:
|
||||||
needs: pre-commit
|
needs: tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
@ -76,7 +88,7 @@ jobs:
|
||||||
cache-to: ${{ steps.cache.outputs.cache-to }}
|
cache-to: ${{ steps.cache.outputs.cache-to }}
|
||||||
|
|
||||||
release-binary:
|
release-binary:
|
||||||
needs: pre-commit
|
needs: tests
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|
@ -84,21 +96,45 @@ jobs:
|
||||||
include:
|
include:
|
||||||
- os: macos-11
|
- os: macos-11
|
||||||
target: aarch64-apple-darwin
|
target: aarch64-apple-darwin
|
||||||
|
|
||||||
|
env:
|
||||||
|
SCCACHE_GHA_ENABLED: true
|
||||||
|
RUSTC_WRAPPER: sccache
|
||||||
|
CARGO_INCREMENTAL: 0
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- run: |
|
- name: Install Rust
|
||||||
rustup set auto-self-update disable
|
uses: actions-rs/toolchain@v1
|
||||||
rustup toolchain install stable --profile minimal --target ${{ matrix.target }}
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
target: ${{ matrix.target }}
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
- name: Sccache cache
|
||||||
|
uses: mozilla-actions/sccache-action@v0.0.3
|
||||||
|
with:
|
||||||
|
version: "v0.4.0"
|
||||||
|
|
||||||
- run: |
|
- name: Cargo registry cache
|
||||||
cargo build --release --target ${{ matrix.target }}
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml') }}-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml') }}-
|
||||||
|
cargo-${{ runner.os }}-
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- name: Bulid release binary
|
||||||
|
run: cargo build --release --target ${{ matrix.target }}
|
||||||
|
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
retention-days: 3
|
retention-days: 3
|
||||||
name: tabby_${{ matrix.target }}
|
name: tabby_${{ matrix.target }}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use cmake::Config;
|
use cmake::Config;
|
||||||
use rust_cxx_cmake_bridge::read_cmake_generated;
|
use rust_cxx_cmake_bridge::read_cmake_generated;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Tell cargo to invalidate the built crate whenever the wrapper changes
|
// Tell cargo to invalidate the built crate whenever the wrapper changes
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use tokenizers::tokenizer::{Tokenizer};
|
use tokenizers::tokenizer::Tokenizer;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate derive_builder;
|
extern crate derive_builder;
|
||||||
|
|
@ -73,7 +73,7 @@ impl TextInferenceEngine {
|
||||||
options.num_replicas_per_device,
|
options.num_replicas_per_device,
|
||||||
);
|
);
|
||||||
return TextInferenceEngine {
|
return TextInferenceEngine {
|
||||||
engine: engine,
|
engine,
|
||||||
tokenizer: Tokenizer::from_file(&options.tokenizer_path).unwrap(),
|
tokenizer: Tokenizer::from_file(&options.tokenizer_path).unwrap(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -88,10 +88,11 @@ impl TextInferenceEngine {
|
||||||
);
|
);
|
||||||
let output_ids: Vec<u32> = output_tokens
|
let output_ids: Vec<u32> = output_tokens
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|x| {
|
.filter_map(|x| match self.tokenizer.token_to_id(x) {
|
||||||
match self.tokenizer.token_to_id(x) {
|
Some(y) => Some(y),
|
||||||
Some(y) => Some(y),
|
None => {
|
||||||
None => { println!("Warning: token ({}) missed in vocab", x); None }
|
println!("Warning: token ({}) missed in vocab", x);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ fn parse_lib_path_dir_and_name(static_lib_str: &str) -> (PathBuf, String, bool,
|
||||||
// TODO use "file_prefix" https://github.com/rust-lang/rust/issues/86319
|
// TODO use "file_prefix" https://github.com/rust-lang/rust/issues/86319
|
||||||
let liblib_name = static_lib_path.my_file_prefix().unwrap();
|
let liblib_name = static_lib_path.my_file_prefix().unwrap();
|
||||||
let liblib_name_str: String = liblib_name.to_str().unwrap().into();
|
let liblib_name_str: String = liblib_name.to_str().unwrap().into();
|
||||||
let lib_name_str = liblib_name_str.trim_start_matches("lib");
|
let lib_name_str = liblib_name_str
|
||||||
|
.strip_prefix("lib")
|
||||||
|
.unwrap_or(&liblib_name_str);
|
||||||
|
|
||||||
// basically:
|
// basically:
|
||||||
// - input = /.../target/debug/build/lib-circuits-wrapper-49025516ce40925e/out/build/_deps/glog-build/libglogd.so.0.6.0
|
// - input = /.../target/debug/build/lib-circuits-wrapper-49025516ce40925e/out/build/_deps/glog-build/libglogd.so.0.6.0
|
||||||
|
|
@ -45,13 +47,13 @@ fn parse_lib_path_dir_and_name(static_lib_str: &str) -> (PathBuf, String, bool,
|
||||||
|
|
||||||
let is_framework = static_lib_str.ends_with(".framework");
|
let is_framework = static_lib_str.ends_with(".framework");
|
||||||
|
|
||||||
return (
|
(
|
||||||
dir.to_path_buf(),
|
dir.to_path_buf(),
|
||||||
lib_name_str.to_string(),
|
lib_name_str.to_string(),
|
||||||
is_static,
|
is_static,
|
||||||
is_system,
|
is_system,
|
||||||
is_framework,
|
is_framework,
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the content of "cmake_generated_rust_wrapper_libs" which SHOULD have
|
// Parse the content of "cmake_generated_rust_wrapper_libs" which SHOULD have
|
||||||
|
|
@ -75,7 +77,7 @@ fn read_cmake_generated_to_output(
|
||||||
// - NON system libs (obviously) wether SHARED or STATIC
|
// - NON system libs (obviously) wether SHARED or STATIC
|
||||||
// - system STATIC libs eg /usr/lib/x86_64-linux-gnu/libboost_filesystem.a else
|
// - system STATIC libs eg /usr/lib/x86_64-linux-gnu/libboost_filesystem.a else
|
||||||
// "error: could not find native static library `boost_filesystem`, perhaps an -L flag is missing?"
|
// "error: could not find native static library `boost_filesystem`, perhaps an -L flag is missing?"
|
||||||
if !is_system || is_static || !is_framework {
|
if (!is_system && !is_framework) || is_static {
|
||||||
writeln!(output, "cargo:rustc-link-search=native={}", dir.display()).unwrap();
|
writeln!(output, "cargo:rustc-link-search=native={}", dir.display()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +99,7 @@ fn read_cmake_generated_to_output(
|
||||||
|
|
||||||
pub fn read_cmake_generated(cmake_generated_rust_wrapper_libs_str: &str) {
|
pub fn read_cmake_generated(cmake_generated_rust_wrapper_libs_str: &str) {
|
||||||
read_cmake_generated_to_output(
|
read_cmake_generated_to_output(
|
||||||
&cmake_generated_rust_wrapper_libs_str,
|
cmake_generated_rust_wrapper_libs_str,
|
||||||
&mut std::io::stdout(),
|
&mut std::io::stdout(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +118,7 @@ impl HasMyFilePrefix for std::path::Path {
|
||||||
fn my_file_prefix(&self) -> Option<&OsStr> {
|
fn my_file_prefix(&self) -> Option<&OsStr> {
|
||||||
self.file_name()
|
self.file_name()
|
||||||
.map(split_file_at_dot)
|
.map(split_file_at_dot)
|
||||||
.and_then(|(before, _after)| Some(before))
|
.map(|(before, _after)| before)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,52 +159,68 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_local_lib_static_ok() {
|
fn parse_local_lib_static_ok() {
|
||||||
let (dir, lib_name_str, is_static, is_system) =
|
let (dir, lib_name_str, is_static, is_system, is_framework) =
|
||||||
parse_lib_path_dir_and_name("/some/path/liblibstatic.a");
|
parse_lib_path_dir_and_name("/some/path/liblibstatic.a");
|
||||||
assert_eq!(dir.as_os_str(), "/some/path");
|
assert_eq!(dir.as_os_str(), "/some/path");
|
||||||
assert_eq!(lib_name_str, "libstatic");
|
assert_eq!(lib_name_str, "libstatic");
|
||||||
assert_eq!(is_static, true);
|
assert!(is_static);
|
||||||
assert_eq!(is_system, false);
|
assert!(!is_system);
|
||||||
|
assert!(!is_framework);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_local_lib_shared_ok() {
|
fn parse_local_lib_shared_ok() {
|
||||||
let (dir, lib_name_str, is_static, is_system) =
|
let (dir, lib_name_str, is_static, is_system, is_framework) =
|
||||||
parse_lib_path_dir_and_name("/some/path/liblibshared.so");
|
parse_lib_path_dir_and_name("/some/path/liblibshared.so");
|
||||||
assert_eq!(dir.as_os_str(), "/some/path");
|
assert_eq!(dir.as_os_str(), "/some/path");
|
||||||
assert_eq!(lib_name_str, "libshared");
|
assert_eq!(lib_name_str, "libshared");
|
||||||
assert_eq!(is_static, false);
|
assert!(!is_static);
|
||||||
assert_eq!(is_system, false);
|
assert!(!is_system);
|
||||||
|
assert!(!is_framework);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_local_lib_shared_with_soversion_ok() {
|
fn parse_local_lib_shared_with_soversion_ok() {
|
||||||
let (dir, lib_name_str, is_static, is_system) =
|
let (dir, lib_name_str, is_static, is_system, is_framework) =
|
||||||
parse_lib_path_dir_and_name("/some/path/liblibshared.so.1.2.3");
|
parse_lib_path_dir_and_name("/some/path/liblibshared.so.1.2.3");
|
||||||
assert_eq!(dir.as_os_str(), "/some/path");
|
assert_eq!(dir.as_os_str(), "/some/path");
|
||||||
assert_eq!(lib_name_str, "libshared");
|
assert_eq!(lib_name_str, "libshared");
|
||||||
assert_eq!(is_static, false);
|
assert!(!is_static);
|
||||||
assert_eq!(is_system, false);
|
assert!(!is_system);
|
||||||
|
assert!(!is_framework);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_system_lib_static_ok() {
|
fn parse_system_lib_static_ok() {
|
||||||
let (dir, lib_name_str, is_static, is_system) =
|
let (dir, lib_name_str, is_static, is_system, is_framework) =
|
||||||
parse_lib_path_dir_and_name("/usr/lib/libsystem1.a");
|
parse_lib_path_dir_and_name("/usr/lib/libsystem1.a");
|
||||||
assert_eq!(dir.as_os_str(), "/usr/lib");
|
assert_eq!(dir.as_os_str(), "/usr/lib");
|
||||||
assert_eq!(lib_name_str, "system1");
|
assert_eq!(lib_name_str, "system1");
|
||||||
assert_eq!(is_static, true);
|
assert!(is_static);
|
||||||
assert_eq!(is_system, true);
|
assert!(is_system);
|
||||||
|
assert!(!is_framework);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_system_lib_shared_ok() {
|
fn parse_system_lib_shared_ok() {
|
||||||
let (dir, lib_name_str, is_static, is_system) =
|
let (dir, lib_name_str, is_static, is_system, is_framework) =
|
||||||
parse_lib_path_dir_and_name("/usr/lib/libsystem2.so");
|
parse_lib_path_dir_and_name("/usr/lib/libsystem2.so");
|
||||||
assert_eq!(dir.as_os_str(), "/usr/lib");
|
assert_eq!(dir.as_os_str(), "/usr/lib");
|
||||||
assert_eq!(lib_name_str, "system2");
|
assert_eq!(lib_name_str, "system2");
|
||||||
assert_eq!(is_static, false);
|
assert!(!is_static);
|
||||||
assert_eq!(is_system, true);
|
assert!(is_system);
|
||||||
|
assert!(!is_framework);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_framework_ok() {
|
||||||
|
let (dir, lib_name_str, is_static, is_system, is_framework) =
|
||||||
|
parse_lib_path_dir_and_name("/AAA/BBB.framework");
|
||||||
|
assert_eq!(dir.as_os_str(), "/AAA");
|
||||||
|
assert_eq!(lib_name_str, "BBB");
|
||||||
|
assert!(!is_static);
|
||||||
|
assert!(!is_system);
|
||||||
|
assert!(is_framework);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ pub struct CompletionState {
|
||||||
impl CompletionState {
|
impl CompletionState {
|
||||||
pub fn new(options: TextInferenceEngineCreateOptions) -> Self {
|
pub fn new(options: TextInferenceEngineCreateOptions) -> Self {
|
||||||
let engine = TextInferenceEngine::create(options);
|
let engine = TextInferenceEngine::create(options);
|
||||||
return Self { engine: engine };
|
Self { engine }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,10 @@ lazy_static! {
|
||||||
|
|
||||||
pub fn remove_stop_words<'a>(language: &'a str, text: &'a str) -> &'a str {
|
pub fn remove_stop_words<'a>(language: &'a str, text: &'a str) -> &'a str {
|
||||||
let re = LANGUAGES.get(language).unwrap_or(&DEFAULT);
|
let re = LANGUAGES.get(language).unwrap_or(&DEFAULT);
|
||||||
let position = re.find_iter(&text).next();
|
let position = re.find_iter(text).next();
|
||||||
if let Some(m) = position {
|
if let Some(m) = position {
|
||||||
&text[..m.start()]
|
&text[..m.start()]
|
||||||
} else {
|
} else {
|
||||||
&text
|
text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue