Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 9d8cf40b rédigé par Kubat's avatar Kubat
Parcourir les fichiers

RUST: Split the rust part of lektor into multiple modules

parent 792ead8f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 87 ajouts et 30 suppressions
...@@ -349,7 +349,7 @@ ExternalProject_Add(liblektor_rs ...@@ -349,7 +349,7 @@ ExternalProject_Add(liblektor_rs
SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/rust/liblektor-rs" SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/rust/liblektor-rs"
BUILD_COMMAND ${RUST_BUILD_CMD} BUILD_COMMAND ${RUST_BUILD_CMD}
COMMAND ${RUST_BUILD_CMD} COMMAND ${RUST_BUILD_CMD}
BUILD_BYPRODUCTS "${CMAKE_SOURCE_DIR}/src/rust/target/${RUST_BUILD_TYPE}/liblektor_rs.a" BUILD_BYPRODUCTS "${CMAKE_SOURCE_DIR}/src/rust/target/${RUST_BUILD_TYPE}/liblektor_unsafe.a"
BUILD_ALWAYS 1 BUILD_ALWAYS 1
BUILD_IN_SOURCE 1 BUILD_IN_SOURCE 1
) )
...@@ -358,7 +358,7 @@ add_dependencies(lektord liblektor_rs) ...@@ -358,7 +358,7 @@ add_dependencies(lektord liblektor_rs)
target_link_libraries(lektord target_link_libraries(lektord
PRIVATE PRIVATE
"${CMAKE_SOURCE_DIR}/src/rust/target/${RUST_BUILD_TYPE}/liblektor_rs.a" "${CMAKE_SOURCE_DIR}/src/rust/target/${RUST_BUILD_TYPE}/liblektor_unsafe.a"
${MPV_LIBRARY} ${MPV_LIBRARY}
${CMAKE_DL_LIBS} ${CMAKE_DL_LIBS}
${SQLITE3_LIBRARY} ${SQLITE3_LIBRARY}
......
...@@ -68,6 +68,14 @@ the correct sqlite support on your system: ...@@ -68,6 +68,14 @@ the correct sqlite support on your system:
cargo install diesel_cli --no-default-features --features sqlite cargo install diesel_cli --no-default-features --features sqlite
``` ```
To visualize dependencies of the rust part of lektor, you can write the
following commands from the root of each rust workspaces:
```sh
cargo install cargo-depgraph
cargo depgraph --all-deps --dedup-transitive-deps | dot -Tpng > dependencies.png
```
### Building instructions ### Building instructions
The manual way of installing and setting up lektor: The manual way of installing and setting up lektor:
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
"json.format.enable": true, "json.format.enable": true,
"rust-analyzer.checkOnSave.command": "clippy", "rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.inlayHints.parameterHints.enable": false, "rust-analyzer.inlayHints.parameterHints.enable": false,
"rust-analyzer.procMacro.attributes.enable": true "rust-analyzer.diagnostics.enable": true,
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.procMacro.attributes.enable": true,
} }
} }
\ No newline at end of file
[package] [workspace]
name = "lektor-rs" resolver = "2"
version = "0.1.0" members = [
edition = "2021" "lektor_c_compat",
"lektor_db",
"lektor_repo",
"lektor_unsafe",
"kurisu_api",
]
[lib] [workspace.package]
crate-type = ["staticlib"] edition = "2021"
authors = ["Maël MARTIN"]
version = "0.1.0"
license = "MIT"
[dependencies] [workspace.dependencies]
log = "0.4" log = "0.4"
libc = "0.2.0" libc = "0.2.0"
diesel_migrations = "2" diesel_migrations = "2"
......
src/rust/liblektor-rs/dependencies.png

1020 ko

