Skip to content

Conversation

@kubaplas
Copy link
Contributor

@kubaplas kubaplas commented Oct 30, 2025

Summary by CodeRabbit

  • Chores

    • Updated build templates to target multiple compilation environments with adjusted entry-point behavior.
    • Expanded crate lint allowances to reduce build warnings across templates.
  • Refactor

    • Simplified CLI container/deployer APIs: removed an optional package-name parameter in common paths and introduced explicit "named" variants; example usages were updated accordingly.

@kubaplas kubaplas requested a review from kpob October 30, 2025 15:03
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Walkthrough

Refactors template build entrypoints to apply no_main only for wasm32 and add non-wasm fallback main() stubs; expands lint allows and tightens cfg guards in schema-build templates to consider odra_module and target_arch; updates odra-cli container and deployer APIs to introduce named contract variants and remove package_name from the simple deploy path.

Changes

Cohort / File(s) Summary
Template build_contract.rs files
templates/blank/bin/build_contract.rs, templates/cep18/bin/build_contract.rs, templates/cep95/bin/build_contract.rs, templates/full/bin/build_contract.rs, templates/workspace/flapper/bin/build_contract.rs, templates/workspace/flipper/bin/build_contract.rs
Replace unconditional #![no_main] with #![cfg_attr(target_arch = "wasm32", no_main)] (or equivalent #[cfg_attr(..., no_main)]) and add #[cfg(not(target_arch = "wasm32"))] fn main() {} fallback for non-wasm targets.
Template build_schema.rs files
templates/blank/bin/build_schema.rs, templates/cep18/bin/build_schema.rs, templates/cep95/bin/build_schema.rs, templates/full/bin/build_schema.rs, templates/workspace/flapper/bin/build_schema.rs, templates/workspace/flipper/bin/build_schema.rs
Add crate-level allows: redundant_imports and clippy::single_component_path_imports; change cfg guards from cfg(not(target_arch = "wasm32")) to cfg(all(not(odra_module = ""), not(target_arch = "wasm32"))) for the extern block and schema main; add fallback empty main() under cfg(any(odra_module = "", target_arch = "wasm32")).
Examples
examples/bin/odra_cli.rs
Update call sites to match new odra-cli API: remove the optional package_name argument from DogContract::load_or_deploy and remove the package_name argument from DeployedContractsContainer::contract_ref calls.
odra-cli: container API
odra-cli/src/container.rs
Add trait methods contract_ref(env) and contract_ref_named(env, name); rename add_contractadd_contract_named(contract, package_name) and add convenience add_contract(contract) delegating to named variant; update DeployedContractsContainer impl accordingly.
odra-cli: deployer utils
odra-cli/src/utils.rs
Remove package_name parameter from load_or_deploy; use contract_ref and add_contract in the simple path; use contract_ref_named and add_contract_named in the cfg-enabled path (load_or_deploy_with_cfg), updating call sites accordingly.

Sequence Diagram(s)

sequenceDiagram
  participant Deployer as DeployerExt
  participant Container as DeployedContractsContainer
  participant Contract as HostContract (deployed)

  Note over Deployer,Container: Simple path (no package_name)
  Deployer->>Container: contract_ref::<Contract>(env)
  alt contract exists
    Container-->>Deployer: Ok(HostRef)
  else not found
    Deployer->>Deployer: try_deploy(...) -> contract
    Deployer->>Container: add_contract(&contract)
    Container-->>Deployer: Ok(())
    Deployer-->>Deployer: return HostRef
  end

  Note over Deployer,Container: CFG-enabled path (named package)
  Deployer->>Container: contract_ref_named::<Contract>(env, package_name)
  alt contract exists
    Container-->>Deployer: Ok(HostRef)
  else not found
    Deployer->>Deployer: try_deploy_with_cfg(...) -> contract
    Deployer->>Container: add_contract_named(&contract, package_name)
    Container-->>Deployer: Ok(())
    Deployer-->>Deployer: return HostRef
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Attention areas:
    • Correctness of cfg expressions involving odra_module and target_arch across all schema templates.
    • API surface changes in odra-cli: trait method signatures, renames (add_contract_named), and updated call sites in utils and examples.
    • Ensure no duplicate symbol or link errors for host vs wasm builds due to added fallback mains.
    • Tests/examples that exercise deploy/load flows may need verification.

Possibly related PRs

Suggested reviewers

  • zie1ony

Poem

🐇 In templates I hop and I bind,
wasm wears no_main, hosts keep a mind.
Containers now know named from plain,
deployers skip a package name.
A little rabbit cheers the compile line!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Updated templates' bins to fix compilation errors" is directly related to the primary changes in this pull request. The vast majority of modifications across multiple template directories target build_contract.rs and build_schema.rs files with conditional compilation updates (wasm32-specific no_main attributes, fallback main functions, and adjusted cfg guards) that resolve compilation issues across different build targets. The title accurately captures the core objective at an appropriate level of abstraction. While there are also secondary API changes in odra-cli that support these template fixes, the title reasonably summarizes the main focus of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/templates-bins

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05c77ab and b1fb1f9.

