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

feat: production build #354

Open
wants to merge 5 commits into
base: fix/build-spec
Choose a base branch
from

Conversation

Daanvdplas
Copy link
Collaborator

@Daanvdplas Daanvdplas commented Nov 27, 2024

Adds the build profile to pop cli

use super::*;
use cli::MockCli;
use strum::VariantArray;

fn add_production_profile(project: &Path) -> anyhow::Result<()> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Happy to hear where I can place this function as it now exists in three places.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I had the same question in the pop call contract. The solution was to have a public function in the crate pop_contracts under a testing module that can be then used by the pop-cli https://github.com/r0gue-io/pop-cli/pull/306/files#diff-1735e49d7426a2bb8a539485425778554b43ef1ca455b26bd8138b69c69b18aeR27

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we see it can be used in contracts then Ale's suggestion is the best approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will be used for parachains and builds, not for smart contracts as far as I'm aware. However, I see no reason not to place it in common.

@AlexD10S your suggestion doesn't use any feature flag? This means it is added to the compilation time of the users which doesn't seem ideal. I suggest we come up with a feature name that we can start to use in the repository

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A random idea; we add it to the templates Cargo.toml files which makes it a public crate function in general. Adding it will make the pop cli users aware of this possibility and will improve their chain when they go live to production, through this we create awareness for builders, a win.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at what it is actually doing, https://github.com/r0gue-io/pop-cli/blob/main/crates/pop-common/src/manifest.rs might be the best candidate. It arguably should be improved to use the functionality available via the Manifest object - e.g. reading the manifest, checking if the profile already exists and adding if not.

Note: if it is moved to a library crate it should not use anyhow: https://github.com/dtolnay/anyhow?tab=readme-ov-file#comparison-to-thiserror.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a great suggestion, I will not add it to the templates as default, something we can consider in the future

@Daanvdplas Daanvdplas requested review from AlexD10S and al3mart and removed request for AlexD10S November 27, 2024 19:32
Copy link
Contributor

@al3mart al3mart left a comment

Choose a reason for hiding this comment

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

Way cleaner this way 👍 :

My biggest concern is that by removing the option --release it forces us to include a deprecation message, an alias or something or some warning in the release notes.

Looks good. Left a few nits.

pub(crate) release: bool,
/// Build profile [default: debug].
#[clap(long, value_enum)]
pub(crate) profile: Option<Profile>,
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -40,20 +38,20 @@ pub(crate) enum ChainType {
// A development chain that runs mainly on one node.
#[default]
#[strum(
serialize = "Development",
serialize = "development",
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs the capitalization. Otherwise the command seems to complete successfully.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't understand. I changed this so that the user doesn't have to write "Development" but "development"

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, so I'm not really familiar with the details of strum here.
But the reason of the failure is that the the node or spec builder requires this to be "Development". So the pain point is when this variant is serialized into the spec.

Although, even if we have serialize = "Development" users will be able to use --type development just fine. It's a bit confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

message = "Development",
detailed_message = "Meant for a development chain that runs mainly on one node."
)]
Development,
// A local chain that runs locally on multiple nodes for testing purposes.
#[strum(
serialize = "Local",
serialize = "local",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

message = "Local",
detailed_message = "Meant for a local chain that runs locally on multiple nodes for testing purposes."
)]
Local,
// A live chain.
#[strum(serialize = "Live", message = "Live", detailed_message = "Meant for a live chain.")]
#[strum(serialize = "live", message = "Live", detailed_message = "Meant for a live chain.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

@@ -28,9 +29,9 @@ pub(crate) struct BuildArgs {
/// The package to be built.
#[arg(short = 'p', long)]
pub(crate) package: Option<String>,
/// For production, always build in release mode to exclude debug features.
#[clap(short, long)]
pub(crate) release: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change.
Users that were running with pop build --release won't be able to just use this newer version. Imagine scripts.

We should consider a deprecation message and maybe an alias from --release to --profile=release during at least one more release of the CLI.

Copy link
Contributor

Choose a reason for hiding this comment

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

An alias is ideal - the build command should have some familarity with cargo, allowing -r, --release or --profile release

Copy link
Contributor

@evilrobot-01 evilrobot-01 Nov 28, 2024

Choose a reason for hiding this comment

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

It should not be deprecated in my view.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a bad idea to use the alias.
A suggestion would be to add the conflicts_with rule to prevent users from using both the --release and --profile=production flags at the same time.

#[clap(short, long, conflicts_with="profile")]
pub(crate) release: bool,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that it should not be deprecated for the normal build command and put it back in

Copy link
Collaborator

@AlexD10S AlexD10S left a comment

Choose a reason for hiding this comment

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

The only change requested is based on Ale's feedback about keeping the --release flag as deprecated.
Here’s how you can handle it:
1- Update the help message for the flag: https://github.com/r0gue-io/pop-cli/blob/main/crates/pop-cli/src/commands/test/contract.rs#L18
2- If the flag is used, display a warning to inform the user: https://github.com/r0gue-io/pop-cli/blob/main/crates/pop-cli/src/commands/test/contract.rs#L50
3- You can set the Profile to release if the flag was specified.

crates/pop-cli/src/commands/build/mod.rs Outdated Show resolved Hide resolved
Base automatically changed from daan/feat-use_chain_spec_file to fix/build-spec November 29, 2024 14:52
@al3mart
Copy link
Contributor

al3mart commented Nov 29, 2024

I'll do the rebase here

// All commands originating from root command are valid
BuildParachainCommand {
path: args.path,
package: args.package,
release: args.release,
profile: Some(profile),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Option requirement should be removed when removing the deprecated parachain build and contract command.

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.

4 participants