I can not run Substrate on M1 - rust

I could run Substrate before based on this advise. Link
cargo.toml
[patch.crates-io]
librocksdb-sys = { git =
"https://github.com/hdevalence/rustrocksdb", branch = "master" }
[workspace]
members = [
'node',
'pallets/*',
'runtime',
]
[profile.release]
panic = 'unwind'
cargo.lock
[[package]]
name = "libc"
version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum
="ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
But I got another error again. Like
169 | (*cx.uc_mcontext).__ss.__rip as *const u8
| ^^^^^ unknown field
|
= note: available fields are: `__x`, `__fp`, `__lr`, `__sp`, `__pc` ... and 2 others
error: aborting due to previous error
For more information about this error, try `rustc --explain E0609`.
error: could not compile `wasmtime-runtime`
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
Do you know how to resolve this problem? Thank you so much!

Related

Compiling bevy_dylib v0.5.0 error: linking with `cc` failed: exit status: 1

On Mac freshly upgraded to Monterey, I'm getting the following when attempting to cargo run a trivial Bevy program. I've reinstalled XCode CLTs like recommended here and other places. I've tried messing around with some of the cargo.yml with no success.
Compiling bevy_dylib v0.5.0
error: linking with `cc` failed: exit status: 1
note: "cc" "-Wl,-exported_symbols_list,/var/folders/rp/lky8r76j5v5dk0rqg_yzk35w0000gn/T/rustcDYBmaq/list"
"-m64" "-arch" "x86_64" <......... many pages of warnings>
ld: warning: object file (/Users/BWStearns/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy-glsl-to-spirv-0.2.1/build/osx/libSPIRV-Tools-opt.glsltospirv.a(const_folding_rules.cpp.o)) was built for newer macOS version (10.13) than being linked (10.7)
<many more pages of warnings>
"_CGDisplayCreateUUIDFromDisplayID", referenced from:
_$LT$winit..platform_impl..platform..monitor..MonitorHandle$u20$as$u20$core..cmp..PartialEq$GT$::eq::h541b069daf520ec9 in libwinit-4f8b93ad49cc21f8.rlib(winit-4f8b93ad49cc21f8.winit.355ded65-cgu.6.rcgu.o)
_$LT$winit..platform_impl..platform..monitor..MonitorHandle$u20$as$u20$core..cmp..Ord$GT$::cmp::h951d61f6bd1d7a5f in libwinit-4f8b93ad49cc21f8.rlib(winit-4f8b93ad49cc21f8.winit.355ded65-cgu.6.rcgu.o)
winit::platform_impl::platform::monitor::MonitorHandle::ns_screen::h3207f8aed4eae22f in libwinit-4f8b93ad49cc21f8.rlib(winit-4f8b93ad49cc21f8.winit.355ded65-cgu.6.rcgu.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile `bevy_dylib` due to previous error
The cargo.yml is like this:
[package]
name = "my_bevy_game"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = { version = "0.5.0", features = ["dynamic"] }
I just ran into this starting this week. I am pretty sure this exact code was compiling fine a couple weeks ago. Any help would be greatly appreciated.
main.rs looks like
use bevy::prelude::*;
struct Person;
struct Name(String);
fn add_people(mut commands: Commands) {
commands.spawn().insert(Person).insert(Name("Elaina Proctor".to_string()));
commands.spawn().insert(Person).insert(Name("Renzo Hume".to_string()));
commands.spawn().insert(Person).insert(Name("Zayna Nieves".to_string()));
}
fn greet_people(query: Query<&Name, With<Person>>) {
for name in query.iter() {
println!("hello {}!", name.0);
}
}
pub struct HelloPlugin;
impl Plugin for HelloPlugin {
fn build(&self, app: &mut AppBuilder) {
app.add_startup_system(add_people.system())
.add_system(greet_people.system());
}
}
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_plugin(HelloPlugin)
.run();
}
Update:
Definitely something about the environment on my machine because on a different macbook it worked fine.
So I found a solution if you discover this issue and the code works on other machines. Uninstall rust with rustup self uninstall and then renistall with the standard script curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh and then you should be good.

Resolving imports in Rust

