Skip to content

Crate-level ABI declaration for ink! entities #2479

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

Closed
davidsemakula opened this issue Apr 8, 2025 · 0 comments · Fixed by #2501
Closed

Crate-level ABI declaration for ink! entities #2479

davidsemakula opened this issue Apr 8, 2025 · 0 comments · Fixed by #2501
Assignees
Labels
B-design Designing a new component, interface or functionality. Breaking change This PR of issue introduces a breaking change

Comments

@davidsemakula
Copy link
Collaborator

davidsemakula commented Apr 8, 2025

Background

ink! v6 supports both the native ink! and Solidity ABI specifications.
Currently, ink! contracts can specify the target ABI using the abi config argument of the contract attribute macro (i.e. #[ink::contract(abi = "..")]).

Motivation

However, this means the specified ABI is only accessible to the contract attribute proc-macro during codegen.
This is problematic because the specified ABI is also relevant to other ink! entities (e.g. trait definitions, events and - in the future - errors) that can be defined either outside of contract module, or in separate standalone crates.

Design

  • Introduce a Cargo.toml section [package.metadata.ink-lang] with a field abi and possible values "ink", "sol" and "all" e.g.

    [package]
    name = "flipper"
    # ... more stuff
      
    [package.metadata.ink-lang]
    abi = "sol"

    NOTE: Cargo will warn about "unused" keys by default except for keys in "package.metadata" (see details)

  • Introduce a rustc cfg setting/flag ink_abi with possible values "ink", "sol" and "all" which is used to propagate the package.metadata.ink-lang.abi value defined in Cargo.toml as described above into the build environment

  • Update cargo-contract to:

    • Read the value of the package.metadata.ink-lang.abi field from Cargo.toml (if present)
    • Validate the specified value and issue warnings/errors as appropriate
    • Set the ink_abi cfg flag as appropriate (e.g. --cfg 'ink_abi="sol"')
    • Update the cargo contract new subcommand to support ABI specification via a CLI arg (i.e. cargo contract new --abi <ink|sol|all>)
    • Add cargo contract test subcommand for propagating the ABI specified in Cargo.toml into the build environment for tests
  • Update proc-macros for ink! entities to support the new cfg option (e.g. #[cfg(ink_abi = "sol")] - see also) to generate ABI specific code

Implementation

Docs

@davidsemakula davidsemakula self-assigned this Apr 8, 2025
@davidsemakula davidsemakula changed the title Crate level ABI declaration for ink! entities Crate-level ABI declaration for ink! entities Apr 8, 2025
@davidsemakula davidsemakula added B-design Designing a new component, interface or functionality. Breaking change This PR of issue introduces a breaking change labels Apr 9, 2025
@davidsemakula davidsemakula moved this from Backlog to In progress in ink! + `cargo-contract` v6 May 4, 2025
@davidsemakula davidsemakula moved this from In progress to In review in ink! + `cargo-contract` v6 May 12, 2025
@github-project-automation github-project-automation bot moved this from In review to Done in ink! + `cargo-contract` v6 May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-design Designing a new component, interface or functionality. Breaking change This PR of issue introduces a breaking change
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant