adding gzip to static files
This commit is contained in:
parent
c4826d3bfd
commit
5364b66629
|
@ -1,4 +1,4 @@
|
|||
[alias]
|
||||
xtask = "r -p xtask --"
|
||||
wasm-build = "b --target wasm32-unknown-unknown --profile=small -Zbuild-std=core,alloc -Zbuild-std-features=optimize_for_size,panic_immediate_abort -p"
|
||||
wasm-build-debug = "b --target wasm32-unknown-unknown -p"
|
||||
wasm-build-debug = "b --target wasm32-unknown-unknown --profile=small-dev -Zbuild-std=core,alloc -Zbuild-std-features=optimize_for_size -p"
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,4 +3,4 @@
|
|||
/.rgignore
|
||||
rustc-ice-*
|
||||
db.sqlite
|
||||
/depell/src/*.wasm
|
||||
/depell/src/*.gz
|
||||
|
|
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -1,6 +1,6 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
|
@ -407,9 +407,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.158"
|
||||
version = "0.2.159"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
|
||||
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
|
||||
|
||||
[[package]]
|
||||
name = "libsqlite3-sys"
|
||||
|
@ -528,9 +528,9 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.86"
|
||||
version = "1.0.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
|
||||
checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
@ -547,7 +547,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "regalloc2"
|
||||
version = "0.10.2"
|
||||
source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#4100af4e24bc2921c0931c901651a969c898f852"
|
||||
source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#21c43e3ee182824e92e2b25f1d3c03ed47f9c02b"
|
||||
dependencies = [
|
||||
"allocator-api2",
|
||||
"bumpalo",
|
||||
|
|
11
Cargo.toml
11
Cargo.toml
|
@ -29,13 +29,16 @@ codegen-units = 1
|
|||
panic = "abort"
|
||||
|
||||
[profile.small]
|
||||
#rustflags = ["-Zfmt-debug=none", "-Zlocation-detail=none"]
|
||||
rustflags = ["-Zfmt-debug=none", "-Zlocation-detail=none"]
|
||||
inherits = "release"
|
||||
opt-level = "z"
|
||||
strip = "debuginfo"
|
||||
#strip = true
|
||||
strip = true
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
||||
|
||||
[profile.small-dev]
|
||||
inherits = "dev"
|
||||
opt-level = "z"
|
||||
strip = "debuginfo"
|
||||
panic = "abort"
|
||||
|
|
|
@ -12,3 +12,6 @@ rusqlite = "0.32.1"
|
|||
serde = { version = "1.0.210", features = ["derive"] }
|
||||
time = "0.3.36"
|
||||
tokio = { version = "1.40.0", features = ["rt"] }
|
||||
|
||||
[features]
|
||||
gzip = []
|
||||
|
|
|
@ -22,7 +22,10 @@ macro_rules! static_asset {
|
|||
get(|| async {
|
||||
axum::http::Response::builder()
|
||||
.header("content-type", $mime)
|
||||
.body(axum::body::Body::from(Bytes::from_static(include_bytes!($body))))
|
||||
.header("content-encoding", "gzip")
|
||||
.body(axum::body::Body::from(Bytes::from_static(include_bytes!(concat!(
|
||||
$body, ".gz"
|
||||
)))))
|
||||
.unwrap()
|
||||
})
|
||||
};
|
||||
|
@ -42,20 +45,8 @@ async fn amain() {
|
|||
.route("/", get(Index::page))
|
||||
.route("/index.css", static_asset!("text/css", "index.css"))
|
||||
.route("/index.js", static_asset!("text/javascript", "index.js"))
|
||||
.route(
|
||||
"/hbfmt.wasm",
|
||||
static_asset!(
|
||||
"application/wasm",
|
||||
"../../target/wasm32-unknown-unknown/small/wasm_hbfmt.wasm"
|
||||
),
|
||||
)
|
||||
.route(
|
||||
"/hbc.wasm",
|
||||
static_asset!(
|
||||
"application/wasm",
|
||||
"../../target/wasm32-unknown-unknown/small/wasm_hbc.wasm"
|
||||
),
|
||||
)
|
||||
.route("/hbfmt.wasm", static_asset!("application/wasm", "hbfmt.wasm"))
|
||||
.route("/hbc.wasm", static_asset!("application/wasm", "hbc.wasm"))
|
||||
.route("/index-view", get(Index::get))
|
||||
.route("/feed", get(Index::page))
|
||||
.route("/profile", get(Profile::page))
|
||||
|
|
|
@ -9,6 +9,6 @@ crate-type = ["cdylib"]
|
|||
[dependencies]
|
||||
hblang = { workspace = true, features = [] }
|
||||
hbvm.workspace = true
|
||||
log = "0.4.22"
|
||||
log = { version = "0.4.22", features = ["release_max_level_error"] }
|
||||
wasm-rt = { version = "0.1.0", path = "../wasm-rt", features = ["log"] }
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#![feature(alloc_error_handler)]
|
||||
#![feature(pointer_is_aligned_to)]
|
||||
#![feature(slice_take)]
|
||||
#![no_std]
|
||||
|
||||
|
@ -36,9 +37,9 @@ macro_rules! decl_runtime {
|
|||
|
||||
unsafe {
|
||||
use core::fmt::Write;
|
||||
let mut f = Write(&mut PANIC_MESSAGE[..]);
|
||||
let mut f = $crate::Write(&mut PANIC_MESSAGE[..]);
|
||||
_ = writeln!(f, "{}", _info);
|
||||
PANIC_MESSAGE_LEN = 1024 - f.0.len();
|
||||
PANIC_MESSAGE_LEN = $max_panic_size - f.0.len();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,7 @@ impl log::Log for Logger {
|
|||
|
||||
fn log(&self, record: &log::Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
const MAX_LOG_MESSAGE: usize = 1024 * 4;
|
||||
const MAX_LOG_MESSAGE: usize = 1024 * 8;
|
||||
#[no_mangle]
|
||||
static mut LOG_MESSAGES: [u8; MAX_LOG_MESSAGE] = [0; MAX_LOG_MESSAGE];
|
||||
#[no_mangle]
|
||||
|
@ -115,7 +116,8 @@ unsafe impl<const SIZE: usize> GlobalAlloc for ArenaAllocator<SIZE> {
|
|||
let until = self.arena.get() as *mut u8;
|
||||
|
||||
let new_head = (*self.head.get()).sub(size);
|
||||
let aligned_head = (new_head as usize & !(1 << (align - 1))) as *mut u8;
|
||||
let aligned_head = (new_head as usize & !(align - 1)) as *mut u8;
|
||||
debug_assert!(aligned_head.is_aligned_to(align));
|
||||
|
||||
if until > aligned_head {
|
||||
return core::ptr::null_mut();
|
||||
|
|
|
@ -294,7 +294,7 @@ enum LocCow<'a> {
|
|||
Owned(Loc),
|
||||
}
|
||||
|
||||
impl<'a> LocCow<'a> {
|
||||
impl LocCow<'_> {
|
||||
fn as_ref(&self) -> &Loc {
|
||||
match self {
|
||||
Self::Ref(value) => value,
|
||||
|
@ -309,7 +309,7 @@ impl<'a> From<&'a Loc> for LocCow<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Loc> for LocCow<'a> {
|
||||
impl From<Loc> for LocCow<'_> {
|
||||
fn from(value: Loc) -> Self {
|
||||
Self::Owned(value)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
slice_from_ptr_range,
|
||||
is_sorted
|
||||
)]
|
||||
#![feature(pointer_is_aligned_to)]
|
||||
#![warn(clippy::dbg_macro)]
|
||||
#![allow(stable_features, internal_features)]
|
||||
#![no_std]
|
||||
|
@ -532,7 +533,7 @@ mod ty {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> core::fmt::Display for Display<'a> {
|
||||
impl core::fmt::Display for Display<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
use Kind as TK;
|
||||
match TK::from_ty(self.ty) {
|
||||
|
|
|
@ -818,7 +818,7 @@ generate_expr! {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Expr<'a> {
|
||||
impl Expr<'_> {
|
||||
pub fn declares(&self, iden: Result<Ident, &str>) -> Option<Ident> {
|
||||
match *self {
|
||||
Self::Ident { id, name, .. } if iden == Ok(id) || iden == Err(name) => Some(id),
|
||||
|
@ -897,13 +897,13 @@ impl Poser for Pos {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Poser for Expr<'a> {
|
||||
impl Poser for Expr<'_> {
|
||||
fn posi(&self) -> Pos {
|
||||
self.pos()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Poser> Poser for CommentOr<'a, T> {
|
||||
impl<T: Poser> Poser for CommentOr<'_, T> {
|
||||
fn posi(&self) -> Pos {
|
||||
match self {
|
||||
CommentOr::Or(expr) => expr.posi(),
|
||||
|
@ -918,7 +918,7 @@ pub enum CommentOr<'a, T> {
|
|||
Comment { literal: &'a str, pos: Pos },
|
||||
}
|
||||
|
||||
impl<'a, T: Copy> CommentOr<'a, T> {
|
||||
impl<T: Copy> CommentOr<'_, T> {
|
||||
pub fn or(&self) -> Option<T> {
|
||||
match *self {
|
||||
CommentOr::Or(v) => Some(v),
|
||||
|
@ -1175,7 +1175,7 @@ impl StackAlloc {
|
|||
}
|
||||
|
||||
let dst = self.data.add(self.len) as *mut T;
|
||||
debug_assert!(dst.is_aligned(),);
|
||||
debug_assert!(dst.is_aligned());
|
||||
self.len += core::mem::size_of::<T>();
|
||||
core::ptr::write(dst, value);
|
||||
}
|
||||
|
|
|
@ -2556,7 +2556,7 @@ impl<'a> Function<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> regalloc2::Function for Function<'a> {
|
||||
impl regalloc2::Function for Function<'_> {
|
||||
fn num_insts(&self) -> usize {
|
||||
self.instrs.len()
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ impl BitSet {
|
|||
const ELEM_SIZE: usize = core::mem::size_of::<usize>() * 8;
|
||||
|
||||
pub fn clear(&mut self, bit_size: usize) {
|
||||
let new_len = (bit_size + Self::ELEM_SIZE - 1) / Self::ELEM_SIZE;
|
||||
let new_len = bit_size.div_ceil(Self::ELEM_SIZE);
|
||||
self.data.clear();
|
||||
self.data.resize(new_len, 0);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use {
|
|||
alloc::boxed::Box,
|
||||
};
|
||||
|
||||
impl<'p, A, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, A, OUT_PROG_EXEC> {
|
||||
impl<A, const OUT_PROG_EXEC: bool> SoftPagedMem<'_, A, OUT_PROG_EXEC> {
|
||||
/// Maps host's memory into VM's memory
|
||||
///
|
||||
/// # Safety
|
||||
|
|
|
@ -32,8 +32,8 @@ pub struct SoftPagedMem<'p, PfH, const OUT_PROG_EXEC: bool = true> {
|
|||
pub icache: ICache,
|
||||
}
|
||||
|
||||
impl<'p, PfH: HandlePageFault, const OUT_PROG_EXEC: bool> Memory
|
||||
for SoftPagedMem<'p, PfH, OUT_PROG_EXEC>
|
||||
impl<PfH: HandlePageFault, const OUT_PROG_EXEC: bool> Memory
|
||||
for SoftPagedMem<'_, PfH, OUT_PROG_EXEC>
|
||||
{
|
||||
/// Load value from an address
|
||||
///
|
||||
|
@ -92,7 +92,7 @@ impl<'p, PfH: HandlePageFault, const OUT_PROG_EXEC: bool> Memory
|
|||
}
|
||||
}
|
||||
|
||||
impl<'p, PfH: HandlePageFault, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, PfH, OUT_PROG_EXEC> {
|
||||
impl<PfH: HandlePageFault, const OUT_PROG_EXEC: bool> SoftPagedMem<'_, PfH, OUT_PROG_EXEC> {
|
||||
// Everyone behold, the holy function, the god of HBVM memory accesses!
|
||||
|
||||
/// Split address to pages, check their permissions and feed pointers with offset
|
||||
|
|
|
@ -33,27 +33,34 @@ fn build_wasm_blob(name: &str, debug: bool) -> io::Result<()> {
|
|||
let mut c = build_cmd(if debug { "cargo wasm-build-debug" } else { "cargo wasm-build" });
|
||||
c.arg(format!("wasm-{name}"));
|
||||
exec(c)?;
|
||||
|
||||
let out_path = format!("target/wasm32-unknown-unknown/small/wasm_{name}.wasm");
|
||||
let profile = if debug { "small-dev" } else { "small" };
|
||||
let out_path = format!("target/wasm32-unknown-unknown/{profile}/wasm_{name}.wasm");
|
||||
if !debug {
|
||||
exec(build_cmd(format!("wasm-opt -Oz {out_path} -o {out_path}")))?;
|
||||
}
|
||||
exec(build_cmd(format!("cp {out_path} depell/src/wasm-{name}.wasm")))
|
||||
exec(build_cmd(format!("cp {out_path} depell/src/{name}.wasm")))?;
|
||||
exec(build_cmd(format!("gzip -f depell/src/{name}.wasm")))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let args = std::env::args().skip(1).collect::<Vec<_>>();
|
||||
match args[0].as_str() {
|
||||
"fmt" => fmt(args[1] == "-r" || args[1] == "--renumber"),
|
||||
"build-depell" => {
|
||||
build_wasm_blob("hbfmt", false)?;
|
||||
build_wasm_blob("hbc", false)?;
|
||||
exec(build_cmd("cargo build -p depell --release"))?;
|
||||
Ok(())
|
||||
}
|
||||
"build-depell-debug" => {
|
||||
build_wasm_blob("hbfmt", true)?;
|
||||
build_wasm_blob("hbc", true)?;
|
||||
exec(build_cmd("gzip -k -f depell/src/index.js"))?;
|
||||
exec(build_cmd("gzip -k -f depell/src/index.css"))?;
|
||||
exec(build_cmd("cargo run -p depell --features gzip"))?;
|
||||
Ok(())
|
||||
}
|
||||
"build-depell" => {
|
||||
build_wasm_blob("hbfmt", false)?;
|
||||
build_wasm_blob("hbc", false)?;
|
||||
exec(build_cmd("gzip -k -f depell/src/index.js"))?;
|
||||
exec(build_cmd("gzip -k -f depell/src/index.css"))?;
|
||||
exec(build_cmd("cargo run -p depell --features gzip --release"))?;
|
||||
Ok(())
|
||||
}
|
||||
_ => Ok(()),
|
||||
|
|
Loading…
Reference in a new issue