Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite from proc-macro to build.rs #15

Merged
merged 16 commits into from
Nov 11, 2024
Merged
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
CARGO_TERM_COLOR: always
ASSET_DIR: ../static

jobs:
format:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["memory-serve", "memory-serve-macros", "examples/test"]
members = ["memory-serve", "examples/test"]
resolver = "2"

[workspace.package]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ memory-serve is designed to work with [axum](https://github.com/tokio-rs/axum)
## Usage

Provide a relative path to the directory containing your static assets
to the [`load_assets!`] macro. This macro creates a data structure intended to
using the `ASSET_PATH` environment variable. This macro creates a data structure intended to
be consumed by [`MemoryServe::new`]. Calling [`MemoryServe::into_router()`] on
the resulting instance produces a axum
Copy link
Contributor

@paul-hansen paul-hansen Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment still mentions the removed macro.

Feel free to write something different but I adapted part of the description of the PR to maybe save you some time:

Suggested change
Provide a relative path to the directory containing your static assets
to the [`load_assets!`] macro. This macro creates a data structure intended to
using the `ASSET_PATH` environment variable. This macro creates a data structure intended to
be consumed by [`MemoryServe::new`]. Calling [`MemoryServe::into_router()`] on
the resulting instance produces a axum
Provide a relative path to the directory containing your static assets
using the `ASSET_PATH` environment variable. This path will be used in a build script and any changes to files in that path or the variable itself will trigger a rerun and will load fresh assets. The output of the build script is consumed by [`MemoryServe::new`]. Calling [`MemoryServe::into_router()`] on
the resulting instance produces a axum

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I took your suggestion and also mentioned the build script instead of the macro further on. See 7fad903

[`Router`](https://docs.rs/axum/latest/axum/routing/struct.Router.html) that
Expand All @@ -45,12 +45,12 @@ calling [`Router::into_make_service()`](https://docs.rs/axum/latest/axum/routing

```rust,no_run
use axum::{response::Html, routing::get, Router};
use memory_serve::{load_assets, MemoryServe};
use memory_serve::MemoryServe;
use std::net::SocketAddr;

#[tokio::main]
async fn main() {
let memory_router = MemoryServe::new(load_assets!("static"))
let memory_router = MemoryServe::new()
.index_file(Some("/index.html"))
.into_router();

Expand Down
10 changes: 6 additions & 4 deletions examples/test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use axum::{response::Html, routing::get, Router};
use memory_serve::{load_assets, MemoryServe};
use memory_serve::MemoryServe;
use std::net::SocketAddr;
use tracing::info;
use tracing::{info, Level};

#[tokio::main]
async fn main() {
tracing_subscriber::fmt().init();
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();

let memory_router = MemoryServe::new(load_assets!("../../static"))
let memory_router = MemoryServe::new()
.index_file(Some("/index.html"))
.into_router();

Expand Down
22 changes: 0 additions & 22 deletions memory-serve-macros/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion memory-serve-macros/README.md

This file was deleted.

31 changes: 0 additions & 31 deletions memory-serve-macros/src/asset.rs

This file was deleted.

62 changes: 0 additions & 62 deletions memory-serve-macros/src/lib.rs

This file was deleted.

158 changes: 0 additions & 158 deletions memory-serve-macros/src/utils.rs

This file was deleted.

11 changes: 8 additions & 3 deletions memory-serve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ publish.workspace = true
description.workspace = true

[dependencies]
brotli = "6.0"
brotli = "7.0"
flate2 = "1.0"
axum = { version = "0.7", default-features = false }
memory-serve-macros = { version = "0.6", path = "../memory-serve-macros" }
tracing = "0.1"
sha256 = "1.4"

[build-dependencies]
sha256 = "1.4"
brotli = "7.0"
mime_guess = "2.0"
walkdir = "2"

[dev-dependencies]
tokio = { version = "1", features = ["full"] }
tower = "0.4"
tower = { version = "0.5", features = ["util"] }
axum = { version = "0.7" }
Loading