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(sozo): support for feature flags #2112

Merged
merged 9 commits into from
Jul 10, 2024
Merged

feat(sozo): support for feature flags #2112

merged 9 commits into from
Jul 10, 2024

Conversation

lambda-0x
Copy link
Contributor

@lambda-0x lambda-0x commented Jun 27, 2024

Description

fix: #2010

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Introduced a new feature called 'something' with related functionality.
    • Added new modules and interfaces for handling 'something' feature.
    • Updated contract manifests to include new contracts and functionalities.
    • Added new configuration options in Scarb.toml.
  • Improvements

    • Enhanced compilation logic with better feature handling.
    • Updated workspace and package management for more efficient builds.
  • Bug Fixes

    • Fixed inconsistencies in the number of elements in manifest fields.

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 71.11111% with 13 lines in your changes missing coverage. Please review.

Project coverage is 68.00%. Comparing base (bbb355e) to head (ef87c32).

Files Patch % Lines
bin/sozo/src/commands/test.rs 0.00% 13 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2112   +/-   ##
=======================================
  Coverage   68.00%   68.00%           
=======================================
  Files         331      331           
  Lines       42697    42725   +28     
=======================================
+ Hits        29035    29057   +22     
- Misses      13662    13668    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

coderabbitai bot commented Jul 8, 2024

Walkthrough

The changes introduce support for conditional compilation features in the sozo project, enabling specific functionalities based on provided features. Key updates include new fields for feature specifications in build and test arguments, modifications in compilation logic to handle workspace and package details, and adjustments in test and example files to demonstrate the new feature capabilities.

Changes

Files/Directories Change Summary
bin/sozo/src/commands/build.rs, test.rs Introduced FeaturesSpec for feature specification, updated CompileOpts usage, and redefined BuildArgs.
crates/dojo-lang/src/compiler_test.rs Modified test functions to handle workspace and package details.
crates/dojo-lang/src/scarb_internal/mod.rs Updated compile_workspace function signature to include packages.
crates/dojo-test-utils/build.rs, src/compiler.rs Added logic to read workspace and collect package IDs before compilation.
crates/dojo-world/src/manifest/manifest_test.rs Increased the number of elements in the contracts field from 3 to 4.
examples/spawn-and-move/Scarb.toml Added feature sections and whitespace modifications.
examples/spawn-and-move/.../dojo_examples-actions*.json Added a new function call_something to the contract.
examples/spawn-and-move/.../dojo_examples-something*.json Introduced interfaces, structs, and implementations related to contracts and upgradability.
examples/spawn-and-move/.../manifest.json, manifest.toml Updated class_hash values and added new entities and functions.
examples/spawn-and-move/src/actions.cairo Implemented conditional compilation and new methods related to 'something'.
examples/spawn-and-move/src/lib.cairo, something.cairo Added new module and interface implementations under conditional compilation feature.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SozoBuild
    participant ScarbBuild
    participant Workspace
    participant ScarbCompile
    
    User->>SozoBuild: build with --features
    SozoBuild->>ScarbBuild: Pass features to scarb build
    ScarbBuild->>Workspace: Read workspace
    Workspace-->>ScarbBuild: Return workspace info
    ScarbBuild->>ScarbCompile: Compile with selected features
    ScarbCompile-->>ScarbBuild: Compilation result
    SozoBuild-->>User: Build finished
Loading

Assessment against linked issues

