-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(hub-embed): auto-build & embed hub instead of pulling from rele…
…ases
- Loading branch information
1 parent
7ad0ba7
commit 4bce14d
Showing
7 changed files
with
46 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,6 @@ tests/basic-game/.env | |
# Added by cargo | ||
|
||
/target | ||
.env* | ||
.yarn/cache | ||
.yarn/install-state.gz | ||
.turbo |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
use std::{env, fs, path::Path}; | ||
|
||
const HUB_URL: &str = "https://releases.rivet.gg/hub/2025-01-13-06-33-44-c31561791-embed.zip"; | ||
const OUT_DIR: &str = "hub_files"; | ||
use std::{env, fs, path::Path, process::Command, path::PathBuf}; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// Get the output directory from the cargo environment variable | ||
let target_dir = env::var("OUT_DIR")?; | ||
let out_dir = Path::new(&target_dir).join(OUT_DIR); | ||
|
||
// Download the file | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
|
||
let response = reqwest::blocking::get(HUB_URL)?; | ||
let zip_content = response.bytes()?; | ||
|
||
// Extract to out dir | ||
if !out_dir.exists() { | ||
fs::create_dir_all(&out_dir)?; | ||
} | ||
|
||
let mut zip_archive = zip::ZipArchive::new(std::io::Cursor::new(zip_content))?; | ||
|
||
for i in 0..zip_archive.len() { | ||
let mut file = zip_archive.by_index(i)?; | ||
let outpath = out_dir.join(file.name()); | ||
|
||
if file.name().ends_with('/') { | ||
fs::create_dir_all(&outpath)?; | ||
} else { | ||
if let Some(p) = outpath.parent() { | ||
if !p.exists() { | ||
fs::create_dir_all(p)?; | ||
} | ||
} | ||
let mut outfile = fs::File::create(&outpath)?; | ||
std::io::copy(&mut file, &mut outfile)?; | ||
} | ||
} | ||
let manifest_dir = env::var("CARGO_MANIFEST_DIR")?; | ||
let out_dir = Path::new(&target_dir); | ||
|
||
let project_root = PathBuf::from(manifest_dir.clone()).join("../../.."); | ||
let hub_path = project_root.join("frontend/apps/hub"); | ||
|
||
// Build hub | ||
println!("Running yarn install"); | ||
let status = Command::new("yarn") | ||
.arg("install") | ||
.arg("--immutable") | ||
.current_dir(&hub_path) | ||
.status()?; | ||
assert!(status.success(), "yarn install failed"); | ||
|
||
println!("Running yarn build"); | ||
let status = Command::new("yarn") | ||
.current_dir(&hub_path) | ||
.args(["dlx", "turbo", "run", "build:embedded"]) | ||
// This will be substituted at runtime | ||
.env("VITE_APP_API_URL", "__APP_API_URL__") | ||
.status()?; | ||
assert!(status.success(), "hub build failed"); | ||
|
||
// Copy dist directory to out_dir | ||
let dist_path = hub_path.join("dist"); | ||
fs::create_dir_all(out_dir)?; | ||
fs_extra::dir::copy( | ||
dist_path, | ||
out_dir, | ||
&fs_extra::dir::CopyOptions::new().overwrite(true), | ||
)?; | ||
|
||
// Set the path in the env | ||
println!("cargo:rustc-env=HUB_PATH={}", out_dir.display()); | ||
|
||
println!("cargo:rerun-if-changed={}", hub_path.display()); | ||
|
||
Ok(()) | ||
} |