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

Turn devenv into a library #1235

Merged
merged 1 commit into from
May 27, 2024
Merged

Turn devenv into a library #1235

merged 1 commit into from
May 27, 2024

Conversation

ankhers
Copy link
Contributor

@ankhers ankhers commented May 27, 2024

This is a small example of how to turn the devenv binary into both a library and a binary. The reason this works is that the devenv/Cargo.toml file would allow you to specify one or more binaries, and only a single library. However, because we are using the default values for everything, we do not need to explicitly define these sections. The library entry point will be devenv/src/lib.rs.

In the lib.rs file, we specify that we also want to use the log module. So we define and export this module. So now anything that imports the devenv package can just use devenv::log::* in order to access the pieces defined inside of that module.

There is a problem including the command module since main.rs defines an App struct, and then the command module defines an implementation of that struct. The problem here being that lib.rs does not define the App struct, so when the command module has use crate::App, it is not defined as it is in the case of the devenv binary.

This is a small example of how to turn the devenv binary into both a
library and a binary. The reason this works is that the
devenv/Cargo.toml file would allow you to specify one or more binaries,
and only a single library. However, because we are using the default
values for everything, we do not need to explicitly define these
sections. The library entry point will be devenv/src/lib.rs.

In the lib.rs file, we specify that we also want to use the log module.
So we define and export this module. So now anything that imports the
devenv package can just use devenv::log::* in order to access the pieces
defined inside of that module.

There is a problem including the command module since main.rs defines an
App struct, and then the command module defines an implementation of
that struct. The problem here being that lib.rs does not define the App
struct, so when the command module has use crate::App, it is not defined
as it is in the case of the devenv binary.
@domenkozar
Copy link
Member

I assume the next step is we split the cli stuff and App?

@ankhers
Copy link
Contributor Author

ankhers commented May 27, 2024 via email

@domenkozar domenkozar merged commit 60ed3db into cachix:main May 27, 2024
5 of 6 checks passed
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