Fix build script not using $OUT_PATH
This commit is contained in:
parent
794787a4be
commit
246cbf82cf
6 changed files with 55 additions and 29 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
|
@ -547,7 +547,27 @@ version = "5.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
"dirs-sys 0.4.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
|
||||
dependencies = [
|
||||
"dirs-sys 0.3.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2250,6 +2270,7 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
"quote",
|
||||
"rust-embed-utils",
|
||||
"shellexpand",
|
||||
"syn 2.0.28",
|
||||
"walkdir",
|
||||
]
|
||||
|
|
@ -2409,6 +2430,15 @@ dependencies = [
|
|||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shellexpand"
|
||||
version = "2.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.17"
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ humantime = "2.1.0"
|
|||
humantime-serde = "1.1.1"
|
||||
mime_guess = "2.0.4"
|
||||
rand = "0.8.5"
|
||||
rust-embed = "6.8.1"
|
||||
rust-embed = { version = "6.8.1", features = ["interpolate-folder-path"] }
|
||||
serde = { version = "1.0.181", features = ["derive"] }
|
||||
sqlx = { version = "0.7.1", features = ["runtime-tokio", "sqlite", "time"] }
|
||||
time = { version = "0.3.25", features = ["formatting", "macros", "parsing"] }
|
||||
|
|
|
|||
44
build.rs
44
build.rs
|
|
@ -6,38 +6,32 @@ use std::{
|
|||
|
||||
use walkdir::WalkDir;
|
||||
|
||||
const MIGRATION_DIR: &str = "migrations";
|
||||
const STATIC_DIR: &str = "static";
|
||||
const TEMPLATE_DIR: &str = "templates";
|
||||
|
||||
const STATIC_OUT_DIR: &str = "target/static";
|
||||
const STATIC_IGNORE_EXT: &[&str] = &["ts"];
|
||||
|
||||
fn watch_dir(path: &Path) {
|
||||
WalkDir::new(path)
|
||||
.into_iter()
|
||||
.for_each(|e| println!("cargo:rerun-if-changed={}", e.unwrap().path().display()));
|
||||
}
|
||||
|
||||
fn run_tsc() {
|
||||
let status = Command::new("tsc").status().unwrap();
|
||||
fn run_tsc(static_out_dir: &Path) {
|
||||
let status = Command::new("tsc")
|
||||
.arg("--outDir")
|
||||
.arg(static_out_dir)
|
||||
.status()
|
||||
.unwrap();
|
||||
|
||||
assert!(status.success(), "tsc produced errors");
|
||||
}
|
||||
|
||||
fn copy_static_files() {
|
||||
let files = WalkDir::new(STATIC_DIR)
|
||||
fn copy_static_files(static_dir: &Path, static_out_dir: &Path) {
|
||||
let files = WalkDir::new(static_dir)
|
||||
.into_iter()
|
||||
.map(|e| e.unwrap())
|
||||
.filter(|e| e.file_type().is_file())
|
||||
.filter(|e| {
|
||||
let extension = e.path().extension().and_then(|s| s.to_str()).unwrap_or("");
|
||||
!STATIC_IGNORE_EXT.contains(&extension)
|
||||
});
|
||||
.filter(|e| e.file_type().is_file());
|
||||
|
||||
for file in files {
|
||||
let components = file.path().components().collect::<Vec<_>>();
|
||||
let relative_path = components.into_iter().rev().take(file.depth()).rev();
|
||||
let mut target = PathBuf::new().join(STATIC_OUT_DIR);
|
||||
let mut target = static_out_dir.to_path_buf();
|
||||
target.extend(relative_path);
|
||||
fs::create_dir_all(target.parent().unwrap()).unwrap();
|
||||
fs::copy(file.path(), target).unwrap();
|
||||
|
|
@ -49,16 +43,18 @@ fn main() {
|
|||
builder.git_sha(false);
|
||||
builder.emit().unwrap();
|
||||
|
||||
watch_dir(MIGRATION_DIR.as_ref());
|
||||
watch_dir(STATIC_DIR.as_ref());
|
||||
watch_dir(TEMPLATE_DIR.as_ref());
|
||||
let out_dir: PathBuf = std::env::var("OUT_DIR").unwrap().into();
|
||||
let static_out_dir = out_dir.join("static");
|
||||
|
||||
// Since remove_dir_all fails if the directory doesn't exist, we ensure it
|
||||
// exists before deleting it. This way, we can use the remove_dir_all Result
|
||||
// to ensure the directory was deleted successfully.
|
||||
fs::create_dir_all(STATIC_OUT_DIR).unwrap();
|
||||
fs::remove_dir_all(STATIC_OUT_DIR).unwrap();
|
||||
fs::create_dir_all(&static_out_dir).unwrap();
|
||||
fs::remove_dir_all(&static_out_dir).unwrap();
|
||||
|
||||
run_tsc();
|
||||
copy_static_files();
|
||||
watch_dir("scripts".as_ref());
|
||||
run_tsc(&static_out_dir);
|
||||
|
||||
watch_dir("static".as_ref());
|
||||
copy_static_files("static".as_ref(), &static_out_dir);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use axum::{
|
|||
use rust_embed::RustEmbed;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "target/static"]
|
||||
#[folder = "$OUT_DIR/static"]
|
||||
pub struct StaticFiles;
|
||||
|
||||
pub struct StaticFile<T>(T);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{ // See also https://aka.ms/tsconfig
|
||||
"include": [ "static/**/*" ],
|
||||
"include": [ "scripts/**/*" ],
|
||||
|
||||
"compilerOptions": {
|
||||
"target": "ES2015",
|
||||
"module": "ES2015",
|
||||
"rootDir": "static",
|
||||
"rootDir": "scripts",
|
||||
"outDir": "target/static",
|
||||
|
||||
// Misc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue