Start refactoring Rust code into separate crates

This commit is contained in:
Eric Zhang 2021-06-01 10:21:48 -05:00
parent 1b7f0ad808
commit fa3fcb5e69
16 changed files with 55 additions and 28 deletions

13
Cargo.lock generated
View file

@ -801,13 +801,22 @@ dependencies = [
]
[[package]]
name = "rustpad"
name = "rustpad-core"
version = "0.1.0"
dependencies = [
"operational-transform",
"serde",
"serde_json",
]
[[package]]
name = "rustpad-server"
version = "0.1.0"
dependencies = [
"dotenv",
"futures",
"log",
"operational-transform",
"parking_lot",
"pretty_env_logger",
"serde",
"serde_json",

View file

@ -1,19 +1,6 @@
[package]
name = "rustpad"
version = "0.1.0"
authors = ["Eric Zhang <ekzhang1@gmail.com>"]
edition = "2018"
[workspace]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dotenv = "0.15.0"
futures = "0.3.15"
log = "0.4.14"
operational-transform = "0.6.0"
pretty_env_logger = "0.4.0"
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
tokio = { version = "1.6.1", features = ["full"] }
tokio-stream = "0.1.6"
warp = "0.3.1"
members = [
"rustpad-server",
"rustpad-core",
]

View file

@ -1,8 +1,5 @@
FROM ekidd/rust-musl-builder:1.51.0 as backend
WORKDIR /home/rust/src
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
COPY . .
RUN cargo test --release
RUN cargo build --release
@ -16,6 +13,6 @@ RUN npm run build
FROM scratch
COPY --from=frontend /usr/src/app/dist dist
COPY --from=backend /home/rust/src/target/x86_64-unknown-linux-musl/release/rustpad .
COPY --from=backend /home/rust/src/target/x86_64-unknown-linux-musl/release/rustpad-server .
USER 1000:1000
CMD [ "./rustpad" ]
CMD [ "./rustpad-server" ]

View file

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/app/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rustpad</title>
<meta
@ -19,6 +19,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/app/main.tsx"></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

10
rustpad-core/Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "rustpad-core"
version = "0.1.0"
authors = ["Eric Zhang <ekzhang1@gmail.com>"]
edition = "2018"
[dependencies]
operational-transform = "0.6.0"
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"

7
rustpad-core/src/lib.rs Normal file
View file

@ -0,0 +1,7 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}

17
rustpad-server/Cargo.toml Normal file
View file

@ -0,0 +1,17 @@
[package]
name = "rustpad-server"
version = "0.1.0"
authors = ["Eric Zhang <ekzhang1@gmail.com>"]
edition = "2018"
[dependencies]
dotenv = "0.15.0"
futures = "0.3.15"
log = "0.4.14"
pretty_env_logger = "0.4.0"
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
tokio = { version = "1.6.1", features = ["full"] }
tokio-stream = "0.1.6"
warp = "0.3.1"
parking_lot = "0.11.1"

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -15,5 +15,5 @@
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["app"]
"include": ["src"]
}