📒 Files selected for processing (3)
  • examples/bin/odra_cli.rs (1 hunks)
  • odra-cli/src/container.rs (3 hunks)
  • odra-cli/src/utils.rs (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
odra-cli/src/utils.rs (3)
odra-cli/src/cli.rs (1)
  • contract (82-93)
odra-cli/src/cmd/contract.rs (1)
  • Self (81-81)
examples/bin/odra_cli.rs (1)
  • container (50-50)
odra-cli/src/container.rs (4)
core/src/host.rs (1)
  • env (33-33)
odra-cli/src/cmd/contract.rs (3)
  • T (89-93)
  • add_contract_named (23-31)
  • add_contract (33-37)
odra-cli/src/cmd/events.rs (2)
  • add_contract_named (39-42)
  • add_contract (34-37)
odra-cli/src/cli.rs (1)
  • contract (82-93)
🔇 Additional comments (3)
examples/bin/odra_cli.rs (1)

50-50: Aligned with the new container API

Calling contract_ref::<DogContract>(env) matches the updated helper that defaults the package context and keeps the scenario clean. Looks good.

odra-cli/src/utils.rs (1)

28-39: Refactor keeps load/deploy behavior intact

Switching to contract_ref/add_contract in the simple path and the named variants in the cfg path cleanly mirrors the container changes without altering semantics. Nice simplification.

Also applies to: 53-66

odra-cli/src/container.rs (1)

102-115: Convenience wrappers look solid

The new contract_ref/add_contract shims defer cleanly to the named implementations, so existing named flows keep working while unnamed lookups get a simpler call site. Nicely done.

Also applies to: 169-195


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
templates/full/bin/build_schema.rs (1)

2-3: Broad lint allowances for templates.

Allowing unused_imports, redundant_imports, and clippy::single_component_path_imports is reasonable for template code where generated projects may have varying import needs. However, these suppressions prevent detection of actual import hygiene issues.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 71024eb and 05c77ab.

📒 Files selected for processing (12)
  • templates/blank/bin/build_contract.rs (1 hunks)
  • templates/blank/bin/build_schema.rs (1 hunks)
  • templates/cep18/bin/build_contract.rs (1 hunks)
  • templates/cep18/bin/build_schema.rs (1 hunks)
  • templates/cep95/bin/build_contract.rs (1 hunks)
  • templates/cep95/bin/build_schema.rs (1 hunks)
  • templates/full/bin/build_contract.rs (1 hunks)
  • templates/full/bin/build_schema.rs (1 hunks)
  • templates/workspace/flapper/bin/build_contract.rs (1 hunks)
  • templates/workspace/flapper/bin/build_schema.rs (1 hunks)
  • templates/workspace/flipper/bin/build_contract.rs (1 hunks)
  • templates/workspace/flipper/bin/build_schema.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (12)
templates/workspace/flapper/bin/build_contract.rs (5)
templates/blank/bin/build_contract.rs (1)
  • main (8-8)
templates/cep18/bin/build_contract.rs (1)
  • main (8-8)
templates/cep95/bin/build_contract.rs (1)
  • main (8-8)
templates/full/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flipper/bin/build_contract.rs (1)
  • main (8-8)
templates/cep18/bin/build_schema.rs (2)
odra-macros/src/utils/attr.rs (1)
  • odra_module (11-13)
odra-build/src/lib.rs (1)
  • schema (10-21)
templates/blank/bin/build_contract.rs (5)
templates/cep18/bin/build_contract.rs (1)
  • main (8-8)
templates/cep95/bin/build_contract.rs (1)
  • main (8-8)
templates/full/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flapper/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flipper/bin/build_contract.rs (1)
  • main (8-8)
templates/cep18/bin/build_contract.rs (5)
templates/blank/bin/build_contract.rs (1)
  • main (8-8)
templates/cep95/bin/build_contract.rs (1)
  • main (8-8)
templates/full/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flapper/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flipper/bin/build_contract.rs (1)
  • main (8-8)
templates/full/bin/build_contract.rs (5)
templates/blank/bin/build_contract.rs (1)
  • main (8-8)
templates/cep18/bin/build_contract.rs (1)
  • main (8-8)
templates/cep95/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flapper/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flipper/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flapper/bin/build_schema.rs (2)
odra-macros/src/utils/attr.rs (1)
  • odra_module (11-13)
odra-build/src/lib.rs (1)
  • schema (10-21)
templates/workspace/flipper/bin/build_contract.rs (5)
templates/blank/bin/build_contract.rs (1)
  • main (8-8)
templates/cep18/bin/build_contract.rs (1)
  • main (8-8)
templates/cep95/bin/build_contract.rs (1)
  • main (8-8)
templates/full/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flapper/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flipper/bin/build_schema.rs (2)
odra-macros/src/utils/attr.rs (1)
  • odra_module (11-13)
odra-build/src/lib.rs (1)
  • schema (10-21)
templates/blank/bin/build_schema.rs (5)
odra-macros/src/utils/attr.rs (1)
  • odra_module (11-13)
templates/cep18/bin/build_schema.rs (4)
  • module_schema (8-8)
  • casper_contract_schema (9-9)
  • main (13-17)
  • main (20-20)
modules/bin/build_schema.rs (2)
  • module_schema (7-7)
  • casper_contract_schema (8-8)
examples/bin/build_schema.rs (3)
  • module_schema (7-7)
  • casper_contract_schema (8-8)
  • main (12-16)
odra-build/src/lib.rs (1)
  • schema (10-21)
templates/full/bin/build_schema.rs (4)
odra-macros/src/utils/attr.rs (1)
  • odra_module (11-13)
templates/blank/bin/build_schema.rs (4)
  • module_schema (8-8)
  • casper_contract_schema (9-9)
  • main (13-17)
  • main (20-20)
modules/bin/build_schema.rs (2)
  • module_schema (7-7)
  • casper_contract_schema (8-8)
odra-build/src/lib.rs (1)
  • schema (10-21)
templates/cep95/bin/build_contract.rs (6)
templates/blank/bin/build_contract.rs (1)
  • main (8-8)
templates/cep18/bin/build_contract.rs (1)
  • main (8-8)
templates/cep95/bin/build_schema.rs (2)
  • main (13-17)
  • main (20-20)
templates/full/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flapper/bin/build_contract.rs (1)
  • main (8-8)
templates/workspace/flipper/bin/build_contract.rs (1)
  • main (8-8)
templates/cep95/bin/build_schema.rs (2)
odra-macros/src/utils/attr.rs (1)
  • odra_module (11-13)
templates/blank/bin/build_schema.rs (4)
  • module_schema (8-8)
  • casper_contract_schema (9-9)
  • main (13-17)
  • main (20-20)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Evaluate benchmark
  • GitHub Check: Test templates
  • GitHub Check: Test
  • GitHub Check: Calculate test coverage
🔇 Additional comments (13)
templates/workspace/flapper/bin/build_contract.rs (1)

3-8: Conditional entry point fix looks good.
no_main now only applies on wasm32 and the stub main() keeps host builds happy, so this bin compiles cleanly across targets.

templates/cep95/bin/build_contract.rs (1)

3-8: Template bin configuration is ready.
Target-specific no_main plus the guarded empty main() resolve the cross-target build failures for this template.

templates/full/bin/build_contract.rs (1)

3-8: Full template binary looks good.
The selective no_main and host-only stub entry point bring this bin in line with the fixed compilation flow.

templates/blank/bin/build_contract.rs (1)

3-8: Blank template bin verified.
The wasm-only no_main and fallback main() maintain compatibility across targets.

templates/cep18/bin/build_contract.rs (1)

3-8: CEP18 contract bin ready.
The cfg-guarded entry points match the intended cross-target behavior.

templates/workspace/flipper/bin/build_contract.rs (1)

3-8: Workspace flipper bin looks solid.
Applying no_main only on wasm32 and adding the host stub entry point fixes the prior compilation gap.

templates/cep95/bin/build_schema.rs (1)

2-20: CFG split resolves schema build edge cases.
Gating the externs and real main() on non-empty odra_module plus non-wasm32 avoids undefined symbol/linker issues, while the fallback noop main() keeps alternative configs compiling.

templates/workspace/flapper/bin/build_schema.rs (1)

2-20: Workspace schema builder configuration is on point.
The tightened cfg conditions plus fallback entry point ensure schema generation only runs where supported and still compiles under wasm or empty-module setups.

templates/cep18/bin/build_schema.rs (2)

2-3: Lint allowances match other templates.

Consistent with templates/full/bin/build_schema.rs - these broad allowances are acceptable for template code.


6-20: Cfg conditions correctly implemented.

The conditional compilation logic matches the pattern established in other template files and properly ensures a main() function exists in all build configurations.

templates/blank/bin/build_schema.rs (1)

2-20: Changes consistent with other templates.

The lint allowances and cfg conditions match the pattern in templates/full/bin/build_schema.rs and templates/cep18/bin/build_schema.rs. This consistency across templates is good for maintainability.

templates/workspace/flipper/bin/build_schema.rs (1)

2-20: Workspace template correctly updated.

The changes mirror those in other templates but use the concrete crate name flipper (line 4) instead of a placeholder, which is appropriate for a workspace example template.

templates/full/bin/build_schema.rs (1)

6-20: Cfg logic verified as correct and exhaustive.

The verification confirms that odra_module behavior is consistent when unset versus set to empty string—both result in identical cfg behavior since odra-build/src/lib.rs defaults unset ODRA_MODULE to "". The conditions are mutually exclusive and exhaustive across all build scenarios (all build_schema.rs files across templates and workspace projects implement the same proven pattern).

Copy link

@llamapreview llamapreview bot left a comment

Choose a reason for hiding this comment

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

AI Code Review by LlamaPReview

🎯 TL;DR & Recommendation

Recommendation: Approve with suggestions

This PR fixes compilation errors in template binaries but introduces minor suggestions for improving maintainability and reducing potential confusion in build configurations.

🌟 Strengths

  • Resolves compilation errors across multiple contract templates.
  • Enhances build configurations for better cross-platform support.
Priority File Category Impact Summary Anchors
P2 templates/blank/bin/build_schema.rs Architecture Build fragility from conditional compilation dependency
P2 templates/blank/bin/build_schema.rs Maintainability Unsafe blocks risking undefined behavior
P2 templates/blank/bin/build_contract.rs Architecture Confusion from dual compilation targets
P2 templates/blank/bin/build_schema.rs Maintainability Lint suppressions hiding code smells

🔍 Notable Themes

  • Consistent use of conditional compilation across templates that could benefit from centralized configuration management.
  • Opportunities to replace unsafe code with safer alternatives and improve lint handling.

💡 Have feedback? We'd love to hear it in our GitHub Discussions.
✨ This review was generated by LlamaPReview Advanced, which is free for all open-source projects. Learn more.

Comment on lines +12 to 17
#[cfg(all(not(odra_module = ""), not(target_arch = "wasm32")))]
fn main() {
odra_build::schema(unsafe { crate::module_schema() }, unsafe {
crate::casper_contract_schema()
});
}
Copy link

Choose a reason for hiding this comment

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

P2 | Confidence: High

The unsafe blocks for accessing module_schema() and casper_contract_schema() functions are unnecessary and introduce potential undefined behavior risks. Since these are extern "Rust" functions declared in the same compilation unit, they should be called directly without unsafe blocks. The current implementation suggests a misunderstanding of Rust's unsafe semantics.

Suggested change
#[cfg(all(not(odra_module = ""), not(target_arch = "wasm32")))]
fn main() {
odra_build::schema(unsafe { crate::module_schema() }, unsafe {
crate::casper_contract_schema()
});
}
#[cfg(all(not(odra_module = ""), not(target_arch = "wasm32")))]
fn main() {
odra_build::schema(module_schema(), casper_contract_schema());
}

#![doc = "Binary for building wasm files from odra contracts."]
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "wasm32", no_main)]
Copy link

