diff --git a/.github/workflows/docker.rust.yml b/.github/workflows/docker.rust.yml index 8556058..0984700 100644 --- a/.github/workflows/docker.rust.yml +++ b/.github/workflows/docker.rust.yml @@ -8,15 +8,27 @@ on: branches: ["main" ] jobs: - pre-commit: + tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - - uses: pre-commit/action@v3.0.0 + - uses: actions/checkout@v3 + with: + 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: - needs: pre-commit + needs: tests runs-on: ubuntu-latest permissions: contents: read @@ -76,7 +88,7 @@ jobs: cache-to: ${{ steps.cache.outputs.cache-to }} release-binary: - needs: pre-commit + needs: tests runs-on: ${{ matrix.os }} strategy: matrix: @@ -84,21 +96,45 @@ jobs: include: - os: macos-11 target: aarch64-apple-darwin + + env: + SCCACHE_GHA_ENABLED: true + RUSTC_WRAPPER: sccache + CARGO_INCREMENTAL: 0 + steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 with: submodules: recursive - - run: | - rustup set auto-self-update disable - rustup toolchain install stable --profile minimal --target ${{ matrix.target }} + - name: Install Rust + uses: actions-rs/toolchain@v1 + 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: | - cargo build --release --target ${{ matrix.target }} + - name: Cargo registry cache + 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: retention-days: 3 name: tabby_${{ matrix.target }} diff --git a/crates/ctranslate2-bindings/build.rs b/crates/ctranslate2-bindings/build.rs index 407a410..6ac5585 100644 --- a/crates/ctranslate2-bindings/build.rs +++ b/crates/ctranslate2-bindings/build.rs @@ -1,7 +1,7 @@ use cmake::Config; use rust_cxx_cmake_bridge::read_cmake_generated; -use std::path::PathBuf; use std::env; +use std::path::PathBuf; fn main() { // Tell cargo to invalidate the built crate whenever the wrapper changes diff --git a/crates/ctranslate2-bindings/src/lib.rs b/crates/ctranslate2-bindings/src/lib.rs index 5701c6c..14649d1 100644 --- a/crates/ctranslate2-bindings/src/lib.rs +++ b/crates/ctranslate2-bindings/src/lib.rs @@ -1,4 +1,4 @@ -use tokenizers::tokenizer::{Tokenizer}; +use tokenizers::tokenizer::Tokenizer; #[macro_use] extern crate derive_builder; @@ -73,7 +73,7 @@ impl TextInferenceEngine { options.num_replicas_per_device, ); return TextInferenceEngine { - engine: engine, + engine, tokenizer: Tokenizer::from_file(&options.tokenizer_path).unwrap(), }; } @@ -88,10 +88,11 @@ impl TextInferenceEngine { ); let output_ids: Vec = output_tokens .iter() - .filter_map(|x| { - match self.tokenizer.token_to_id(x) { - Some(y) => Some(y), - None => { println!("Warning: token ({}) missed in vocab", x); None } + .filter_map(|x| match self.tokenizer.token_to_id(x) { + Some(y) => Some(y), + None => { + println!("Warning: token ({}) missed in vocab", x); + None } }) .collect(); diff --git a/crates/rust-cxx-cmake-bridge/src/lib.rs b/crates/rust-cxx-cmake-bridge/src/lib.rs index 94bb7a1..885f208 100644 --- a/crates/rust-cxx-cmake-bridge/src/lib.rs +++ b/crates/rust-cxx-cmake-bridge/src/lib.rs @@ -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 let liblib_name = static_lib_path.my_file_prefix().unwrap(); 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: // - 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"); - return ( + ( dir.to_path_buf(), lib_name_str.to_string(), is_static, is_system, is_framework, - ); + ) } // 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 // - 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?" - if !is_system || is_static || !is_framework { + if (!is_system && !is_framework) || is_static { 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) { read_cmake_generated_to_output( - &cmake_generated_rust_wrapper_libs_str, + cmake_generated_rust_wrapper_libs_str, &mut std::io::stdout(), ) } @@ -116,7 +118,7 @@ impl HasMyFilePrefix for std::path::Path { fn my_file_prefix(&self) -> Option<&OsStr> { self.file_name() .map(split_file_at_dot) - .and_then(|(before, _after)| Some(before)) + .map(|(before, _after)| before) } } @@ -157,52 +159,68 @@ mod tests { #[test] 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"); assert_eq!(dir.as_os_str(), "/some/path"); assert_eq!(lib_name_str, "libstatic"); - assert_eq!(is_static, true); - assert_eq!(is_system, false); + assert!(is_static); + assert!(!is_system); + assert!(!is_framework); } #[test] 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"); assert_eq!(dir.as_os_str(), "/some/path"); assert_eq!(lib_name_str, "libshared"); - assert_eq!(is_static, false); - assert_eq!(is_system, false); + assert!(!is_static); + assert!(!is_system); + assert!(!is_framework); } #[test] 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"); assert_eq!(dir.as_os_str(), "/some/path"); assert_eq!(lib_name_str, "libshared"); - assert_eq!(is_static, false); - assert_eq!(is_system, false); + assert!(!is_static); + assert!(!is_system); + assert!(!is_framework); } #[test] 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"); assert_eq!(dir.as_os_str(), "/usr/lib"); assert_eq!(lib_name_str, "system1"); - assert_eq!(is_static, true); - assert_eq!(is_system, true); + assert!(is_static); + assert!(is_system); + assert!(!is_framework); } #[test] 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"); assert_eq!(dir.as_os_str(), "/usr/lib"); assert_eq!(lib_name_str, "system2"); - assert_eq!(is_static, false); - assert_eq!(is_system, true); + assert!(!is_static); + 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] diff --git a/crates/tabby/src/serve/completions.rs b/crates/tabby/src/serve/completions.rs index 125ac26..99d9a24 100644 --- a/crates/tabby/src/serve/completions.rs +++ b/crates/tabby/src/serve/completions.rs @@ -66,7 +66,7 @@ pub struct CompletionState { impl CompletionState { pub fn new(options: TextInferenceEngineCreateOptions) -> Self { let engine = TextInferenceEngine::create(options); - return Self { engine: engine }; + Self { engine } } } diff --git a/crates/tabby/src/serve/completions/languages.rs b/crates/tabby/src/serve/completions/languages.rs index 5ff637e..f9cab10 100644 --- a/crates/tabby/src/serve/completions/languages.rs +++ b/crates/tabby/src/serve/completions/languages.rs @@ -16,10 +16,10 @@ lazy_static! { pub fn remove_stop_words<'a>(language: &'a str, text: &'a str) -> &'a str { 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 { &text[..m.start()] } else { - &text + text } }