1
0
Fork 1
mirror of https://example.com synced 2024-11-24 11:06:38 +09:00

dev: create virtual rust workspace in the repository root

Co-authored-by: naskya <m@naskya.net>
This commit is contained in:
sup39 2024-01-31 19:32:56 +09:00 committed by naskya
parent 8dc96a3195
commit 18aeeaabd2
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
12 changed files with 89 additions and 67 deletions

View file

@ -45,6 +45,8 @@ Dockerfile
docker-compose.yml
docker-compose.example.yml
/target
/dev
/docs
/neko

3
.gitignore vendored
View file

@ -73,9 +73,10 @@ yarn*
.devenv
.direnv
# Cargo cache for Docker
# Cargo
/.cargo-cache
/.cargo-target
/target
# Custom
custom/

35
Cargo.toml Normal file
View file

@ -0,0 +1,35 @@
[workspace]
members = ["packages/backend-rs"]
resolver = "2"
[workspace.dependencies]
napi = { version = "2.15.0", default-features = false }
napi-build = "2.1.0"
napi-derive = "2.15.0"
argon2 = "0.5.3"
async-trait = "0.1.77"
basen = "0.1.0"
bcrypt = "0.15.0"
cfg-if = "1.0.0"
chrono = "0.4.33"
cuid2 = "0.1.2"
idna = "0.5.0"
jsonschema = "0.17.1"
once_cell = "1.19.0"
parse-display = "0.8.2"
pretty_assertions = "1.4.0"
rand = "0.8.5"
regex = "1.10.3"
schemars = "0.8.16"
sea-orm = "0.12.12"
serde ="1.0.196"
serde_json = "1.0.113"
serde_yaml = "0.9.31"
thiserror = "1.0.56"
tokio = "1.35.1"
url = "2.5.0"
urlencoding = "2.1.3"
[profile.release]
lto = true

View file