Choose a reason for hiding this comment

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

P2 | Confidence: High

The dual compilation target approach (WASM vs native) is architecturally sound but creates potential confusion. The empty main() function for native targets serves as a placeholder but provides no meaningful functionality or documentation about its purpose. This could lead to maintenance confusion about why these binaries exist for native compilation.

Suggested change
#![cfg_attr(target_arch = "wasm32", no_main)]
#[cfg(not(target_arch = "wasm32"))]
fn main() {
// Placeholder for native compilation - actual contract logic is WASM-only
}

Comment on lines +2 to +3
#![allow(unused_imports, redundant_imports)]
#![allow(clippy::single_component_path_imports)]
Copy link

Choose a reason for hiding this comment

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

P2 | Confidence: High

The blanket allowance of lints (redundant_imports, single_component_path_imports) suppresses legitimate warnings that could help maintain code quality. While this may reduce build noise, it hides potential code smells and reduces the compiler's ability to catch actual issues during development.

Comment on lines +6 to 10
#[cfg(all(not(odra_module = ""), not(target_arch = "wasm32")))]
extern "Rust" {
fn module_schema() -> odra::contract_def::ContractBlueprint;
fn casper_contract_schema() -> odra::schema::casper_contract_schema::ContractSchema;
}
Copy link

Choose a reason for hiding this comment

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

P2 | Confidence: Medium

Speculative: The conditional compilation using odra_module environment variable creates potential build-time fragility. This introduces a dependency on external build configuration that may not be consistently set across different development environments or CI/CD pipelines. The condition not(odra_module = "") relies on specific build tooling to define this variable, which could lead to inconsistent behavior between local development and production builds.

@kubaplas kubaplas merged commit c247e27 into release/2.4.1 Oct 31, 2025
5 checks passed
@kubaplas kubaplas deleted the bugfix/templates-bins branch October 31, 2025 12:46
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.

3 participants