I'm having trouble with importing rand crate from crates.io. After adding the line rand="0.8.3" and then running command cargo build for the project, it keeps displaying the same errors:
error[E0432]: unresolved import `rand`
--> main.rs:1:5
|
1 | use rand::Rng;
| ^^^^ maybe a missing crate `rand`?
error[E0433]: failed to resolve: use of undeclared crate or module `rand`
--> main.rs:4:25
|
4 | let secret_number = rand::thread_rng().gen_range(1..=11);
| ^^^^ use of undeclared crate or module `rand`
error: aborting due to 2 previous errors
the cargo.toml file
[package]
name = "roller"
version = "0.1.0"
authors = ["User"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.3"
Basically the simplest reproducible example is this single line of code:
use rand::Rng;
fn main(){
let secret_number = rand::thread_rng().gen_range(1..=11);
print!("{}",secret_number);
}
What's wrong with it?
Just in case:
The **cargo.lock**file:
# This file is automatically #generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
name = "rand_chacha"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
"rand_core",
]
[[package]]
name = "roller"
version = "0.1.0"
dependencies = [
"rand",
]
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
In file Cargo.toml add lines:
[dependencies]
rand="0.3.14"
And rebuild project!
It worked with these versions:
rustc 1.53.0
cargo 1.53.0
Took answer from here https://github.com/rust-lang/rust/issues/34616
got the same error when I run it with vs code(rust-analyzer).
When you press the run button
rustic main.rs this command is called in terminal, it will cause error.
Type this in terminal,
cargo build
cargo run
It works well
If you think that you did everything right and get a strange unable to import error like this then you could try cargo clean.
That will allow you to fully re-build your binary/library after that.

Why building with rustc command cannot see crates?

Hi I'm trying to explore Rust. What I'm trying to do is using glob module, when i build code with $cargo build and $cargo run it's succesfully builds and runs the executable but if i try it with $rustc main.rs it gives me
error[E0432]: unresolved import `glob`
--> src/main.rs:1:5
|
1 | use glob::glob;
| ^^^^ use of undeclared type or module `glob`
Any ideas?
Version : ╰─ rustc --version rustc 1.43.1 (8d69840ab 2020-05-04)
Code is here:
use glob::glob;
fn main() {
for entry in glob("/home/user/*.jpg").unwrap(){
match entry {
Ok(path) => println!("{:?}", path.display()),
Err(e) => println!("{:?}",e),
}
};
}
My toml
[package]
name = "test1"
version = "0.1.0"
authors = ["ieuD <example#mail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
glob = "0.3.0"
rustc on its own doesn't handle your dependencies, it just compiles stuff. When you run rustc on your file, it will start compiling it and encounter the unknown glob crate. Dependencies are handled by cargo via Cargo.toml.
Though you could only use rustc (see the answer here) it's a task that's considerably more difficult, that's why cargo is around.

"Failed to parse manifest" when compiling rustc using a locally-modified copy of the libc crate

I need to build the rustc compiler using a modified libc crate. I cloned the libc directory and made the changes, now how do I include the modified libc in my build?
This is my Cargo.toml
[patch.crates-io]
# Similar to Cargo above we want the RLS to use a vendored version of `rustfmt`
# that we're shipping as well (to ensure that the rustfmt in RLS and the
# `rustfmt` executable are the same exact version).
rustfmt-nightly = { path = "src/tools/rustfmt" }
# See comments in `src/tools/rustc-workspace-hack/README.md` for what's going on
# here
rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }
# See comments in `tools/rustc-std-workspace-core/README.md` for what's going on
# here
rustc-std-workspace-core = { path = 'src/tools/rustc-std-workspace-core' }
rustc-std-workspace-alloc = { path = 'src/tools/rustc-std-workspace-alloc' }
rustc-std-workspace-std = { path = 'src/tools/rustc-std-workspace-std' }
libc = {path = "../libc"}
[patch."https://github.com/rust-lang/rust-clippy"]
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
[dependencies]
# libc = {verion = "0.2", default-features= false, path = "../libc"}
This is the error I get:
mahto#hydlnxeng27:/local/mnt/workspace/mahto/rust$ ./x.py build --config config.toml src/libstd 2>&1 | tee build.log
Updating only changed submodules
Submodules updated in 0.04 seconds
error: failed to parse manifest at `/local/mnt/workspace/mahto/rust/Cargo.toml`
Caused by:
virtual manifests do not specify [dependencies]
failed to run: /local/mnt/workspace/mahto/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /local/mnt/workspace/mahto/rust/src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:00:00
After commenting-out the dependencies section in Cargo.toml, I get this new error:
error[E0433]: failed to resolve: unresolved import
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `libc`.