Objective (Issue #2010) Addressed Explanation
Support --features option
Forward --features option to scarb build
<FEATURES> can contain one or many features, separated by comma
Support optional features key in sozo profiles
Test with conditional compilation feature

Poem

In the realm of code so bright,
Features dance in Sozo's light,
Compile with ease, a joyful flight,
Conditional paths, shining white.
With each build, new heights we cite,
Scarb and Sozo, futures unite!
🐇✨🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lambda-0x
Copy link
Contributor Author

(rebased to main after scarb was updated)

@glihm glihm marked this pull request as ready for review July 9, 2024 22:03
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bbb355e and 5212064.

Files selected for processing (19)
  • bin/sozo/src/commands/build.rs (6 hunks)
  • bin/sozo/src/commands/test.rs (3 hunks)
  • crates/dojo-lang/src/compiler_test.rs (2 hunks)
  • crates/dojo-lang/src/scarb_internal/mod.rs (3 hunks)
  • crates/dojo-test-utils/build.rs (2 hunks)
  • crates/dojo-test-utils/src/compiler.rs (2 hunks)
  • crates/dojo-world/src/manifest/manifest_test.rs (1 hunks)
  • examples/spawn-and-move/Scarb.toml (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-actions-40b6994c.json (1 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-something-71cfad55.json (1 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/manifest.json (3 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/manifest.toml (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json (1 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-something-71cfad55.json (1 hunks)
  • examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-something-71cfad55.toml (1 hunks)
  • examples/spawn-and-move/src/actions.cairo (4 hunks)
  • examples/spawn-and-move/src/lib.cairo (1 hunks)
  • examples/spawn-and-move/src/something.cairo (1 hunks)
Files skipped from review due to trivial changes (3)
  • examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml
  • examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-something-71cfad55.toml
  • examples/spawn-and-move/src/lib.cairo
Additional comments not posted (40)
examples/spawn-and-move/src/something.cairo (2)

1-4: Trait definition looks good.

The ISomething trait is correctly defined with the dojo::interface attribute and a single function something.


6-11: Module and contract implementation look good.

The something module correctly uses the dojo::contract attribute and implements the ISomething trait. The something function is defined but currently empty.

crates/dojo-lang/src/compiler_test.rs (2)

16-17: Workspace reading and package ID collection look good.

The workspace is correctly read, and package IDs are collected before the compilation process.


27-27: Updated function call looks good.

The compile_workspace function call correctly includes the packages parameter.

examples/spawn-and-move/Scarb.toml (1)

18-20: Feature sections look good.

The [features] sections are correctly added, allowing conditional compilation based on the specified features.

crates/dojo-test-utils/build.rs (2)

56-57: Workspace reading and package ID collection look good.

The workspace is correctly read, and package IDs are collected before the compilation process.


67-67: Updated function call looks good.

The compile_workspace function call correctly includes the packages parameter.

examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-something-71cfad55.json (5)

3-6: LGTM! Implementation of ContractImpl

The ContractImpl correctly implements the dojo::contract::IContract interface.


8-23: LGTM! Definition of ByteArray struct

The ByteArray struct is correctly defined with appropriate members and types.


26-94: LGTM! Definition of IContract interface

The IContract interface is correctly defined with appropriate functions, inputs, outputs, and state mutability.


98-110: LGTM! Implementation of WorldProviderImpl and definition of IWorldDispatcher struct

The WorldProviderImpl correctly implements the dojo::world::IWorldProvider interface, and the IWorldDispatcher struct is correctly defined with a contract address member.


130-223: LGTM! Implementations and definitions related to dojo_examples::something module

The implementations (ISomethingImpl, IDojoInitImpl, and UpgradableImpl), interfaces, and events are correctly defined with appropriate functions, inputs, outputs, and state mutability.

examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-something-71cfad55.json (5)

3-6: LGTM! Implementation of ContractImpl

The ContractImpl correctly implements the dojo::contract::IContract interface.


8-23: LGTM! Definition of ByteArray struct

The ByteArray struct is correctly defined with appropriate members and types.


26-94: LGTM! Definition of IContract interface

The IContract interface is correctly defined with appropriate functions, inputs, outputs, and state mutability.


98-110: LGTM! Implementation of WorldProviderImpl and definition of IWorldDispatcher struct

The WorldProviderImpl correctly implements the dojo::world::IWorldProvider interface, and the IWorldDispatcher struct is correctly defined with a contract address member.


130-223: LGTM! Implementations and definitions related to dojo_examples::something module

The implementations (ISomethingImpl, IDojoInitImpl, and UpgradableImpl), interfaces, and events are correctly defined with appropriate functions, inputs, outputs, and state mutability.

bin/sozo/src/commands/test.rs (3)

17-19: LGTM! Importing FeaturesSpec

The import statement for FeaturesSpec is correctly added.


62-64: LGTM! Adding features field to TestArgs struct

The features field is correctly added to the TestArgs struct.


76-90: LGTM! Updating compilation unit generation logic

The logic for generating compilation units is correctly updated to consider features.

crates/dojo-lang/src/scarb_internal/mod.rs (3)

18-19: LGTM! Importing PackageId

The import statement for PackageId is correctly added.


86-90: LGTM! Updating compile_workspace function signature

The compile_workspace function signature is correctly updated to include a packages parameter.


Line range hint 94-108:
LGTM! Updating logic to filter compilation units based on packages

The logic for filtering compilation units is correctly updated to consider the packages.

examples/spawn-and-move/src/actions.cairo (4)

2-3: Conditional import for ContractAddress looks good.

The import statement is correctly conditionally included based on the feature flag something.


13-14: Conditional function call_something in IActions trait looks good.

The function is correctly conditionally included based on the feature flag something.


33-34: Conditional import for ISomethingDispatcher and ISomethingDispatcherTrait looks good.

The import statement is correctly conditionally included based on the feature flag something.


133-138: Conditional function call_something in ActionsImpl implementation looks good.

The function is correctly conditionally included based on the feature flag something and interacts with the ISomethingDispatcher.

examples/spawn-and-move/manifests/dev/deployment/manifest.toml (1)

73-86: New contract entry for dojo_examples-something looks good.

The entry includes relevant metadata and configuration details.

examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-actions-40b6994c.json (1)

299-310: New function call_something in dojo_examples::actions::IActions interface looks good.

The function includes the necessary inputs and state mutability.

examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json (1)

299-310: New function call_something in dojo_examples::actions::IActions interface looks good.

The function includes the necessary inputs and state mutability.

crates/dojo-test-utils/src/compiler.rs (2)

77-79: Verify workspace reading and package ID collection.

The added code reads the workspace and collects package IDs before compilation. Ensure this logic correctly integrates with the rest of the compilation process and handles potential errors.


91-91: Verify compile_workspace function call with new parameter.

The compile_workspace function call now includes the packages parameter. Ensure this change is correctly handled within the function and verify its impact on the compilation process.

bin/sozo/src/commands/build.rs (3)

44-46: Verify new features field in BuildArgs.

The new features field is added to the BuildArgs struct. Ensure this field is correctly defined and integrated, and verify its impact on the build arguments.


87-89: Verify compile_workspace function call with features parameter.

The compile_workspace function call now includes the features parameter. Ensure this change is correctly handled within the function and verify its impact on the compilation process.


160-173: Verify Default implementation for BuildArgs.

The Default implementation for BuildArgs now includes the features field. Ensure this implementation correctly initializes the new field and verify its impact on default build arguments.

crates/dojo-world/src/manifest/manifest_test.rs (1)

356-359: Verify updated number of elements in contracts field.

The number of elements in the contracts field has been updated from 3 to 4. Ensure this change correctly reflects the updated contract specifications and verify its impact on related tests.

examples/spawn-and-move/manifests/dev/deployment/manifest.json (4)

1133-1134: New Contract Entry Added.

A new DojoContract entry has been added with the necessary fields and ABI definitions.

Ensure that the address, class_hash, and original_class_hash are correct and match the deployed contract.


1434-1445: New Function Added to IActions Interface.

The function call_something has been added to the dojo_examples::actions::IActions interface with the appropriate input parameter and state mutability.

Ensure that the function implementation and usage are correctly integrated.


1991-1992: New Contract Entry Added.

A new DojoContract entry has been added with the necessary fields and ABI definitions.

Ensure that the address, class_hash, and original_class_hash are correct and match the deployed contract.


1993-2227: New Contract Entry Added.

A new DojoContract entry has been added with the necessary fields and ABI definitions.

Ensure that the address, class_hash, and original_class_hash are correct and match the deployed contract.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5212064 and 7ad24c5.

Files selected for processing (1)
  • bin/sozo/tests/test_migrate.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • bin/sozo/tests/test_migrate.rs

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7ad24c5 and ef87c32.

Files selected for processing (10)
  • bin/sozo/tests/test_migrate.rs (1 hunks)
  • examples/spawn-and-move/Scarb.toml (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-something-71cfad55.json (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-something-71cfad55.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json (1 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-something-71cfad55.json (1 hunks)
  • examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-something-71cfad55.toml (1 hunks)
Files skipped from review due to trivial changes (3)
  • examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml
  • examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-something-71cfad55.toml
  • examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-something-71cfad55.toml
Files skipped from review as they are similar to previous changes (4)
  • bin/sozo/tests/test_migrate.rs
  • examples/spawn-and-move/Scarb.toml
  • examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-something-71cfad55.json
  • examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml
Additional comments not posted (3)
examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-something-71cfad55.json (1)

130-144: New implementation and interface for ISomething look correct.

The new ISomethingImpl and ISomething are consistent with existing structures and naming conventions.

examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json (1)

301-310: New function call_something in IActions looks correct.

The new call_something function is consistent with existing structures and naming conventions.

examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json (1)

301-310: New function call_something in IActions looks correct.

The new call_something function is consistent with existing structures and naming conventions.

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

🚀

@glihm glihm merged commit f319acc into main Jul 10, 2024
15 checks passed
@glihm glihm deleted the sozo-features branch July 10, 2024 14:59
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.

Support --features option
2 participants