|
1 |
| -use std::{env, fs, path::Path}; |
2 |
| - |
3 |
| -const HUB_URL: &str = "https://releases.rivet.gg/hub/2025-01-13-06-33-44-c31561791-embed.zip"; |
4 |
| -const OUT_DIR: &str = "hub_files"; |
| 1 | +use std::{env, fs, path::Path, process::Command, path::PathBuf}; |
5 | 2 |
|
6 | 3 | fn main() -> Result<(), Box<dyn std::error::Error>> {
|
7 | 4 | // Get the output directory from the cargo environment variable
|
8 | 5 | let target_dir = env::var("OUT_DIR")?;
|
9 |
| - let out_dir = Path::new(&target_dir).join(OUT_DIR); |
10 |
| - |
11 |
| - // Download the file |
12 |
| - println!("cargo:rerun-if-changed=build.rs"); |
13 |
| - |
14 |
| - let response = reqwest::blocking::get(HUB_URL)?; |
15 |
| - let zip_content = response.bytes()?; |
16 |
| - |
17 |
| - // Extract to out dir |
18 |
| - if !out_dir.exists() { |
19 |
| - fs::create_dir_all(&out_dir)?; |
20 |
| - } |
21 |
| - |
22 |
| - let mut zip_archive = zip::ZipArchive::new(std::io::Cursor::new(zip_content))?; |
23 |
| - |
24 |
| - for i in 0..zip_archive.len() { |
25 |
| - let mut file = zip_archive.by_index(i)?; |
26 |
| - let outpath = out_dir.join(file.name()); |
27 |
| - |
28 |
| - if file.name().ends_with('/') { |
29 |
| - fs::create_dir_all(&outpath)?; |
30 |
| - } else { |
31 |
| - if let Some(p) = outpath.parent() { |
32 |
| - if !p.exists() { |
33 |
| - fs::create_dir_all(p)?; |
34 |
| - } |
35 |
| - } |
36 |
| - let mut outfile = fs::File::create(&outpath)?; |
37 |
| - std::io::copy(&mut file, &mut outfile)?; |
38 |
| - } |
39 |
| - } |
| 6 | + let manifest_dir = env::var("CARGO_MANIFEST_DIR")?; |
| 7 | + let out_dir = Path::new(&target_dir); |
| 8 | + |
| 9 | + let project_root = PathBuf::from(manifest_dir.clone()).join("../../.."); |
| 10 | + let hub_path = project_root.join("frontend/apps/hub"); |
| 11 | + |
| 12 | + // Build hub |
| 13 | + println!("Running yarn install"); |
| 14 | + let status = Command::new("yarn") |
| 15 | + .arg("install") |
| 16 | + .arg("--immutable") |
| 17 | + .current_dir(&hub_path) |
| 18 | + .status()?; |
| 19 | + assert!(status.success(), "yarn install failed"); |
| 20 | + |
| 21 | + println!("Running yarn build"); |
| 22 | + let status = Command::new("yarn") |
| 23 | + .current_dir(&hub_path) |
| 24 | + .args(["dlx", "turbo", "run", "build:embedded"]) |
| 25 | + // This will be substituted at runtime |
| 26 | + .env("VITE_APP_API_URL", "__APP_API_URL__") |
| 27 | + .status()?; |
| 28 | + assert!(status.success(), "hub build failed"); |
| 29 | + |
| 30 | + // Copy dist directory to out_dir |
| 31 | + let dist_path = hub_path.join("dist"); |
| 32 | + fs::create_dir_all(out_dir)?; |
| 33 | + fs_extra::dir::copy( |
| 34 | + dist_path, |
| 35 | + out_dir, |
| 36 | + &fs_extra::dir::CopyOptions::new().overwrite(true), |
| 37 | + )?; |
40 | 38 |
|
41 | 39 | // Set the path in the env
|
42 | 40 | println!("cargo:rustc-env=HUB_PATH={}", out_dir.display());
|
43 | 41 |
|
| 42 | + println!("cargo:rerun-if-changed={}", hub_path.display()); |
| 43 | + |
44 | 44 | Ok(())
|
45 | 45 | }
|
0 commit comments