[package]
name = "kurisu_api"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
[dependencies]
log.workspace = true
serde.workspace = true
[package]
name = "lektor_c_compat"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
[dependencies]
log.workspace = true
libc.workspace = true
pub const LEKTOR_TAG_MAX: usize = 256; //! Types defined in the C part of the project. Don't use them from safe C code,
//! only use the safe wrappers.
pub struct LktQueue; pub struct LktQueue;
pub struct LktDb; pub struct LktDb;
......
//! Defines functions and types that matches the one defined in the C part of
//! the lektor source code.
//!
//! From safe rust code you *must not* use the types defined in the [c_types]
//! module.
pub mod c_types;
pub use libc::{c_char, c_int, c_long, c_void, size_t};
/// The maximal length of a tag in lektor.
pub const LEKTOR_TAG_MAX: usize = 256;
[package]
name = "lektor_db"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
[dependencies]
log.workspace = true
serde.workspace = true
diesel_migrations = "2"
diesel = { version = "2", default-features = false, features = ["sqlite"] }
kurisu_api = { path = "../kurisu_api" }
...@@ -34,7 +34,7 @@ fn main() { ...@@ -34,7 +34,7 @@ fn main() {
.canonicalize() .canonicalize()
.expect("failed to canonicalize OUT_DIR"); .expect("failed to canonicalize OUT_DIR");
let source_dir = out_dir let source_dir = out_dir
.join("../../../../../liblektor-rs") .join("../../../../../liblektor-rs/lektor_db")
.canonicalize() .canonicalize()
.expect("failed to canonicalize the source path"); .expect("failed to canonicalize the source path");
let migration_dir = source_dir let migration_dir = source_dir
......
use super::{ use crate::{
models::*,
queue::{LktDatabasePriority, LktDatabaseQueueRangeIter}, queue::{LktDatabasePriority, LktDatabaseQueueRangeIter},
*, *,
}; };
use crate::{database::models::*, kurisu_api::v1 as api_v1}; use kurisu_api::v1 as api_v1;
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
/// The migrations!
const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
/// Run migrations in a connexion!
fn run_migration(conn: &mut SqliteConnection) -> Result<(), String> {
conn.run_pending_migrations(MIGRATIONS)
.map_err(|err| err.to_string())
.map(|_| ())
}
/// Create a connexion to a database and run automatically the migrations. /// Create a connexion to a database and run automatically the migrations.
fn establish_connection(path: impl AsRef<str>) -> Result<SqliteConnection, String> { fn establish_connection(path: impl AsRef<str>) -> Result<SqliteConnection, String> {
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
let mut conn = SqliteConnection::establish(path.as_ref()) let mut conn = SqliteConnection::establish(path.as_ref())
.map_err(|err| format!("error connecting to {}: {}", path.as_ref(), err))?; .map_err(|err| format!("error connecting to {}: {}", path.as_ref(), err))?;
self::run_migration(&mut conn)?; conn.run_pending_migrations(MIGRATIONS)
.map_err(|err| err.to_string())?;
Ok(conn) Ok(conn)
} }
...@@ -32,7 +25,9 @@ pub struct LktDatabaseConnection { ...@@ -32,7 +25,9 @@ pub struct LktDatabaseConnection {
/// expression... /// expression...
macro_rules! with_dsl { macro_rules! with_dsl {
($table: ident => $expr: expr) => {{ ($table: ident => $expr: expr) => {{
#[allow(unused_imports)]
use self::schema::$table::dsl::*; use self::schema::$table::dsl::*;
#[allow(unused_imports)]
use diesel::dsl::*; use diesel::dsl::*;
$expr $expr
}}; }};
......
use super::*;
pub enum LktDatabaseError { pub enum LktDatabaseError {
DieselConnection(diesel::ConnectionError), DieselConnection(diesel::ConnectionError),
DieselResult(diesel::result::Error), DieselResult(diesel::result::Error),
......
...@@ -5,11 +5,9 @@ pub mod error; ...@@ -5,11 +5,9 @@ pub mod error;
pub mod models; pub mod models;
pub mod queue; pub mod queue;
pub mod schema; pub mod schema;
pub mod unsafe_interface;
pub(self) use diesel::prelude::*; pub(self) use diesel::prelude::*;
pub(self) use error::*; pub(self) use error::*;
pub(self) use log::*;
pub(self) use std::{ pub(self) use std::{
collections::VecDeque, collections::VecDeque,
ops::{Index, Range}, ops::{Index, Range},
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter