merge upstream
All checks were successful
mnemo-build-and-publish / gractwo-mnemo-build (push) Successful in 40s

This commit is contained in:
2026-04-07 23:16:50 +00:00
5 changed files with 37 additions and 36 deletions

View File

@@ -21,6 +21,7 @@ RUN apk add --no-cache clang lld musl-dev git
# source code into the container. Once built, copy the executable to an
# output directory before the cache mounted /app/target is unmounted.
RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=build.rs,target=build.rs \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target/ \

View File

@@ -7,30 +7,35 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/web");
if std::env::var("IN_DOCKER").is_err() {
let os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| String::from("unknown"));
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_else(|_| String::from("unknown"));
let download_url = match (os.as_str(), arch.as_str()) {
("macos", "aarch64") => {
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64"
}
("linux", "x86_64") => {
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64"
}
("linux", "aarch64") => {
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-arm64"
}
_ => return Err(format!("Unsupported platform: {} {}", os, arch).into()),
};
let os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| String::from("unknown"));
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_else(|_| String::from("unknown"));
let env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_else(|_| String::from("unknown"));
let download_url = match (os.as_str(), arch.as_str(), env.as_str()) {
("macos", "aarch64", _) => {
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64"
}
("linux", "x86_64", "musl") => {
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64-musl"
}
("linux", "x86_64", _) => {
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64"
}
("linux", "aarch64", "musl") => {
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-arm64-musl"
}
("linux", "aarch64", _) => {
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-arm64"
}
_ => return Err(format!("Unsupported platform: {} {}", os, arch).into()),
};
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let tailwind_binary = out_dir.join("tailwind");
fs::create_dir_all(&out_dir)?;
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let tailwind_binary = out_dir.join("tailwind");
fs::create_dir_all(&out_dir)?;
download_tailwind(&download_url, &tailwind_binary)?;
println!("cargo:rustc-env=TAILWIND_BIN={}", tailwind_binary.display());
run_tailwind(&tailwind_binary)?;
}
download_tailwind(&download_url, &tailwind_binary)?;
println!("cargo:rustc-env=TAILWIND_BIN={}", tailwind_binary.display());
run_tailwind(&tailwind_binary)?;
Ok(())
}
@@ -43,19 +48,18 @@ fn run_tailwind(bin: &PathBuf) -> Result<(), Box<dyn std::error::Error>> {
.join("web")
.join("input.css");
let inputstr = input.to_str().unwrap();
let output = Path::new(&basedir)
.join("src")
.join("web")
.join("styles.css");
let output = PathBuf::from(env::var("OUT_DIR")?).join("styles.css");
let outputstr = output.to_str().unwrap();
let args = vec!["-i", inputstr, "-o", outputstr, "--minify"];
let run = Command::new(&bin).args(args).status()?;
match run.success() {
true => println!("Tailwind CSS build complete."),
false => println!("Tailwind CSS build failed."),
};
Ok(())
true => {
println!("Tailwind CSS build complete.");
Ok(())
}
false => panic!("Tailwind CSS build failed."),
}
}
fn download_tailwind(url: &str, target_path: &Path) -> Result<(), Box<dyn std::error::Error>> {

View File

@@ -2,5 +2,3 @@ Mnemosyne
Mnemosyne is a work-in-progress project which aims to satisfy all the quote-collecting needs of your community, all the while making them queryable and well notarized.
Note on tailwind and styles.css: The styles.css file, which is generated by a standalone Tailwind binary downloaded and executed automatically within build.rs, is to be committed any time it changes, as without it styling will be broken on the frontend part of the page. This is in contrast to a perhaps expected approach of gitignoring them and just generating them every build; this is incompatible with building docker images in an efficient way, however, as docker exposes no way to mount directories while retaining ability to write files and execute binaries.

View File

@@ -9,13 +9,13 @@ mod components;
mod icons;
mod pages;
pub const STYLES_CSS: &str = include_str!("./styles.css");
pub const CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/styles.css"));
pub fn web_router() -> Router {
Router::new()
.route(
"/styles.css",
get(|| async { ([(header::CONTENT_TYPE, "text/css")], STYLES_CSS) }),
get(([(header::CONTENT_TYPE, "text/css")], CSS)),
)
.merge(pages::pages())
}

File diff suppressed because one or more lines are too long