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

Allow embedding Lemmy, fix setup error #2618

Merged
merged 3 commits into from
Dec 19, 2022
Merged

Allow embedding Lemmy, fix setup error #2618

merged 3 commits into from
Dec 19, 2022

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented Dec 16, 2022

This moves the main.rs code into lib.rs, so that it can be included by other crates. I am using this in to test lemmyBB in LemmyNet/lemmyBB#70 so that no additional setup like bash scripts are needed. In the future I also plan to provide a production build variant of lemmyBB which embeds Lemmy, which will make installation easier (one less binary to install).

Additionally i noticed a bug during site setup, if none of the rate limit vars is set, diesel throws an error "There are no changes to save. This query cannot be built".

use std::{env, sync::Arc, thread, time::Duration};
use tracing_actix_web::TracingLogger;

pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out that this wasnt used at all, and we were already embedding migrations in db_schema crate.

Copy link
Member

Choose a reason for hiding this comment

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

Weird how rust didn't check the stuff in main, but I noticed that on my system too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Its because the item is marked as public, so Rust will never mark it as unused as it might be used by another crate. Unfortunately there is no way to change this logic, so there are probably more public unused items across Lemmy codebase. The only tool I found to detect unused code in workspaces gave only false positives.

src/lib.rs Outdated
const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);

/// Placing the main function in lib.rs allows other crates to import it and embed Lemmy
pub async fn main2() -> Result<(), LemmyError> {
Copy link
Member

@dessalines dessalines Dec 17, 2022

Choose a reason for hiding this comment

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

Maybe rename to something other than main2. Maybe like start, entry, run.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

use std::{env, sync::Arc, thread, time::Duration};
use tracing_actix_web::TracingLogger;

pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
Copy link
Member

Choose a reason for hiding this comment

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

Weird how rust didn't check the stuff in main, but I noticed that on my system too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants