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

construct_runtime! requires 'srml_system' to be imported as 'system' in its parent namespace #3295

Open
bddap opened this issue Aug 2, 2019 · 2 comments

Comments

@bddap
Copy link
Contributor

@bddap bddap commented Aug 2, 2019

When srml_system is named something other than system. construct_runtime! fails. decl_module! behaves similarly.

This compiles:

use srml_system as system;
construct_runtime!(
    pub enum Runtime where
        Block = Block,
        NodeBlock = opaque::Block,
        UncheckedExtrinsic = UncheckedExtrinsic
    {
        System: system::{Module, Call, Storage, Config, Event},
        Timestamp: srml_timestamp::{Module, Call, Storage, Inherent},
        Aura: srml_aura::{Module, Config<T>, Inherent(Timestamp)},
        Indices: srml_indices::{default, Config<T>},
        Balances: srml_balances,
        Sudo: srml_sudo,
        TemplateModule: template::{Module, Call, Storage, Event<T>},
    }
);

This results in errors:

// use srml_system as system;
construct_runtime!(
    pub enum Runtime where
        Block = Block,
        NodeBlock = opaque::Block,
        UncheckedExtrinsic = UncheckedExtrinsic
    {
        System: srml_system::{Module, Call, Storage, Config, Event},
        Timestamp: srml_timestamp::{Module, Call, Storage, Inherent},
        Aura: srml_aura::{Module, Config<T>, Inherent(Timestamp)},
        Indices: srml_indices::{default, Config<T>},
        Balances: srml_balances,
        Sudo: srml_sudo,
        TemplateModule: template::{Module, Call, Storage, Event<T>},
    }
);
errors
Compiling runtime v2.0.0 (/Users/a/d/substrate-warmup/runtime)
error: failed to run custom build command for `runtime v2.0.0 (/Users/a/d/substrate-warmup/runtime)`

Caused by:
  process didn't exit successfully: `/Users/a/d/substrate-warmup/runtime/target/debug/build/runtime-55c470ebc602fae6/build-script-build` (exit code: 1)
--- stdout
Executing build command: "rustup" "run" "nightly" "cargo" "build" "--target=wasm32-unknown-unknown" "--manifest-path=/Users/a/d/substrate-warmup/runtime/target/debug/wbuild/runtime/Cargo.toml"

--- stderr
   Compiling wasm-build-runner-impl v1.0.0 (/Users/a/d/substrate-warmup/runtime/target/debug/build/runtime-2a8a67935ec6fc11/out/wasm_build_runner)
    Finished dev [unoptimized + debuginfo] target(s) in 0.79s
     Running `target/debug/build/runtime-2a8a67935ec6fc11/out/wasm_build_runner/target/debug/wasm-build-runner-impl`
   Compiling runtime v2.0.0 (/Users/a/d/substrate-warmup/runtime)
error[E0433]: failed to resolve: use of undeclared type or module `system`
  --> /Users/a/d/substrate-warmup/runtime/src/template.rs:32:1
   |
32 | / decl_module! {
33 | |     /// The module declaration.
34 | |     pub struct Module<T: Trait> for enum Call where origin: T::Origin {
35 | |         // Initializing events
...  |
54 | |     }
55 | | }
   | |_^ use of undeclared type or module `system`
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `system`
   --> /Users/a/d/substrate-warmup/runtime/src/lib.rs:206:1
    |
206 | / construct_runtime!(
207 | |     pub enum Runtime where
208 | |         Block = Block,
209 | |         NodeBlock = opaque::Block,
...   |
219 | |     }
220 | | );
    | |__^ use of undeclared type or module `system`
    |
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `system`
   --> /Users/a/d/substrate-warmup/runtime/src/lib.rs:206:1
    |
206 | / construct_runtime!(
207 | |     pub enum Runtime where
208 | |         Block = Block,
209 | |         NodeBlock = opaque::Block,
...   |
219 | |     }
220 | | );
    | |__^ use of undeclared type or module `system`
    |
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `system`
   --> /Users/a/d/substrate-warmup/runtime/src/lib.rs:206:1
    |
206 | / construct_runtime!(
207 | |     pub enum Runtime where
208 | |         Block = Block,
209 | |         NodeBlock = opaque::Block,
...   |
219 | |     }
220 | | );
    | |__^ use of undeclared type or module `system`
    |
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0119]: conflicting implementations of trait `core::convert::From<[type error]>` for type `Call`:
   --> /Users/a/d/substrate-warmup/runtime/src/lib.rs:206:1
    |
206 | / construct_runtime!(
207 | |     pub enum Runtime where
208 | |         Block = Block,
209 | |         NodeBlock = opaque::Block,
...   |
219 | |     }
220 | | );
    | |  ^
    | |  |
    | |__first implementation here
    |    conflicting implementation for `Call`
    |
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0119]: conflicting implementations of trait `template::sr_api_hidden_includes_decl_storage::hidden_include::IsSubType<[type error], Runtime>` for type `Call`:
   --> /Users/a/d/substrate-warmup/runtime/src/lib.rs:206:1
    |
206 | / construct_runtime!(
207 | |     pub enum Runtime where
208 | |         Block = Block,
209 | |         NodeBlock = opaque::Block,
...   |
219 | |     }
220 | | );
    | |  ^
    | |  |
    | |__first implementation here
    |    conflicting implementation for `Call`
    |
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0119, E0433.
For more information about an error, try `rustc --explain E0119`.
error: Could not compile `runtime`.

To learn more, run the command again with --verbose.

Let me know if you need more info to reproduce the issue.

@wuminzhe

This comment has been minimized.

Copy link

@wuminzhe wuminzhe commented Aug 7, 2019

I think the reason for this error is that the system is hard-coded in the construct_runtime macro, so if you change it to any other name, the code will complain "use of undeclared type or module system" :

(
    $runtime:ident;
    $system:ident;
    { $( $parsed_module:ident :: $parsed_name:ident $(<$instance:ident>)? ,)*};
) => {
    pub type System = system::Module<$runtime>;
    $(
        pub type $parsed_name = $parsed_module::Module<$runtime $(, $parsed_module::$instance )?>;
    )*
    type AllModules = ( $( $parsed_name, )* );
}
@thiolliere

This comment has been minimized.

Copy link
Contributor

@thiolliere thiolliere commented Aug 8, 2019

at some point we could search for its rename similarly to what we do in procedural macro with https://crates.io/crates/proc-macro-crate

but then this would search for srml-system and one could want to use another system maybe ?
I think the correct solution would be to to make system crate name as an input of construct runtime so user can provide whatever name he wants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.