Repository navigation
fix(build): build kokoro-server for the CMake target, not the host #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cdb33b5
bb0b6e9
1a9cc0b
c68d095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ A high-performance, lightweight C++ inference implementation of the [Kokoro](htt | |
| - **CMake** (3.15+) | ||
| - **Ninja** (recommended; `uv run bootstrap.py build` uses it when it is in `PATH`) | ||
| - **C++ compiler** (C++17 support required) | ||
| - **Rust** (1.80+, via [rustup](https://rustup.rs)): builds `kokoro-server`; configure with `-DKOKORO_BUILD_SERVER=OFF` to skip it | ||
| - **Rust** (1.80+, via [rustup](https://rustup.rs)): builds `kokoro-server` for the CMake target (cross builds need `rustup target add <triple>`, and a C compiler that already targets that triple, or `-DKOKORO_RUST_LINKER=<wrapper>` for non-MSVC cross builds—MSVC cross builds set `CARGO_TARGET_<TRIPLE>_LINKER` directly); if `CARGO_TARGET_<TRIPLE>_LINKER` is already set in the environment it takes precedence over `KOKORO_RUST_LINKER`—unset it when you need CMake to pass the wrapper; a macOS universal build (`CMAKE_OSX_ARCHITECTURES` set) may detect no single Rust target and default `KOKORO_BUILD_SERVER` OFF—set `-DKOKORO_RUST_TARGET=<triple>` and `-DKOKORO_BUILD_SERVER=ON` to enable it (a universal server needs separate architecture builds); configure with `-DKOKORO_BUILD_SERVER=OFF` to skip it | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the server default for all unmapped targets. On a fresh Linux Also applies to: 273-273, 499-499, 746-746
|
||
| - **[uv](https://docs.astral.sh/uv/)**: runs `bootstrap.py` and `voice_tool.py`, and installs their Python dependencies (Python 3.10+, click) into `.venv` on first use | ||
|
|
||
| ## Setup | ||
|
|
@@ -270,7 +270,7 @@ MIT | |
| - **CMake** (3.15+) | ||
| - **Ninja**(推荐;`uv run bootstrap.py build` 在 `PATH` 中找到它时使用) | ||
| - **C++ 编译器** (需要支持 C++17) | ||
| - **Rust**(1.80+,通过 [rustup](https://rustup.rs) 安装):用于构建 `kokoro-server`;配置时加 `-DKOKORO_BUILD_SERVER=OFF` 可跳过 | ||
| - **Rust**(1.80+,通过 [rustup](https://rustup.rs) 安装):为 CMake 目标平台构建 `kokoro-server`(交叉编译需先运行 `rustup target add <triple>`,且 C 编译器需已面向同一目标平台,否则非 MSVC 交叉编译用 `-DKOKORO_RUST_LINKER=<wrapper>`,MSVC 交叉编译直接设置 `CARGO_TARGET_<TRIPLE>_LINKER`);若环境中已设置 `CARGO_TARGET_<TRIPLE>_LINKER`,则优先于 `KOKORO_RUST_LINKER`(需要 CMake 传递包装器时请取消其设置);macOS 通用构建(设置 `CMAKE_OSX_ARCHITECTURES`)可能无法检测到单一 Rust 目标,从而默认关闭 `KOKORO_BUILD_SERVER`(通过 `-DKOKORO_RUST_TARGET=<triple>` 和 `-DKOKORO_BUILD_SERVER=ON` 启用;通用服务器需分别为各架构构建);配置时加 `-DKOKORO_BUILD_SERVER=OFF` 可跳过 | ||
| - **[uv](https://docs.astral.sh/uv/)**:用于运行 `bootstrap.py` 和 `voice_tool.py`,首次运行时会将其 Python 依赖(Python 3.10+、click)安装到 `.venv` | ||
|
|
||
| ## 准备 | ||
|
|
@@ -496,7 +496,7 @@ Implementación ligera y de alto rendimiento en C++ de la inferencia del modelo | |
| - **CMake** (3.15+) | ||
| - **Ninja** (recomendado; `uv run bootstrap.py build` lo usa si está en el `PATH`) | ||
| - **Compilador de C++** (con soporte de C++17) | ||
| - **Rust** (1.80+, con [rustup](https://rustup.rs)): compila `kokoro-server`; configura con `-DKOKORO_BUILD_SERVER=OFF` para omitirlo | ||
| - **Rust** (1.80+, con [rustup](https://rustup.rs)): compila `kokoro-server` para la plataforma destino de CMake (la compilación cruzada necesita `rustup target add <triple>` y un compilador de C que ya apunte a esa plataforma, o `-DKOKORO_RUST_LINKER=<wrapper>` para compilaciones cruzadas no MSVC—las compilaciones cruzadas MSVC establecen `CARGO_TARGET_<TRIPLE>_LINKER` directamente); si `CARGO_TARGET_<TRIPLE>_LINKER` ya está definido en el entorno, tiene prioridad sobre `KOKORO_RUST_LINKER`—desactívelo si necesita que CMake pase el wrapper; una compilación universal de macOS (`CMAKE_OSX_ARCHITECTURES` definido) puede no detectar un objetivo Rust único y desactivar `KOKORO_BUILD_SERVER` por defecto—use `-DKOKORO_RUST_TARGET=<triple>` y `-DKOKORO_BUILD_SERVER=ON` para habilitarlo (un servidor universal requiere compilaciones separadas por arquitectura); configura con `-DKOKORO_BUILD_SERVER=OFF` para omitirlo | ||
| - **[uv](https://docs.astral.sh/uv/)**: ejecuta `bootstrap.py` y `voice_tool.py`, e instala sus dependencias de Python (Python 3.10+, click) en `.venv` la primera vez | ||
|
|
||
| ## Preparación | ||
|
|
@@ -743,7 +743,7 @@ Eine schnelle, schlanke C++-Implementierung der Inferenz des TTS-Modells [Kokoro | |
| - **CMake** (3.15+) | ||
| - **Ninja** (empfohlen; `uv run bootstrap.py build` verwendet es, wenn es im `PATH` liegt) | ||
| - **C++-Compiler** (mit C++17-Unterstützung) | ||
| - **Rust** (1.80+, über [rustup](https://rustup.rs)): baut `kokoro-server`; mit `-DKOKORO_BUILD_SERVER=OFF` konfigurieren, um es auszulassen | ||
| - **Rust** (1.80+, über [rustup](https://rustup.rs)): baut `kokoro-server` für die CMake-Zielplattform (Cross-Builds brauchen `rustup target add <triple>` und einen C-Compiler, der bereits auf diese Zielplattform zeigt, oder `-DKOKORO_RUST_LINKER=<wrapper>` für nicht-MSVC-Cross-Builds—MSVC-Cross-Builds setzen `CARGO_TARGET_<TRIPLE>_LINKER` direkt); ist `CARGO_TARGET_<TRIPLE>_LINKER` bereits in der Umgebung gesetzt, hat es Vorrang vor `KOKORO_RUST_LINKER`—deaktivieren Sie es, wenn CMake den Wrapper übergeben soll; ein universeller macOS-Build (`CMAKE_OSX_ARCHITECTURES` gesetzt) kann kein einzelnes Rust-Ziel erkennen und `KOKORO_BUILD_SERVER` standardmäßig deaktivieren—setzen Sie `-DKOKORO_RUST_TARGET=<triple>` und `-DKOKORO_BUILD_SERVER=ON`, um es zu aktivieren (ein universeller Server erfordert separate Builds pro Architektur); mit `-DKOKORO_BUILD_SERVER=OFF` konfigurieren, um es auszulassen | ||
| - **[uv](https://docs.astral.sh/uv/)**: führt `bootstrap.py` und `voice_tool.py` aus und installiert beim ersten Aufruf ihre Python-Abhängigkeiten (Python 3.10+, click) in `.venv` | ||
|
|
||
| ## Einrichtung | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # Maps the CMake target (not the host) to a Rust target triple for kokoro-server. | ||
|
|
||
| # MSVC ABI: cl, clang-cl, and GNU-frontend clang++ targeting *-windows-msvc (where CMake leaves MSVC false). | ||
| function(_kokoro_msvc_abi out_var) | ||
| if (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") | ||
| set(${out_var} TRUE PARENT_SCOPE) | ||
| else() | ||
| set(${out_var} FALSE PARENT_SCOPE) | ||
| endif() | ||
| endfunction() | ||
|
|
||
| # Rust arch for the target, or "" when unknown or when several macOS architectures are requested. | ||
| function(_kokoro_rust_arch out_var) | ||
| _kokoro_msvc_abi(msvc_abi) | ||
| if (msvc_abi) | ||
| set(arch_id "${MSVC_CXX_ARCHITECTURE_ID}") | ||
| elseif (APPLE AND CMAKE_OSX_ARCHITECTURES) | ||
| set(arch_id "${CMAKE_OSX_ARCHITECTURES}") | ||
| else() | ||
| set(arch_id "${CMAKE_SYSTEM_PROCESSOR}") | ||
| endif() | ||
| string(TOLOWER "${arch_id}" arch_id) | ||
| if (arch_id MATCHES "^(x64|x86_64|amd64)$") | ||
| set(arch x86_64) | ||
| elseif (arch_id MATCHES "^(arm64|aarch64)$") | ||
| set(arch aarch64) | ||
| elseif (arch_id MATCHES "^(x86|i[3-6]86)$") | ||
| set(arch i686) | ||
| else() | ||
| set(arch "") | ||
| endif() | ||
| set(${out_var} "${arch}" PARENT_SCOPE) | ||
| endfunction() | ||
|
|
||
| # C library of the Linux target, from the toolchain's own triple: musl, else gnu. | ||
| function(_kokoro_linux_libc out_var) | ||
| set(triple "${CMAKE_C_COMPILER_TARGET}") | ||
| if (NOT triple AND CMAKE_C_COMPILER AND NOT MSVC) | ||
| execute_process(COMMAND "${CMAKE_C_COMPILER}" -dumpmachine | ||
| OUTPUT_VARIABLE triple OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE status ERROR_QUIET) | ||
| if (NOT status EQUAL 0) | ||
| set(triple "") | ||
| endif() | ||
| endif() | ||
| if (triple MATCHES "musl") | ||
| set(libc musl) | ||
| else() | ||
| set(libc gnu) # glibc, or a toolchain triple that does not say | ||
| endif() | ||
| set(${out_var} "${libc}" PARENT_SCOPE) | ||
| endfunction() | ||
|
|
||
| # Rust vendor-os(-env) suffix for the target, or "" when unsupported (Android, iOS, BSDs, ...). | ||
| function(_kokoro_rust_os out_var) | ||
| _kokoro_msvc_abi(msvc_abi) | ||
| _kokoro_rust_arch(arch) | ||
| if (WIN32 AND msvc_abi) | ||
| set(os pc-windows-msvc) | ||
| elseif (WIN32 AND MINGW) | ||
| if (arch STREQUAL "aarch64") | ||
| set(os pc-windows-gnullvm) | ||
| else() | ||
| set(os pc-windows-gnu) | ||
| endif() | ||
| elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") | ||
| set(os apple-darwin) | ||
| elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
| _kokoro_linux_libc(libc) | ||
| set(os "unknown-linux-${libc}") | ||
| else() | ||
| set(os "") | ||
| endif() | ||
| set(${out_var} "${os}" PARENT_SCOPE) | ||
| endfunction() | ||
|
|
||
| # Sets out_var to the Rust triple for the CMake target, or "" when there is no mapping. | ||
| function(kokoro_rust_target out_var) | ||
| _kokoro_rust_arch(arch) | ||
| _kokoro_rust_os(os) | ||
| if (arch AND os) | ||
| set(${out_var} "${arch}-${os}" PARENT_SCOPE) | ||
| else() | ||
| set(${out_var} "" PARENT_SCOPE) | ||
| endif() | ||
| endfunction() | ||
|
|
||
| # Sets out_var to the rustc Cargo will use: an explicit RUSTC, else the rustc on PATH, else the one beside cargo | ||
| # (exported to Cargo through out_export, since Cargo would not find that one). A build.rustc in .cargo/config.toml is | ||
| # not visible here, so the probe can only be stricter than the build. | ||
| function(kokoro_rustc out_var cargo out_export) | ||
| if (DEFINED ENV{RUSTC} AND NOT "$ENV{RUSTC}" STREQUAL "") | ||
| set(rustc "$ENV{RUSTC}") | ||
| set(export FALSE) | ||
| else() | ||
| find_program(_kokoro_path_rustc rustc) | ||
| if (_kokoro_path_rustc) | ||
| set(rustc "${_kokoro_path_rustc}") | ||
| set(export FALSE) | ||
| else() | ||
| get_filename_component(cargo_dir "${cargo}" DIRECTORY) | ||
| find_program(_kokoro_beside_rustc rustc HINTS "${cargo_dir}") | ||
| if (NOT _kokoro_beside_rustc) | ||
| message(FATAL_ERROR "rustc not found: ${cargo} is present but no rustc is on PATH or beside it") | ||
| endif() | ||
| set(rustc "${_kokoro_beside_rustc}") | ||
| set(export TRUE) | ||
| endif() | ||
| endif() | ||
| set(${out_var} "${rustc}" PARENT_SCOPE) | ||
| set(${out_export} "${export}" PARENT_SCOPE) | ||
| endfunction() | ||
|
|
||
| # Fails configuration unless rustc has the standard library for the triple. | ||
| function(kokoro_require_rust_std rustc triple) | ||
| execute_process(COMMAND "${rustc}" --print target-libdir --target "${triple}" | ||
| OUTPUT_VARIABLE libdir OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| RESULT_VARIABLE status ERROR_QUIET) | ||
| if (NOT status EQUAL 0 OR NOT IS_DIRECTORY "${libdir}") | ||
| message(FATAL_ERROR "Rust has no standard library for ${triple}: run `rustup target add ${triple}`, " | ||
| "set -DKOKORO_RUST_TARGET=<triple>, or configure with -DKOKORO_BUILD_SERVER=OFF") | ||
| endif() | ||
| endfunction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the Cargo compiler configuration exception.
If
.cargo/config.tomlsetsbuild.rustc, Cargo can use a different compiler from the one selected by this probe. The probe can then reject a target that the configured compiler supports. Document this exception instead of saying that the probe always uses Cargo's compiler.