@ -10,9 +10,13 @@ PACKAGE_JSONS += packages/firefish-js/package.json
PACKAGE_JSONS += packages/megalodon/package.json
PACKAGE_JSONS += packages/sw/package.json
RUST_DIR := packages/backend-rs
RUSTY_STUFF := $(call recursive_wildcard, $(RUST_DIR)/src, *)
RUSTY_STUFF += $(RUST_DIR)/Cargo.toml
CARGO_TOMLS := Cargo.toml
CARGO_TOMLS += packages/backend-rs/Cargo.toml
RUST_BE_DIR := packages/backend-rs
RUST_BE_SRC := Cargo.toml
RUST_BE_SRC += $(RUST_BE_DIR)/Cargo.toml
RUST_BE_SRC += $(call recursive_wildcard, $(RUST_BE_DIR)/src, *)
MIGRATIONS := $(foreach dir, packages/backend/migration, $(wildcard $(dir)/*))
MIGRATIONS += $(foreach dir, packages/backend/migration-neko, $(wildcard $(dir)/*))
@ -50,13 +54,13 @@ $(T)/test-revert: neko/revert.sql $(MIGRATIONS)
.PHONY: update-lockfiles
update-lockfiles: pnpm-lock.yaml $(RUST_DIR)/Cargo.lock
update-lockfiles: pnpm-lock.yaml Cargo.lock
pnpm-lock.yaml: pnpm-workspace.yaml $(PACKAGE_JSONS)
pnpm install
$(RUST_DIR)/Cargo.lock: $(RUST_DIR)/Cargo.toml
cd $(RUST_DIR) && cargo update
Cargo.lock: $(CARGO_TOMLS)
cargo update
.PHONY: run
@ -81,9 +85,9 @@ format:
.PHONY: rust-lint
rust-lint: $(T)/rust-lint
rust-lint: $(T)/rust-be-lint
$(T)/rust-lint: $(RUSTY_STUFF)
$(T)/rust-be-lint: $(RUST_BE_SRC)
pnpm --filter='backend-rs' run lint
touch $@
@ -93,7 +97,7 @@ regenerate-entities: $(T)/regenerate-entities
$(T)/regenerate-entities: $(MIGRATIONS)
pnpm run migrate
cd $(RUST_DIR) && \
cd $(RUST_BE_DIR) && \
sea-orm-cli generate entity \
--output-dir='src/model/entity' \
--database-url='postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST_PORT)/$(POSTGRES_DB)' \
@ -106,15 +110,15 @@ $(T)/regenerate-entities: $(MIGRATIONS)
sed -i "s/NAPI_EXTRA_ATTR_PLACEHOLDER/$${attribute}/" "$${file}"; \
done
sed -i 's/#\[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)\]/#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]\n#[napi_derive::napi]/' \
$(RUST_DIR)/src/model/entity/sea_orm_active_enums.rs
$(RUST_BE_DIR)/src/model/entity/sea_orm_active_enums.rs
touch $@
neko/index.js: $(RUSTY_STUFF)
neko/index.js: $(RUST_BE_SRC)
pnpm --filter='backend-rs' run build:debug
[ -f $(RUST_DIR)/built/index.js ]
[ -f $(RUST_BE_DIR)/built/index.js ]
rm neko/index.js
cp $(RUST_DIR)/built/index.js neko/index.js
cp $(RUST_BE_DIR)/built/index.js neko/index.js
.PHONY: build-image

View file

@ -14,3 +14,6 @@ if [ -d packages/backend/native-utils ]; then
rm --recursive --force packages/backend/native-utils/target
rmdir packages/backend/native-utils || :
fi
# create virtual workspace
rm --recursive --force packages/backend-rs/target

View file

@ -28,7 +28,7 @@
"build:debug": "pnpm clean && pnpm --filter backend-rs run build:debug && pnpm --filter firefish-js run build:debug && pnpm --filter firefish-js run build:types && pnpm --filter !firefish-js --filter !backend-rs -r --parallel run build:debug && pnpm run gulp",
"format": "pnpm -r --parallel run format",
"clean": "pnpm node ./scripts/clean-built.mjs",
"clean-cargo": "pnpm node ./scripts/clean-cargo.mjs",
"clean-cargo": "cargo clean",
"clean-npm": "pnpm node ./scripts/clean-npm.mjs",
"clean-all": "pnpm run clean && pnpm run clean-cargo && pnpm run clean-npm",
"cleanall": "pnpm run clean-all"

View file

@ -3,46 +3,38 @@ edition = "2021"
name = "backend-rs"
version = "0.0.0"
[features]
default = ["napi"]
napi = ["dep:napi-derive"]
[lib]
crate-type = ["cdylib", "lib"]
[dependencies]
async-trait = "0.1.77"
cfg-if = "1.0.0"
chrono = "0.4.33"
cuid2 = "0.1.2"
idna = "0.5.0"
jsonschema = "0.17.1"
once_cell = "1.19.0"
parse-display = "0.8.2"
rand = "0.8.5"
regex = "1.10.3"
schemars = { version = "0.8.16", features = ["chrono"] }
sea-orm = { version = "0.12.12", features = ["sqlx-postgres", "runtime-tokio-rustls"] }
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113"
serde_yaml = "0.9.31"
thiserror = "1.0.56"
tokio = { version = "1.35.1", features = ["full"] }
url = "2.5.0"
napi = { workspace = true, default-features = false, features = ["napi9", "tokio_rt", "chrono_date", "serde-json"] }
napi-derive = { workspace = true }
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.15.0", default-features = false, features = ["napi9", "tokio_rt", "chrono_date", "serde-json"] }
napi-derive = { version = "2.15.0", optional = true }
basen = "0.1.0"
urlencoding = "2.1.3"
argon2 = "0.5.3"
bcrypt = "0.15.0"
argon2 = { workspace = true }
async-trait = { workspace = true }
basen = { workspace = true }
bcrypt = { workspace = true }
cfg-if = { workspace = true }
chrono = { workspace = true }
cuid2 = { workspace = true }
idna = { workspace = true }
jsonschema = { workspace = true }
once_cell = { workspace = true }
parse-display = { workspace = true }
rand = { workspace = true }
regex = { workspace = true }
schemars = { workspace = true, features = ["chrono"] }
sea-orm = { workspace = true, features = ["sqlx-postgres", "runtime-tokio-rustls"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
url = { workspace = true }
urlencoding = { workspace = true }
[dev-dependencies]
pretty_assertions = "1.4.0"
pretty_assertions = { workspace = true }
[build-dependencies]
napi-build = "2.1.0"
[profile.release]
lto = true
napi-build = { workspace = true }

View file

@ -31,8 +31,8 @@
},
"scripts": {
"artifacts": "napi artifacts",
"build": "napi build --features napi --platform --release ./built/",
"build:debug": "napi build --features napi --platform ./built/",
"build": "napi build --platform --release ./built/",
"build:debug": "napi build --platform ./built/",
"prepublishOnly": "napi prepublish -t npm",
"universal": "napi universal",
"version": "napi version",

View file

@ -1,9 +1,7 @@
pub mod config;
pub mod database;
pub mod macros;
pub mod mastodon_api;
pub mod model;
pub mod prelude;
pub mod util;
// #[cfg(feature = "napi")]
pub mod mastodon_api;

View file

@ -1,7 +1,6 @@
#[macro_export]
macro_rules! impl_napi_error_from {
($a:ty) => {
#[cfg(feature = "napi")]
impl From<$a> for napi::Error {
fn from(reason: $a) -> napi::Error {
napi::Error::from_reason(reason.to_string())

View file

@ -1,12 +0,0 @@
import path, { join } from "node:path";
import { fileURLToPath } from "node:url";
import { execa } from "execa";
(async () => {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
execa("cargo", ["clean"], {
cwd: join(__dirname, "/../packages/backend-rs"),
stdio: "inherit",
});
})();