Skip to content

Commit

Permalink
Introduce entrance crate (#1223)
Browse files Browse the repository at this point in the history
* Add ink entrance crate

* Use entrance crate from lang codegen

* Use entrance crate for ink_storage

* Update primitives and storage

* Fix primitive macro

* Move unique_topics test to ink crate

* Update ink crate versions

* Use umbrella crate in ink primitives macro

* Use umbrella crate in storage derive macros

* Use umbrella crate in storage doc tests

* Use umbrella crate in lang codegen

* Fix storage doc tests

* Update erc20 example

* Remove scale libs from entrance crate

* Rename ink_lang crate to ink

* Reexport sub crates from main ink crate

* Metadata std

* Fix up some examples

* Fix up delegator example

* Fix up more examples

* Fix up more examples

* Fix up more examples

* Remove some ink_lang as ink from tests

* Update env_access docs

* Fix up more doc examples

* Remove ink_lang import from some tests

* UI tests

* Fix UI tests

* Remove more ink_lang aliases

* Fix contract-terminate tests

* Fmt

* Attempt to fix CI and ARCHITECTURE doc

* Update crates list

* Restore unique_topics test

* Remove ink_lang from unique_topics test

* Fix typo

* UI tests

* UI tests

* Fmt examples

* Fmt UI tests

* More fmt UI tests

* Fix storage tests

* Fix example tests

* Fix examplesl

* Fix example test

* Examples fmt

* Fix erc20

* Fmt erc20

* Fix doc test

* Move unique_topics test

* Fix UI tests

* Revert CHANGELOG.md

* Use cargo-contract branch in examples-contract-build

* Add ink-debug feature to top level ink crate

* Update CHANGELOG.md

* Rename all ink_lang_* crates to ink_*

* Replace remaining ink_lang_macro refs

* Update CHANGELOG.md

Co-authored-by: Michael Müller <[email protected]>

* Update CHANGELOG

Co-authored-by: Michael Müller <[email protected]>
  • Loading branch information
ascjones and cmichi authored Sep 15, 2022
1 parent c9c81c7 commit 3eb6eb0
Show file tree
Hide file tree
Showing 514 changed files with 1,549 additions and 2,173 deletions.
12 changes: 6 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ variables:
# CI_IMAGE is changed to "-:staging" when the CI image gets rebuilt
# read more https://github.com/paritytech/scripts/pull/244
CI_IMAGE: "paritytech/ink-ci-linux:production"
PURELY_STD_CRATES: "lang/codegen storage/traits/codegen metadata engine"
ALSO_WASM_CRATES: "env storage storage/traits storage/traits/derive allocator prelude primitives lang lang/macro lang/ir"
PURELY_STD_CRATES: "ink/codegen storage/traits/codegen metadata engine"
ALSO_WASM_CRATES: "env storage storage/traits storage/traits/derive allocator prelude primitives ink ink/macro ink/ir"
ALL_CRATES: "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}"
DELEGATOR_SUBCONTRACTS: "accumulator adder subber"
UPGRADEABLE_CONTRACTS: "forward-calls set-code-hash"
Expand Down Expand Up @@ -112,8 +112,8 @@ fmt:
script:
- cargo +nightly fmt --verbose --all -- --check
# For the UI tests we need to disable the license check
- cargo +nightly fmt --verbose --all -- --check ./crates/lang/tests/ui/contract/{pass,fail}/*.rs
- cargo +nightly fmt --verbose --all -- --check ./crates/lang/tests/ui/trait_def/{pass,fail}/*.rs
- cargo +nightly fmt --verbose --all -- --check ./crates/ink/tests/ui/contract/{pass,fail}/*.rs
- cargo +nightly fmt --verbose --all -- --check ./crates/ink/tests/ui/trait_def/{pass,fail}/*.rs
allow_failure: true

examples-fmt:
Expand Down Expand Up @@ -289,7 +289,7 @@ docs:
-p scale-info -p ink_metadata -p ink_env
-p ink_storage -p ink_storage_traits -p ink_storage_codegen -p ink_storage_derive
-p ink_primitives -p ink_prelude
-p ink_lang -p ink_lang_macro -p ink_lang_ir -p ink_lang_codegen
-p ink -p ink_macro -p ink_ir -p ink_codegen
- mv ${CARGO_TARGET_DIR}/doc ./crate-docs
# FIXME: remove me after CI image gets nonroot
- chown -R nonroot:nonroot ./crate-docs
Expand Down Expand Up @@ -367,7 +367,7 @@ examples-contract-build:
<<: *test-refs
script:
- rustup component add rust-src --toolchain stable
- cargo install cargo-contract --version 2.0.0-alpha.1 --force
- cargo install cargo-contract --git https://github.com/paritytech/cargo-contract --branch aj/ink_crate --force
- cargo contract -V
- for example in examples/*/; do
if [ "$example" = "examples/upgradeable-contracts/" ]; then continue; fi;
Expand Down
10 changes: 5 additions & 5 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can find the crate documentation on docs.rs or for our
ink! is composed of a number of crates that are all found in the
`crates/` folder. On a high-level those can be grouped as:

* [`lang`](https://github.com/paritytech/ink/tree/master/crates/lang):
* [`ink`](https://github.com/paritytech/ink/tree/master/crates/ink):
The ink! language itself.
* [`allocator`](https://github.com/paritytech/ink/tree/master/crates/allocator):
The allocator used for dynamic memory allocation in a contract.
Expand Down Expand Up @@ -70,11 +70,11 @@ The central delegating crate for the ink! eDSL is `ink_lang`.
In the `crates/lang/` folder you'll find three separate
crates on which `ink_lang` relies heavily:

* `ink_lang_macro`: The procedural macros, they take code annotated with e.g.
`[ink::contract]` and forwards it to `ink_lang_ir`.
* `ink_lang_ir`: Defines everything the procedural macro needs in order to
* `ink_macro`: The procedural macros, they take code annotated with e.g.
`[ink::contract]` and forwards it to `ink_ir`.
* `ink_ir`: Defines everything the procedural macro needs in order to
parse, analyze and generate code for ink! smart contracts.
* `ink_lang_codegen`: Generates Rust code from the ink! IR.
* `ink_codegen`: Generates Rust code from the ink! IR.

## Building ink! contracts

Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Breaking Changes

#### New `ink` crate
The `ink_lang` crate has been replaced in [#1223](https://github.com/paritytech/ink/pull/1223) by a new top level `ink`
crate. All existing sub-crates are reexported and should be used via the new `ink` crate, so e.g. `ink::env` instead of
`ink_env`. Contract authors should now import the top level `ink` crate instead of the individual crates.

##### Migration
- In `Cargo.toml` Replace all individual `ink_*` crate dependencies with the `ink` crate.
- In the contract source:
- Remove the commonly used `use ink_lang as ink` idiom.
- Replace all usages of individual crates with reexports, e.g. `ink_env``ink::env`.

## Version 4.0.0-alpha.1

### Compatibility
Expand Down
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[workspace]
resolver = "2"
members = [
"crates/ink",
"crates/metadata",
"crates/allocator",
"crates/lang",
"crates/lang/macro",
"crates/lang/ir",
"crates/lang/codegen",
"crates/lang/macro",
"crates/ink",
"crates/ink/macro",
"crates/ink/ir",
"crates/ink/codegen",
"crates/ink/macro",
"crates/prelude",
"crates/primitives",
"crates/engine",
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ It provides methods to
Below you can see the code using the `ink_lang` version of ink!.

```rust
use ink_lang as ink;

#[ink::contract]
mod flipper {
/// The storage of the flipper contract.
Expand Down Expand Up @@ -164,8 +162,7 @@ mod flipper {
#[cfg(test)]
mod tests {
use super::*;
use ink_lang as ink;


#[ink::test]
fn it_works() {
let mut flipper = Flipper::new(false);
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/call/create_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub mod state {
/// # Note
///
/// This is needed because of conflicting implementations of `From<T> for T`
/// in the generated code of `ink_lang`.
/// in the generated code of `ink`.
pub trait FromAccountId<T>
where
T: Environment,
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/chain_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! Definitions and utilities for calling chain extension methods.
//!
//! Users should not use these types and definitions directly but rather use the provided
//! `#[ink::chain_extension]` procedural macro defined in the `ink_lang` crate.
//! `#[ink::chain_extension]` procedural macro defined in the `ink` crate.
use crate::{
backend::EnvBackend,
Expand Down
12 changes: 8 additions & 4 deletions crates/lang/Cargo.toml → crates/ink/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ink_lang"
name = "ink"
version = "4.0.0-alpha.1"
authors = ["Parity Technologies <[email protected]>", "Robin Freyler <[email protected]>"]
edition = "2021"
Expand All @@ -20,13 +20,13 @@ ink_storage = { version = "4.0.0-alpha.1", path = "../storage", default-features
ink_primitives = { version = "4.0.0-alpha.1", path = "../primitives", default-features = false }
ink_metadata = { version = "4.0.0-alpha.1", path = "../metadata", default-features = false, optional = true }
ink_prelude = { version = "4.0.0-alpha.1", path = "../prelude", default-features = false }
ink_lang_macro = { version = "4.0.0-alpha.1", path = "macro", default-features = false }
ink_macro = { version = "4.0.0-alpha.1", path = "macro", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from"] }

[dev-dependencies]
ink_lang_ir = { path = "./ir" }
ink_ir = { path = "./ir" }
ink_metadata = { path = "../metadata", default-features = false }

trybuild = { version = "1.0.60", features = ["diff"] }
Expand All @@ -41,7 +41,11 @@ std = [
"ink_primitives/std",
"ink_env/std",
"ink_storage/std",
"ink_lang_macro/std",
"ink_macro/std",
"scale/std",
]
# Enable contract debug messages via `debug_print!` and `debug_println!`.
ink-debug = [
"ink_env/ink-debug",
]
show-codegen-docs = []
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[package]
name = "ink_lang_codegen"
name = "ink_codegen"
version = "4.0.0-alpha.1"
authors = ["Parity Technologies <[email protected]>", "Robin Freyler <[email protected]>"]
edition = "2021"

license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/paritytech/ink"
documentation = "https://docs.rs/ink_lang_codegen/"
documentation = "https://docs.rs/ink_codegen/"
homepage = "https://www.parity.io/"
description = "data structures and algorithms for generating ink! IR code"
keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"]
categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[lib]
name = "ink_lang_codegen"
name = "ink_codegen"

[dependencies]
ink_primitives = { version = "4.0.0-alpha.1", path = "../../primitives" }
ir = { version = "4.0.0-alpha.1", package = "ink_lang_ir", path = "../ir", default-features = false }
ir = { version = "4.0.0-alpha.1", package = "ink_ir", path = "../ir", default-features = false }
quote = "1"
syn = { version = "1.0", features = ["parsing", "full", "extra-traits"] }
proc-macro2 = "1.0"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ where
{
use syn::spanned::Spanned as _;
args.into_iter().fold(
quote! { ::ink_env::call::utils::EmptyArgumentList },
quote! { ::ink::env::call::utils::EmptyArgumentList },
|rest, arg| {
let span = arg.span();
quote_spanned!(span=>
::ink_env::call::utils::ArgumentList<::ink_env::call::utils::Argument<#arg>, #rest>
::ink::env::call::utils::ArgumentList<::ink::env::call::utils::Argument<#arg>, #rest>
)
}
)
Expand All @@ -98,7 +98,7 @@ pub fn generate_reference_to_trait_info(
trait_path: &syn::Path,
) -> TokenStream2 {
quote_spanned!(span=>
<<::ink_lang::reflect::TraitDefinitionRegistry<Environment>
as #trait_path>::__ink_TraitInfo as ::ink_lang::reflect::TraitInfo>::ID
<<::ink::reflect::TraitDefinitionRegistry<Environment>
as #trait_path>::__ink_TraitInfo as ::ink::reflect::TraitInfo>::ID
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl CallBuilder<'_> {
/// This identifier must not be used outside of the generated `const`
/// block in which the call builder type is going to be defined.
/// In order to refer to the call builder of an ink! smart contract
/// use the [`ink_lang::TraitCallBuilder`] trait implementation.
/// use the [`ink::TraitCallBuilder`] trait implementation.
fn call_builder_ident() -> syn::Ident {
format_ident!("CallBuilder")
}
Expand All @@ -84,7 +84,7 @@ impl CallBuilder<'_> {
#[repr(transparent)]
#[cfg_attr(feature = "std", derive(
::scale_info::TypeInfo,
::ink_storage::traits::StorageLayout,
::ink::storage::traits::StorageLayout,
))]
#[derive(
::core::fmt::Debug,
Expand All @@ -100,12 +100,12 @@ impl CallBuilder<'_> {
}

const _: () = {
impl ::ink_lang::codegen::ContractCallBuilder for #storage_ident {
impl ::ink::codegen::ContractCallBuilder for #storage_ident {
type Type = #cb_ident;
}

impl ::ink_lang::reflect::ContractEnv for #cb_ident {
type Env = <#storage_ident as ::ink_lang::reflect::ContractEnv>::Env;
impl ::ink::reflect::ContractEnv for #cb_ident {
type Env = <#storage_ident as ::ink::reflect::ContractEnv>::Env;
}
};
)
Expand All @@ -119,14 +119,14 @@ impl CallBuilder<'_> {
let span = self.contract.module().storage().span();
let cb_ident = Self::call_builder_ident();
quote_spanned!(span=>
impl ::ink_env::call::FromAccountId<Environment> for #cb_ident {
impl ::ink::env::call::FromAccountId<Environment> for #cb_ident {
#[inline]
fn from_account_id(account_id: AccountId) -> Self {
Self { account_id }
}
}

impl ::ink_lang::ToAccountId<Environment> for #cb_ident {
impl ::ink::ToAccountId<Environment> for #cb_ident {
#[inline]
fn to_account_id(&self) -> AccountId {
<AccountId as ::core::clone::Clone>::clone(&self.account_id)
Expand Down Expand Up @@ -183,8 +183,8 @@ impl CallBuilder<'_> {
let trait_info_id = generator::generate_reference_to_trait_info(span, trait_path);
quote_spanned!(span=>
#[doc(hidden)]
impl ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}> for #cb_ident {
type Forwarder = <<Self as #trait_path>::__ink_TraitInfo as ::ink_lang::codegen::TraitCallForwarder>::Forwarder;
impl ::ink::codegen::TraitCallForwarderFor<{#trait_info_id}> for #cb_ident {
type Forwarder = <<Self as #trait_path>::__ink_TraitInfo as ::ink::codegen::TraitCallForwarder>::Forwarder;

#[inline]
fn forward(&self) -> &Self::Forwarder {
Expand Down Expand Up @@ -213,18 +213,18 @@ impl CallBuilder<'_> {
}

#[inline]
fn build(&self) -> &<Self::Forwarder as ::ink_lang::codegen::TraitCallBuilder>::Builder {
<_ as ::ink_lang::codegen::TraitCallBuilder>::call(
<Self as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::forward(self)
fn build(&self) -> &<Self::Forwarder as ::ink::codegen::TraitCallBuilder>::Builder {
<_ as ::ink::codegen::TraitCallBuilder>::call(
<Self as ::ink::codegen::TraitCallForwarderFor<{#trait_info_id}>>::forward(self)
)
}

#[inline]
fn build_mut(&mut self)
-> &mut <Self::Forwarder as ::ink_lang::codegen::TraitCallBuilder>::Builder
-> &mut <Self::Forwarder as ::ink::codegen::TraitCallBuilder>::Builder
{
<_ as ::ink_lang::codegen::TraitCallBuilder>::call_mut(
<Self as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::forward_mut(self)
<_ as ::ink::codegen::TraitCallBuilder>::call_mut(
<Self as ::ink::codegen::TraitCallForwarderFor<{#trait_info_id}>>::forward_mut(self)
)
}
}
Expand All @@ -244,7 +244,7 @@ impl CallBuilder<'_> {
.map(|message| self.generate_ink_trait_impl_for_message(trait_path, message));
quote_spanned!(span=>
impl #trait_path for #cb_ident {
type __ink_TraitInfo = <::ink_lang::reflect::TraitDefinitionRegistry<Environment>
type __ink_TraitInfo = <::ink::reflect::TraitDefinitionRegistry<Environment>
as #trait_path>::__ink_TraitInfo;

#( #messages )*
Expand Down Expand Up @@ -285,8 +285,8 @@ impl CallBuilder<'_> {
quote_spanned!(span=>
type #output_ident = <<<
Self
as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::Forwarder
as ::ink_lang::codegen::TraitCallBuilder>::Builder
as ::ink::codegen::TraitCallForwarderFor<{#trait_info_id}>>::Forwarder
as ::ink::codegen::TraitCallBuilder>::Builder
as #trait_path>::#output_ident;

#[inline]
Expand All @@ -296,7 +296,7 @@ impl CallBuilder<'_> {
#( , #input_bindings: #input_types )*
) -> Self::#output_ident {
<_ as #trait_path>::#message_ident(
<Self as ::ink_lang::codegen::TraitCallForwarderFor<{#trait_info_id}>>::#build_cmd(self)
<Self as ::ink::codegen::TraitCallForwarderFor<{#trait_info_id}>>::#build_cmd(self)
#( , #input_bindings )*
)
}
Expand Down Expand Up @@ -374,11 +374,11 @@ impl CallBuilder<'_> {
output.map_or_else(|| quote! { () }, |output| quote! { #output });
let output_span = output.span();
let output_type = quote_spanned!(output_span=>
::ink_env::call::CallBuilder<
::ink::env::call::CallBuilder<
Environment,
::ink_env::call::utils::Set< ::ink_env::call::Call< Environment > >,
::ink_env::call::utils::Set< ::ink_env::call::ExecutionInput<#arg_list> >,
::ink_env::call::utils::Set< ::ink_env::call::utils::ReturnType<#return_type> >,
::ink::env::call::utils::Set< ::ink::env::call::Call< Environment > >,
::ink::env::call::utils::Set< ::ink::env::call::ExecutionInput<#arg_list> >,
::ink::env::call::utils::Set< ::ink::env::call::utils::ReturnType<#return_type> >,
>
);
quote_spanned!(span=>
Expand All @@ -389,11 +389,11 @@ impl CallBuilder<'_> {
& #mut_tok self
#( , #input_bindings : #input_types )*
) -> #output_type {
::ink_env::call::build_call::<Environment>()
.call_type(::ink_env::call::Call::new().callee(::ink_lang::ToAccountId::to_account_id(self)))
::ink::env::call::build_call::<Environment>()
.call_type(::ink::env::call::Call::new().callee(::ink::ToAccountId::to_account_id(self)))
.exec_input(
::ink_env::call::ExecutionInput::new(
::ink_env::call::Selector::new([ #( #selector_bytes ),* ])
::ink::env::call::ExecutionInput::new(
::ink::env::call::Selector::new([ #( #selector_bytes ),* ])
)
#(
.push_arg(#input_bindings)
Expand Down
Loading

0 comments on commit 3eb6eb0

Please sign in to comment.