nixos: my custom package derivation fails on `cargo build`

I'm writing a package derivation to install kryptco/kr and it fails on cargo build phase.
kryptco/kr has a submodule kryptco/sigchain which is written by rust.
In the Makefile of kryptco/sigchain, they use the cargo web deploy command to build its submodule. My package deriation fails on this cargo web deploy phase.
These two errors were given.
error: warning: replace for the non root package will be ignored, specify replace at the workspace root:
package: /build/src/github.com/kryptco/kr/sigchain/sigchain_client/Cargo.toml
workspace: /build/src/github.com/kryptco/kr/sigchain/Cargo.toml
error: failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
[6] Couldn't resolve host name; class=Net (12)
The former error says to edit Cargo.toml and add [replace] section, but I want to avoid edit source code if I can.
What is the cause of these error?
This is my package derivation:
# Original: https://github.com/bogsen/nixos-public/blob/a0dc497eab5de528ce3006d\
36c52bc601422cf87/pkgs/krypton/default.nix
{ config, lib, pkgs, ... }: with lib; let
cfg = config.services.krypton;
cargoWeb = with pkgs; rustPlatform.buildRustPackage rec {
...
};
dependencies = with pkgs; [
cargo
emscripten
go
makeWrapper
perl
];
kr = pkgs.stdenv.mkDerivation {
name = "kr";
src = pkgs.fetchFromGitHub {
owner = "kryptco";
repo = "kr";
rev = "2.4.10";
sha256 = "1xxhlkcw2d52q1y4h40iyvq25804w7hzv0lflqnib68aps491xnj";
fetchSubmodules = true;
};
buildInputs = dependencies ++ [cargoWeb];
dontBuild = true;
postUnpack = ''
# prevent referring /homeless-shelter
export HOME=$(pwd)
# https://github.com/kryptco/kr/issues/254#issuecomment-464890476
sed -i.bak -e '8,11d' source/sigchain/Cargo.toml
export GOPATH=$(pwd)
export GOCACHE=$GOPATH/.cache/go-build
mkdir -p src/github.com/kryptco
mv source src/github.com/kryptco/kr
ln -s src/github.com/kryptco/kr source
'';
postPatch = ''
substituteInPlace Makefile --replace sudo ""
'';
makeFlags = [ "PREFIX=$(out)" ];
};
in {
config = {
nixpkgs.config.packageOverrides = pkgs: { kr = kr; };
};
}
And whole error message is here.
# use rsync so that file modifed times are only updated when the contents change
cd dashboard_yew && cargo web deploy --release --target=wasm32-unknown-emscripten && rsync --checksum --delete -r ../target/deploy/* ../target/deploy-final
error: warning: replace for the non root package will be ignored, specify replace at the workspace root:
package: /build/src/github.com/kryptco/kr/sigchain/sigchain_client/Cargo.toml
workspace: /build/src/github.com/kryptco/kr/sigchain/Cargo.toml
Updating crates.io index
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name; class=Net (12)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name; class=Net (12)
error: failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
[6] Couldn't resolve host name; class=Net (12)
make[1]: *** [Makefile:25: libsigchain-with-dashboard] Error 101
make[1]: Leaving directory '/build/src/github.com/kryptco/kr/sigchain'
make: *** [Makefile:71: all] Error 2
builder for '/nix/store/78r0kh34ljzgfx658f9n99f8lxydjfxy-kr.drv' failed with exit code 2
I don't think you'll get around the [replace] edit for the config files. The build failing at cargo web deploy is due to an outdated version of openssl-sys (which is discontinued). Here's how Parity fixed it. Looks like they edited the Cargo.lock file to depend on newer versions of this lib.
You need to make it a fixed-output path, for this take a look at nix-pills.

Resources