chore: Turn project structure into workspace

This commit is contained in:
Lucas Schwiderski 2022-11-18 10:44:01 +01:00
parent d500b01709
commit 987a6ade9b
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8
31 changed files with 124 additions and 57 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "lib/serde_sjson"]
path = lib/serde_sjson
url = git@git.sclu1034.dev:lucas/serde_sjson.git

29
Cargo.lock generated
View file

@ -190,7 +190,9 @@ dependencies = [
"libloading",
"nanorand",
"pin-project-lite",
"sdk",
"serde",
"serde_sjson",
"tempfile",
"tokio",
"tokio-stream",
@ -589,6 +591,26 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "sdk"
version = "0.1.0"
dependencies = [
"color-eyre",
"csv-async",
"futures",
"futures-util",
"glob",
"libloading",
"nanorand",
"pin-project-lite",
"serde",
"serde_sjson",
"tokio",
"tokio-stream",
"tracing",
"tracing-error",
]
[[package]]
name = "serde"
version = "1.0.147"
@ -609,6 +631,13 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_sjson"
version = "0.1.0"
dependencies = [
"serde",
]
[[package]]
name = "sharded-slab"
version = "0.1.4"

View file

@ -1,27 +1,6 @@
[package]
name = "dtmt"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.0.15", features = ["color", "derive", "std", "cargo", "unicode"] }
color-eyre = "0.6.2"
csv-async = { version = "1.2.4", features = ["tokio", "serde"] }
futures = "0.3.25"
futures-util = "0.3.24"
glob = "0.3.0"
libloading = "0.7.4"
nanorand = "0.7.0"
pin-project-lite = "0.2.9"
serde = { version = "1.0.147", features = ["derive"] }
tokio = { version = "1.21.2", features = ["rt-multi-thread", "fs", "process", "macros", "tracing", "io-util", "io-std"] }
tokio-stream = { version = "0.1.11", features = ["fs", "io-util"] }
tracing = { version = "0.1.37", features = ["async-await"] }
tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
[dev-dependencies]
tempfile = "3.3.0"
[workspace]
resolver = "2"
members = ["crates/*", "lib/*"]
[profile.release]
strip = "debuginfo"

26
crates/dtmt/Cargo.toml Normal file
View file

@ -0,0 +1,26 @@
[package]
name = "dtmt"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.0.15", features = ["color", "derive", "std", "cargo", "unicode"] }
color-eyre = "0.6.2"
csv-async = { version = "1.2.4", features = ["tokio", "serde"] }
sdk = { path = "../../lib/sdk", version = "0.1.0" }
futures = "0.3.25"
futures-util = "0.3.24"
glob = "0.3.0"
libloading = "0.7.4"
nanorand = "0.7.0"
pin-project-lite = "0.2.9"
serde = { version = "1.0.147", features = ["derive"] }
serde_sjson = { path = "../../lib/serde_sjson", version = "0.1.0" }
tokio = { version = "1.21.2", features = ["rt-multi-thread", "fs", "process", "macros", "tracing", "io-util", "io-std"] }
tokio-stream = { version = "0.1.11", features = ["fs", "io-util"] }
tracing = { version = "0.1.37", features = ["async-await"] }
tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
[dev-dependencies]
tempfile = "3.3.0"

View file

@ -19,6 +19,6 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(_ctx: Arc<RwLock<dtmt::Context>>, _matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(_ctx: Arc<RwLock<sdk::Context>>, _matches: &ArgMatches) -> Result<()> {
unimplemented!()
}

View file

@ -5,8 +5,8 @@ use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
use color_eyre::eyre::{self, Result};
use color_eyre::{Help, SectionExt};
use dtmt::decompress;
use futures::future::try_join_all;
use sdk::decompress;
use tokio::fs::{self, File};
use tokio::io::BufReader;
use tokio::sync::RwLock;
@ -44,7 +44,7 @@ pub(crate) fn command_definition() -> Command {
#[tracing::instrument(skip(ctx))]
async fn decompress_bundle<P1, P2>(
ctx: Arc<RwLock<dtmt::Context>>,
ctx: Arc<RwLock<sdk::Context>>,
bundle: P1,
destination: P2,
) -> Result<()>
@ -60,7 +60,7 @@ where
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(ctx: Arc<RwLock<dtmt::Context>>, matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(ctx: Arc<RwLock<sdk::Context>>, matches: &ArgMatches) -> Result<()> {
let bundles = matches
.get_many::<PathBuf>("bundle")
.unwrap_or_default()

View file

@ -6,9 +6,9 @@ use color_eyre::{
eyre::{self, Context, Result},
Help, Report, SectionExt,
};
use dtmt::Bundle;
use futures::future::try_join_all;
use glob::Pattern;
use sdk::Bundle;
use tokio::{fs, sync::RwLock};
use crate::cmd::util::collect_bundle_paths;
@ -117,7 +117,7 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(ctx: Arc<RwLock<dtmt::Context>>, matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(ctx: Arc<RwLock<sdk::Context>>, matches: &ArgMatches) -> Result<()> {
{
let ljd_bin = matches
.get_one::<String>("ljd")

View file

@ -5,7 +5,7 @@ use color_eyre::{
eyre::{self, Context, Result},
Help,
};
use dtmt::Bundle;
use sdk::Bundle;
use tokio::{fs::File, io::AsyncReadExt, sync::RwLock};
pub(crate) fn command_definition() -> Command {
@ -42,7 +42,7 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(ctx: Arc<RwLock<dtmt::Context>>, matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(ctx: Arc<RwLock<sdk::Context>>, matches: &ArgMatches) -> Result<()> {
let bundle_path = matches
.get_one::<PathBuf>("bundle")
.expect("required parameter not found");

View file

@ -4,8 +4,8 @@ use std::sync::Arc;
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
use color_eyre::eyre::{self, Result};
use color_eyre::{Help, SectionExt};
use dtmt::Bundle;
use futures::future::try_join_all;
use sdk::Bundle;
use tokio::sync::RwLock;
use crate::cmd::util::collect_bundle_paths;
@ -32,7 +32,7 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(ctx: Arc<RwLock<dtmt::Context>>, matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(ctx: Arc<RwLock<sdk::Context>>, matches: &ArgMatches) -> Result<()> {
let bundles = matches
.get_many::<PathBuf>("bundle")
.unwrap_or_default()

View file

@ -4,7 +4,7 @@ use clap::{Arg, ArgMatches, Command};
use color_eyre::eyre::Result;
use tokio::sync::RwLock;
use dtmt::Oodle;
use sdk::Oodle;
mod decompress;
mod extract;
@ -39,7 +39,7 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(ctx: Arc<RwLock<dtmt::Context>>, matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(ctx: Arc<RwLock<sdk::Context>>, matches: &ArgMatches) -> Result<()> {
if let Some(name) = matches.get_one::<String>("oodle") {
let oodle = Oodle::new(name)?;
let mut ctx = ctx.write().await;

View file

@ -1,16 +1,32 @@
use std::path::PathBuf;
use std::sync::Arc;
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command, ValueEnum};
use color_eyre::eyre::{Context, Result};
use color_eyre::{Help, SectionExt};
use dtmt::murmur::HashGroup;
use tokio::fs::File;
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::sync::RwLock;
use tokio_stream::wrappers::LinesStream;
use tokio_stream::StreamExt;
#[derive(Copy, Clone, PartialEq, ValueEnum)]
pub enum HashGroup {
Filename,
Filetype,
Other,
}
impl From<HashGroup> for sdk::murmur::HashGroup {
fn from(value: HashGroup) -> Self {
match value {
HashGroup::Filename => sdk::murmur::HashGroup::Filename,
HashGroup::Filetype => sdk::murmur::HashGroup::Filetype,
HashGroup::Other => sdk::murmur::HashGroup::Other,
}
}
}
pub(crate) fn command_definition() -> Command {
Command::new("dictionary")
.about("Manipulate a hash dictionary file.")
@ -59,7 +75,7 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(ctx: Arc<RwLock<dtmt::Context>>, matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(ctx: Arc<RwLock<sdk::Context>>, matches: &ArgMatches) -> Result<()> {
match matches.subcommand() {
Some(("lookup", sub_matches)) => {
let hash = sub_matches
@ -72,7 +88,7 @@ pub(crate) async fn run(ctx: Arc<RwLock<dtmt::Context>>, matches: &ArgMatches) -
let ctx = ctx.read().await;
for group in groups {
let value = ctx.lookup_hash(*hash, *group);
let value = ctx.lookup_hash(*hash, (*group).into());
println!("{}", value);
}
@ -98,7 +114,7 @@ pub(crate) async fn run(ctx: Arc<RwLock<dtmt::Context>>, matches: &ArgMatches) -
{
let mut ctx = ctx.write().await;
for line in lines.into_iter() {
ctx.lookup.add(line?, *group);
ctx.lookup.add(line?, (*group).into());
}
}

View file

@ -31,6 +31,6 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(_ctx: Arc<RwLock<dtmt::Context>>, _matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(_ctx: Arc<RwLock<sdk::Context>>, _matches: &ArgMatches) -> Result<()> {
unimplemented!()
}

View file

@ -17,6 +17,6 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(_ctx: Arc<RwLock<dtmt::Context>>, _matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(_ctx: Arc<RwLock<sdk::Context>>, _matches: &ArgMatches) -> Result<()> {
unimplemented!()
}

View file

@ -21,6 +21,6 @@ pub(crate) fn command_definition() -> Command {
}
#[tracing::instrument(skip_all)]
pub(crate) async fn run(_ctx: Arc<RwLock<dtmt::Context>>, _matches: &ArgMatches) -> Result<()> {
pub(crate) async fn run(_ctx: Arc<RwLock<sdk::Context>>, _matches: &ArgMatches) -> Result<()> {
unimplemented!()
}

View file

@ -65,7 +65,7 @@ async fn main() -> Result<()> {
.init();
}
let ctx = dtmt::Context::new();
let ctx = sdk::Context::new();
let ctx = Arc::new(RwLock::new(ctx));
{

20
lib/sdk/Cargo.toml Normal file
View file

@ -0,0 +1,20 @@
[package]
name = "sdk"
version = "0.1.0"
edition = "2021"
[dependencies]
color-eyre = "0.6.2"
csv-async = { version = "1.2.4", features = ["tokio", "serde"] }
futures = "0.3.25"
futures-util = "0.3.24"
glob = "0.3.0"
libloading = "0.7.4"
nanorand = "0.7.0"
pin-project-lite = "0.2.9"
serde = { version = "1.0.147", features = ["derive"] }
serde_sjson = { path = "../../lib/serde_sjson", version = "0.1.0" }
tokio = { version = "1.21.2", features = ["rt-multi-thread", "fs", "process", "macros", "tracing", "io-util", "io-std"] }
tokio-stream = { version = "0.1.11", features = ["fs", "io-util"] }
tracing = { version = "0.1.37", features = ["async-await"] }
tracing-error = "0.2.0"

View file

@ -1,4 +1,3 @@
use clap::ValueEnum;
use color_eyre::{eyre::Context, Help, Result, SectionExt};
use csv_async::{AsyncDeserializer, AsyncSerializer};
use serde::{Deserialize, Serialize};
@ -7,7 +6,7 @@ use tokio_stream::StreamExt;
use super::{murmurhash64, Murmur32, Murmur64, SEED};
#[derive(Copy, Clone, Deserialize, PartialEq, Serialize, ValueEnum)]
#[derive(Copy, Clone, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum HashGroup {
Filename,

View file

@ -1,8 +1,6 @@
#![allow(dead_code)]
use core::ffi::{c_char, c_int, c_size_t, c_ulonglong, c_void};
use clap::ValueEnum;
// Type definitions taken from Unreal Engine's `oodle2.h`
#[repr(C)]
@ -44,19 +42,18 @@ impl From<bool> for OodleLZ_CheckCRC {
#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Debug, ValueEnum)]
#[derive(Clone, Copy, Debug)]
pub enum OodleLZ_Verbosity {
None = 0,
Minimal = 1,
Some = 2,
Lots = 3,
#[clap(hide = true)]
Force32 = 0x40000000,
}
#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Debug, ValueEnum)]
#[derive(Clone, Copy, Debug)]
pub enum OodleLZ_Decode_ThreadPhase {
Phase1 = 1,
Phase2 = 2,
@ -69,9 +66,8 @@ impl OodleLZ_Decode_ThreadPhase {
#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Debug, ValueEnum)]
#[derive(Clone, Copy, Debug)]
pub enum OodleLZ_Compressor {
#[clap(hide = true)]
Invalid = -1,
// None = memcpy, pass through uncompressed bytes
None = 3,
@ -97,13 +93,12 @@ pub enum OodleLZ_Compressor {
Lzblw = 5,
Lza = 6,
Count = 14,
#[clap(hide = true)]
Force32 = 0x40000000,
}
#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Debug, ValueEnum)]
#[derive(Clone, Copy, Debug)]
pub enum OodleLZ_CompressionLevel {
// don't compress, just copy raw bytes
None = 0,
@ -133,7 +128,6 @@ pub enum OodleLZ_CompressionLevel {
HyperFast3 = -3,
// fastest, less compression
HyperFast4 = -4,
#[clap(hide = true)]
Force32 = 0x40000000,
}

1
lib/serde_sjson Submodule

@ -0,0 +1 @@
Subproject commit b53949d5df34f3407e09cdc21da426e64b976832