aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-omega-router / build.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! Decides whether omega's one-launch MoE router (`src/omega_gpu_router_api.h`, |
| 17 | //! OWN-30B router cut on the omega side) is linked. |
| 18 | //! |
| 19 | //! The archive itself is linked by `aien-omega-gpu`'s build script (this crate only declares |
| 20 | //! the extra symbols), so the decision mirrors its inputs: |
| 21 | //! * `AIEN_FORCE_CPU_STUB=1`: stub. |
| 22 | //! * `AIEN_OMEGA_GPU_LIB=<archive>`: native when `nm` finds `omega_gpu_router` defined |
| 23 | //! in that archive. |
| 24 | //! * `AIEN_OMEGA_DIR=<checkout>`: native when the checkout has `src/omega_gpu_router_api.h`. |
| 25 | //! * otherwise: stub (every call returns `Unavailable`). |
| 26 | //! |
| 27 | //! `cfg(has_omega_router)` is set only when native. A stub never fails the build: the engine |
| 28 | //! keeps its host routing, and `is_native()` says which |
| 29 | //! one a binary carries. |
| 30 | use std::path::Path; |
| 31 | use std::process::Command; |
| 32 | |
| 33 | fn main() { |
| 34 | println!("cargo:rustc-check-cfg=cfg(has_omega_router)"); |
| 35 | for v in [ |
| 36 | "AIEN_FORCE_CPU_STUB", |
| 37 | "AIEN_OMEGA_GPU_LIB", |
| 38 | "AIEN_OMEGA_DIR", |
| 39 | ] { |
| 40 | println!("cargo:rerun-if-env-changed={v}"); |
| 41 | } |
| 42 | if std::env::var("AIEN_FORCE_CPU_STUB").as_deref() == Ok("1") { |
| 43 | return; |
| 44 | } |
| 45 | if let Ok(lib) = std::env::var("AIEN_OMEGA_GPU_LIB") { |
| 46 | println!("cargo:rerun-if-changed={lib}"); |
| 47 | if archive_defines(Path::new(&lib), "omega_gpu_router") { |
| 48 | println!("cargo:rustc-cfg=has_omega_router"); |
| 49 | } else { |
| 50 | println!("cargo:warning=aien-omega-router: {lib} does not define the device router API; the device router is stubbed"); |
| 51 | } |
| 52 | return; |
| 53 | } |
| 54 | if let Ok(dir) = std::env::var("AIEN_OMEGA_DIR") { |
| 55 | let header = Path::new(&dir).join("src/omega_gpu_router_api.h"); |
| 56 | println!("cargo:rerun-if-changed={}", header.display()); |
| 57 | if header.is_file() { |
| 58 | println!("cargo:rustc-cfg=has_omega_router"); |
| 59 | } else { |
| 60 | println!("cargo:warning=aien-omega-router: {dir} has no src/omega_gpu_router_api.h (omega before OWN-30B cut 8); the device router is stubbed"); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | fn archive_defines(lib: &Path, symbol: &str) -> bool { |
| 66 | let Ok(out) = Command::new("nm").arg(lib).output() else { |
| 67 | println!("cargo:warning=aien-omega-router: nm not available, assuming the archive lacks the device router API"); |
| 68 | return false; |
| 69 | }; |
| 70 | String::from_utf8_lossy(&out.stdout) |
| 71 | .lines() |
| 72 | .any(|l| l.ends_with(&format!(" T {symbol}"))) |
| 73 | } |