Commit 3e3085da authored by Andrew Jones's avatar Andrew Jones

Merge branch 'master' into aj-metadata-rename

# Conflicts:
#	cli/src/cmd/metadata.rs
parents 00e710f3 80984939
Pipeline #56990 failed with stages
in 27 seconds
......@@ -16,6 +16,8 @@ variables:
CARGO_INCREMENTAL: 0
CI_SERVER_NAME: "GitLab CI"
REGISTRY: registry.parity.io/parity/infrastructure/scripts
ALL_CRATES: "core alloc utils lang2 lang2/macro cli"
WASM_CRATES: "core alloc utils lang2 lang2/macro"
.collect-artifacts: &collect-artifacts
artifacts:
......@@ -32,6 +34,7 @@ variables:
- rustc -vV
- rustup show
- bash --version
- mkdir -p ${CARGO_HOME}; touch ${CARGO_HOME}/config
# global RUSTFLAGS overrides the linker args so this way is better to pass the flags
- printf '[build]\nrustflags = ["-C", "link-dead-code"]\n' | tee ${CARGO_HOME}/config
- sccache -s
......@@ -52,73 +55,121 @@ variables:
#### stage: check-workspace
cargo-check-af:
check-std:
stage: check-workspace
<<: *docker-env
script:
- cargo check --verbose --all --all-features
- for crate in ${ALL_CRATES}; do
cargo check --verbose --all-features;
done
cargo-check-nf:
check-wasm:
stage: check-workspace
<<: *docker-env
script:
- cargo check --verbose --all --no-default-features
- for crate in ${WASM_CRATES}; do
cargo check --verbose --no-default-features --target wasm32-unknown-unknown --manifest-path ${crate}/Cargo.toml;
done
cargo-fmt:
build-std:
stage: check-workspace
<<: *docker-env
script:
- cargo fmt --verbose --all -- --check
- for crate in ${ALL_CRATES}; do
cargo build --verbose --all-features --release;
done
cargo-clippy-af:
build-wasm:
stage: check-workspace
<<: *docker-env
script:
- cargo clippy --verbose --all --all-features -- -D warnings
- for crate in ${WASM_CRATES}; do
cargo build --verbose --no-default-features --release --target wasm32-unknown-unknown --manifest-path ${crate}/Cargo.toml;
done
cargo-clippy-nf:
test-std:
stage: check-workspace
<<: *docker-env
script:
- cargo clippy --verbose --all --no-default-features -- -D warnings
- for crate in ${ALL_CRATES}; do
cargo test --verbose --all-features --release;
done
cargo-test-af:
clippy-std:
stage: check-workspace
<<: *docker-env
script:
- cargo test --verbose --all --all-features
- for crate in ${ALL_CRATES}; do
cargo clippy --verbose --all-features -- -D warnings;
done
cargo-build-nf:
clippy-wasm:
stage: check-workspace
<<: *docker-env
script:
- cargo build --verbose --all --no-default-features --release --target=wasm32-unknown-unknown
- for crate in ${WASM_CRATES}; do
cargo clippy --verbose --manifest-path ${crate}/Cargo.toml --no-default-features -- -D warnings;
done
fmt:
stage: check-workspace
<<: *docker-env
script:
- for crate in ${ALL_CRATES}; do
cargo fmt --verbose -- --check;
done
#### stage: examples
examples-wasm:
examples-test:
stage: examples
<<: *docker-env
script:
- for example in $(ls examples/lang); do
cargo build --release --no-default-features --target=wasm32-unknown-unknown --verbose --manifest-path examples/lang/$example/Cargo.toml;
- for DIR in examples/lang2/*; do
cargo test --verbose --manifest-path ${DIR}/Cargo.toml;
done
- sccache -s
examples-test:
examples-fmt:
stage: examples
<<: *docker-env
script:
- for example in $(ls examples/lang); do
cargo test --verbose --manifest-path examples/lang/$example/Cargo.toml;
- for example in examples/lang2/*; do
cargo fmt --verbose --manifest-path ${example}/Cargo.toml -- --check;
done
- sccache -s
examples-abi:
examples-clippy-std:
stage: examples
<<: *docker-env
script:
- for example in $(ls examples/lang); do
cargo run --package abi-gen --manifest-path examples/lang/$example/Cargo.toml;
- for example in examples/lang2/*; do
cargo clippy --verbose --manifest-path ${example}/Cargo.toml --all-features -- -D warnings;
done
examples-clippy-wasm:
stage: examples
<<: *docker-env
script:
- for example in examples/lang2/*; do
cargo clippy --verbose --manifest-path ${example}/Cargo.toml --no-default-features -- -D warnings;
done
examples-contract-build:
stage: examples
<<: *docker-env
script:
- for example in examples/lang2/*; do
pushd $example &&
cargo contract build &&
popd;
done
examples-generate-abi:
stage: examples
<<: *docker-env
script:
- for example in examples/lang2/*; do
pushd $example &&
cargo contract generate-abi &&
popd;
done
- sccache -s
# ink! - Parity's ink to write smart contracts
| Linux | Codecov | Coveralls | LoC |
|:------------------:|:--------------------:|:----------------------:|:----------------:|
| [![linux][A1]][A2] | [![codecov][C1]][C2] | [![coveralls][D1]][D2] | [![loc][E1]][E2] |
[A1]: https://travis-ci.org/paritytech/ink.svg?branch=master
[A2]: https://travis-ci.org/paritytech/ink
[C1]: https://codecov.io/gh/paritytech/ink/branch/master/graph/badge.svg
[C2]: https://codecov.io/gh/paritytech/ink/branch/master
[D1]: https://coveralls.io/repos/github/paritytech/ink/badge.svg?branch=master
[D2]: https://coveralls.io/github/paritytech/ink?branch=master
[E1]: https://tokei.rs/b1/github/paritytech/ink?category=code
[E2]: https://github.com/Aaronepower/tokei#badges
[F1]: https://img.shields.io/badge/docs-core-blue.svg
[F2]: https://paritytech.github.io/ink/ink_core
[G1]: https://img.shields.io/badge/docs-model-blue.svg
[G2]: https://paritytech.github.io/ink/ink_model
[H1]: https://img.shields.io/badge/docs-abi-blue.svg
[H2]: https://paritytech.github.io/ink/ink_abi
| Linux | Codecov | Coveralls | LoC |
| :----------------: | :------------------: | :--------------------: | :--------------: |
| [![linux][a1]][a2] | [![codecov][c1]][c2] | [![coveralls][d1]][d2] | [![loc][e1]][e2] |
[a1]: https://travis-ci.org/paritytech/ink.svg?branch=master
[a2]: https://travis-ci.org/paritytech/ink
[c1]: https://codecov.io/gh/paritytech/ink/branch/master/graph/badge.svg
[c2]: https://codecov.io/gh/paritytech/ink/branch/master
[d1]: https://coveralls.io/repos/github/paritytech/ink/badge.svg?branch=master
[d2]: https://coveralls.io/github/paritytech/ink?branch=master
[e1]: https://tokei.rs/b1/github/paritytech/ink?category=code
[e2]: https://github.com/Aaronepower/tokei#badges
[f1]: https://img.shields.io/badge/docs-core-blue.svg
[f2]: https://paritytech.github.io/ink/ink_core
[g1]: https://img.shields.io/badge/docs-model-blue.svg
[g2]: https://paritytech.github.io/ink/ink_model
[h1]: https://img.shields.io/badge/docs-abi-blue.svg
[h2]: https://paritytech.github.io/ink/ink_abi
**IMPORTANT NOTE:** WORK IN PROGRESS! Do not expect this to be working.
......@@ -33,9 +27,9 @@ For more information please visit [the ink! tutorial](https://substrate.dev/subs
## Developer Documentation
| `ink_abi` | `ink_core` | `ink_model` |
|-----------|------------|-------------|
| [![][H1]][H2] | [![][F1]][F2] | [![][G1]][G2] |
| `ink_abi` | `ink_core` | `ink_model` |
| ------------- | ------------- | ------------- |
| [![][h1]][h2] | [![][f1]][f2] | [![][g1]][g2] |
### Scripts
......@@ -49,17 +43,38 @@ For building the example smart contracts found under `examples` you will need to
cargo install --git https://github.com/paritytech/ink cargo-contract --force
```
We use the `--force` to ensure you are updated to the most recent `cargo-contract` version.
Use the `--force` to ensure you are updated to the most recent `cargo-contract` version.
### Build example contract and generate the contracts metadata
To build a single example and generate the contracts Wasm file, navigate to the root of the example smart contract and run:
```
cargo contract build
```
To generate the contract metadata (a.k.a. the contract ABI), run the following command:
```
cargo contract generate-metadata
```
You should now have an optimized `<contract-name>.wasm` file and an `metadata.json` file in the `target` folder of the contract.
Please visit [the documentation](https://substrate.dev/substrate-contracts-workshop/#/0/building-your-contract)
about building contracts and generating metadata.
For further information, please have a look at our [smart contracts workshop](https://substrate.dev/substrate-contracts-workshop/).
### Hello, World! - The Flipper
## Hello, World! - The Flipper
The `Flipper` contract is a simple contract containing only a single `bool` value
that it can flip from `true` to `false` and vice versa and return the current state.
Below you can see the code using the `ink_lang2` frontend to ink!.
To create your own version of the flipper contract, you first need to initialize a new ink! project in your working directory.
```
cargo contract new flipper
```
Below you can see the code using the `ink_lang2` version of ink!.
```rust
use ink_core::storage;
......@@ -127,6 +142,8 @@ mod flipper {
}
```
Place this code in the `./lib.rs` file of your flipper contract and run `cargo contract build && cargo contract generate-metadata` to build your first ink! smart contract example.
## Contribution
Visit our [contribution guidelines](CONTRIBUTING.md) for more information.
......@@ -134,4 +151,3 @@ Visit our [contribution guidelines](CONTRIBUTING.md) for more information.
## License
The entire code within this repository is licensed under the [GPLv3](LICENSE). Please [contact us](https://www.parity.io/contact/) if you have questions about the licensing of our products.
of our products.
......@@ -89,12 +89,16 @@ pub fn collect_crate_metadata(working_dir: Option<&PathBuf>) -> Result<CrateMeta
///
/// Currently it assumes that user wants to use `+nightly`.
fn build_cargo_project(working_dir: Option<&PathBuf>) -> Result<()> {
super::exec_cargo("build", &[
"--no-default-features",
"--release",
"--target=wasm32-unknown-unknown",
"--verbose",
], working_dir)
super::exec_cargo(
"build",
&[
"--no-default-features",
"--release",
"--target=wasm32-unknown-unknown",
"--verbose",
],
working_dir,
)
}
/// Ensures the wasm memory import of a given module has the maximum number of pages.
......
......@@ -14,9 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with ink!. If not, see <http://www.gnu.org/licenses/>.
use crate::cmd::{
Result,
};
use crate::cmd::Result;
use cargo_metadata::MetadataCommand;
use std::path::PathBuf;
......@@ -26,13 +24,17 @@ use std::path::PathBuf;
pub(crate) fn execute_generate_metadata(dir: Option<&PathBuf>) -> Result<String> {
println!(" Generating metadata");
super::exec_cargo("run", &[
"--package",
"abi-gen",
"--release",
"--no-default-features",
"--verbose",
], dir)?;
super::exec_cargo(
"run",
&[
"--package",
"abi-gen",
"--release",
// "--no-default-features", // Breaks builds for MacOS (linker errors), we should investigate this issue asap!
"--verbose",
],
dir,
)?;
let cargo_metadata = MetadataCommand::new().exec()?;
let mut out_path = cargo_metadata.target_directory.clone();
......
......@@ -40,7 +40,11 @@ pub(crate) use self::{
new::execute_new,
};
fn exec_cargo(command: &str, args: &[&'static str], working_dir: Option<&PathBuf>) -> Result<()> {
fn exec_cargo(
command: &str,
args: &[&'static str],
working_dir: Option<&PathBuf>,
) -> Result<()> {
let mut cmd = Command::new("cargo");
let mut is_nightly_cmd = Command::new("cargo");
if let Some(dir) = working_dir {
......@@ -60,10 +64,7 @@ fn exec_cargo(command: &str, args: &[&'static str], working_dir: Option<&PathBuf
cmd.arg("+nightly");
}
let output = cmd
.arg(command)
.args(args)
.output()?;
let output = cmd.arg(command).args(args).output()?;
if !output.status.success() {
// Dump the output streams produced by cargo into the stdout/stderr.
......
# ink! code examples
This folder contains a set of example contracts for ink!.
Have a look at the different examples to better understand how to use ink! to build your own Substrate smart contracts.
## Preparation
For building the example smart contracts found in this folder you will need to have `cargo-contract` installed.
```
cargo install --force --git https://github.com/paritytech/ink cargo-contract
```
We use the `--force` to update to the most recent `cargo-contract` version.
## Build example contract and generate the contracts metadata
To build a single example and generate the contracts Wasm file, navigate to the root of the smart contract and run the following command:
`cargo contract build`
To generate the contract metadata (a.k.a. the contract ABI), run the following command:
`cargo contract generate-metadata`
You should now have an optimized `<contract-name>.wasm` file and an `metadata.json` file in the `target` folder of your contract.
## License
The entire code within this repository is licensed under the [GPLv3](LICENSE). Please [contact us](https://www.parity.io/contact/) if you have questions about the licensing of our products.
......@@ -29,8 +29,10 @@ derive_more = { version = "0.99.1", default-features = false, features = ["from"
regex = "1.3"
[dev-dependencies]
ink_abi = { path = "../../abi/" }
ink_core = { path = "../../core/" }
ink_lang2 = { path = ".." }
ink_lang2 = { path = "..", default-features = false, features = ["ink-generate-abi"] }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"] }
trybuild = "1.0"
pretty_assertions = "0.6.1"
......
......@@ -386,16 +386,15 @@ impl TryFrom<syn::ImplItemMethod> for ir::Function {
selector: ir::FunctionSelector::from(&method.sig.ident),
}))
}
_unknown => Err(format_err_span!(attr.span(), "unknown ink! marker",)),
_unknown => {
Err(format_err_span!(attr.span(), "unknown ink! marker",))
}
}?;
if kind == ir::FunctionKind::Method {
kind = new_kind;
Ok(())
} else {
Err(format_err_span!(
attr.span(),
"conflicting ink! marker",
))
Err(format_err_span!(attr.span(), "conflicting ink! marker",))
}
})
.filter_map(Result::err)
......@@ -597,27 +596,29 @@ impl TryFrom<syn::Item> for ir::Item {
}
let event_marker =
markers.iter().position(|marker| marker.is_simple("event"));
let storage_marker =
markers.iter().position(|marker| marker.is_simple("storage"));
let storage_marker = markers
.iter()
.position(|marker| marker.is_simple("storage"));
match (storage_marker, event_marker) {
(Some(_storage_marker), None) => {
ir::ItemStorage::try_from(item_struct)
.map(Into::into)
.map(ir::Item::Ink)
},
}
(None, Some(_event_marker)) => {
ir::ItemEvent::try_from(item_struct)
.map(Into::into)
.map(ir::Item::Ink)
},
}
(None, None) => {
Err(markers
.iter()
.map(|marker| {
format_err_span!(
marker.span(),
"unsupported ink! marker for struct")
"unsupported ink! marker for struct"
)
})
.fold(
format_err!(
......@@ -625,10 +626,10 @@ impl TryFrom<syn::Item> for ir::Item {
"encountered unsupported ink! markers for struct",
),
|mut err1, err2| {
err1.combine(err2);
err1
})
)
err1.combine(err2);
err1
},
))
}
(Some(storage_marker), Some(event_marker)) => {
// Special case: We have both #[ink(storage)] and #[ink(event)].
......@@ -685,17 +686,18 @@ fn split_items(
n => {
Err(storages
.iter()
.map(|storage| {
format_err!(storage.ident, "conflicting storage struct")
})
.map(|storage| format_err!(storage.ident, "conflicting storage struct"))
.fold(
format_err_span!(Span::call_site(), "encountered {} conflicting storage structs", n),
format_err_span!(
Span::call_site(),
"encountered {} conflicting storage structs",
n
),
|mut err1, err2| {
err1.combine(err2);
err1
}
)
)
},
))
}
}?;
let (events, impl_blocks): (Vec<ir::ItemEvent>, Vec<ir::ItemImpl>) =
......@@ -712,7 +714,7 @@ fn split_items(
});
let storage_ident = &storage.ident;
for item_impl in &impl_blocks {
if item_impl.self_ty != storage_ident.to_string() {
if &item_impl.self_ty != storage_ident {
bail!(
item_impl.self_ty,
"ink! impl blocks need to be implemented for the #[ink(storage)] struct"
......
......@@ -219,7 +219,7 @@ where
}
DispatchMode::Call => self.messages.dispatch(&mut self.storage, &call_data),
};
ret.into()
ret
}
}
......
......@@ -40,7 +40,7 @@
trivial_numeric_casts,
unused_extern_crates,
unused_qualifications,
unused_results,
unused_results
)]
#[macro_use]
......
......@@ -17,11 +17,21 @@
declare -A results
cargo check --verbose --all --all-features
results["check_all_features"]=$?
all_crates=("core" "alloc" "utils" "model" "lang" "lang2" "lang2/macro" "cli")
wasm_crates=("core" "alloc" "utils" "model" "lang" "lang2" "lang2/macro")
cargo check --verbose --all --no-default-features
results["check_no_defaults"]=$?
results["check_all_features"]=true
for crate in "${all_crates[@]}"; do
cargo check --verbose --all-features --manifest-path $crate/Cargo.toml
let "results['check_all_features'] |= $?"
cargo check --verbose --no-default-features --manifest-path $crate/Cargo.toml
let "results['check_no_defaults'] |= $?"
done
for crate in "${wasm_crates[@]}"; do
cargo build --verbose --manifest-path $crate/Cargo.toml --no-default-features --release --target=wasm32-unknown-unknown
let "results['build_wasm'] |= $?"
done
cargo fmt --verbose --all -- --check
results["fmt"]=$?
......@@ -32,12 +42,9 @@ results["clippy_all_features"]=$?
cargo clippy --verbose --all --no-default-features -- -D warnings
results["clippy_no_defaults"]=$?
cargo test --verbose --all --all-features
cargo test --verbose --all --all-features --release
results["test_all_features"]=$?
cargo build --verbose --all --no-default-features --release --target=wasm32-unknown-unknown
results["build_wasm"]=$?
all_checks_passed=0
banner="-----------------"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment