Rust .exe fails to open on Windows - rust

I'm building an app with rust. Using --cargo run --release successfully compiles the app and runs it, bringing up the GUI window for the app. However, when I manually open target/release/MyApp.exe, nothing happens. Checked when myapp.exe was last modifies shows that running --cargo run --release is updating the app.
I'm on windows 10 so I added "x86_64-pc-windows-msvc" as the build target.
[package]
name = "MuTexAlpha"
version = "0.1.0"
authors = ["Webb Hinton <wyhinton189#gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
fltk = "0.15.1"
serde = "1.0.118"
texture-synthesis = "0.8.0"
rand = "0.7.3"
num_cpus = "1.13.0"
uuid = { version = "0.8", features = ["serde", "v4"] }
image = "0.23.12"
glob = "0.3.0"
dyn-clone = "1.0.4"
colored = "2.0.0"
arboard = "1.1.0"
id_tree = "1.7.0"
id_tree_layout = "2.0.1"
typetag = "0.1"
serde_json = "1.0.61"
snafu = "0.6.10"
palette = "0.5.0"
indicatif = "0.14.0"
[build]
target = "x86_64-pc-windows-msvc"
Isn't the .exe in release the same program being executed with --cargo run --release?
I have some file dependencies in my app, might this be the cause of the issue? (compiling the app gives no errors, however)
Could this be something specifically related to windows?

Might just be a shot in the dark, but are you opening the exe using Windows Explorer?
Open up a cmd.exe window and try running it from there.

Related

Problem trying to convert a rust project into a rust workspace

I am trying to create a rust workspace, having multiple binaries to build from same project
Actually I prepared structure as follow
Where external Cargo.tml contains only
[workspace]
members = ["itris-console", "autolearn" ]
And itris-console/Cargo.toml contains
[package]
name = "itris"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"
arr_macro = "0.1.3"
[[bin]]
name = "itris"
path = "src/main.rs"
test = false
bench = false
And autolearn/Cargo.toml is
[package]
name = "autolearn"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
I am trying to build it all from project root (the itris2 directory)
I got this problem
cargo build
error: failed to load manifest for workspace member `C:\Progetti\rust\itris2\itris-console`
Caused by:
failed to read `C:\Progetti\rust\itris2\itris-console\Cargo.toml`
Caused by:
Impossibile trovare il percorso specificato. (os error 3)
I consulted what follows but I cannot make it works
https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries
https://stackoverflow.com/a/57630418/1055279
The itris-console and autolearn directories should not be in a src directory.
Currently path to your itris-console directory is C:\Progetti\rust\itris2\src\itris-console while it should be C:\Progetti\rust\itris2\itris-console. Remove the unnecessary src directory from the path and you are almost good to go.
Since you are on windows you also need to use escaped forward-slashes while defining the path to the bin in itris-console\Cargo.toml ("src/main.rs" -> "src\\main.rs").

Run code with cargo run on Raspberry Pi Pico using elf2uf2-rs

I try to run Rust code on a Raspberry Pi Pico. A simple "blink" example application is successfully (as it seems) built using:
cargo build --release --target=thumbv6m-none-eabi
I have installed elf2uf2-rs with:
cargo install elf2uf2-rs
And I then try to run the blink application on the Raspberry Pi Pico using:
cargo run --release --target=thumbv6m-none-eabi
but it fails with this message, where "rp2" is the name of my binary:
target/thumbv6m-none-eabi/release/rp2: cannot execute binary file
Any suggestions on what can be wrong?
This is my Cargo.toml:
[package]
name = "rp2"
version = "0.1.0"
edition = "2021"
[dependencies]
rp2040-hal = "0.3.0"
cortex-m = "0.7.2"
embedded-hal = { version = "0.2.5", features = ["unproven"] }
eh1_0_alpha = { version="=1.0.0-alpha.6", package="embedded-hal", optional=true }
embedded-time = "0.12.0"
panic-halt = "0.2.0"
rp2040-boot2 = "0.2.0"
cortex-m-rt = "0.7"
rp-pico = "0.2.0"
[dev-dependencies]
cortex-m-rt = "0.7"
panic-halt = "0.2.0"
rp2040-boot2 = "0.2.0"
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
Update
I now added a file .cargo/config.toml with this content:
# Choose a default "cargo run" tool.
# probe-run is recommended if you have a debugger
# elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# runner = "probe-run --chip RP2040"
runner = "elf2uf2-rs -d"
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# Code-size optimizations.
# trap unreachable can save a lot of space, but requires nightly compiler.
# uncomment the next line if you wish to enable it
# "-Z", "trap-unreachable=no",
"-C", "inline-threshold=5",
"-C", "no-vectorize-loops",
]
[build]
target = "thumbv6m-none-eabi"
and a memory.x file with this content:
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
RAM : ORIGIN = 0x20000000, LENGTH = 256K
}
EXTERN(BOOT2_FIRMWARE)
SECTIONS {
/* ### Boot loader */
.boot2 ORIGIN(BOOT2) :
{
KEEP(*(.boot2));
} > BOOT2
} INSERT BEFORE .text;
but then the cargo build --release command fails with this error:
error: linking with `rust-lld` failed: exit status: 1
...
= note: rust-lld: error: cannot find linker script defmt.x
I use a MacBook with M1 Apple Silicon chip, this might be a related issue rust-lld problem under AArch64 system.
I have now got the code running on the Raspberry Pi Pico.
The first problem was that I hadn't created the .cargo/config.toml file that contains the instruction to "run" with elf2uf2:
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs -d"
The other problem was that my .cargo/config.toml also contained this reference to defmt that I didn't have on my system, so when commenting out this line (under rustflags), the code compiled with cargo build --release and it was run on the Raspberry Pi Pico with cargo run --release:
# "-C", "link-arg=-Tdefmt.x",

How to change the app name but not library name of a package?

In Rust, I created one package and now I want to change only output app name without changing package name.
Below is the content of Cargo.toml file:
[package]
authors = ["Rust exam"]
edition = "2021"
name = "rust-exam"
description = "Rebuilt for Scale"
version = "1.10.0"
license = "Apache-2.0"
[dependencies]
base64 = "0.12.3"
clap = "2.33.1"
serde = "1.0.132"
serde_json = "1.0.73"
serde_yaml = "0.8.23"
tempfile = "3.2.0"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
When I input cargo build, it makes rust-exam and librust-exam.
I want to only change rust-exam, not change package name. How can I do that?
You can configure the app name like so:
[[bin]]
name = "rust-output"
path = "src/main.rs"

include toml file from another toml

I am trying to include a second toml file from Cargo.toml file.
I don't known how to do that and i don't known do this is possible.
I am trying this:
Cargo.toml:
[package]
name = "toml"
authors = "TANDEX"
version = "0.0.0"
include = ["libs.toml"]
libs.toml:
[dependencies]
termion = "0.9.8"
and this:
Cargo.toml:
include = ["libs.toml"]
[package]
name = "toml"
authors = ["TANDEX"]
version = "0.0.0"
libs.toml:
[dependencies]
termion = "0.9.8"
Both of them don't works.
For information I want to automatically generate one file by script and the `Cargo.toml` leave normal.

Cargo can't parse the Cargo.toml for url version 0.5.7

I encountered a problem when running cargo build:
/usr/local/bin/cargo build --color=always
error: unable to get packages from source
Caused by:
failed to parse manifest at `/home/lzc/.multirust/toolchains/stable/cargo/registry/src/github.com-1ecc6299db9ec823/url-0.5.7/Cargo.toml`
Caused by:
could not parse input as TOML
Caused by:
expected newline, found an identifier at line 14
I found this issue on GitHub, but it didn't solve my problem.
This is my project Cargo.toml:
[dependencies]
hyper = "0.7.2"
rustc-serialize = "0.3"
websocket = "0.15.1"
And my rustc and cargo version:
➜ ~ cargo -V
cargo 0.18.0 (fe7b0cdcf 2017-04-24)
➜ ~ rustc -V
rustc 1.17.0 (56124baa9 2017-04-24)
And here is the file Cargo complains about(/home/lzc/.multirust/toolchains/stable/cargo/registry/src/github.com-1ecc6299db9ec823/url-0.5.7/Cargo.toml):
[package]
name = "url"
version = "0.5.7"
authors = [ "Simon Sapin <simon.sapin#exyr.org>" ]
description = "URL library for Rust, based on the WHATWG URL Standard"
documentation = "http://servo.github.io/rust-url/url/index.html"
repository = "https://github.com/servo/rust-url"
readme = "README.md"
keywords = ["url", "parser"]
license = "MIT/Apache-2.0"
[[test]] name = "format" #<- line 14
[[test]] name = "form_urlencoded"
[[test]] name = "idna"
[[test]] name = "punycode"
[[test]] name = "tests"
[[test]]
name = "wpt"
harness = false
[dev-dependencies]
rustc-test = "0.1"
[features]
query_encoding = ["encoding"]
serde_serialization = ["serde"]
heap_size = ["heapsize", "heapsize_plugin"]
[dependencies.heapsize]
version = ">=0.1.1, <0.4"
optional = true
[dependencies.heapsize_plugin]
version = "0.1.0"
optional = true
[dependencies.encoding]
version = "0.2"
optional = true
[dependencies.serde]
version = ">=0.6.1, <0.8"
optional = true
[dependencies]
uuid = "0.1.17"
rustc-serialize = "0.3"
unicode-bidi = "0.2.3"
unicode-normalization = "0.1.2"
matches = "0.1"
As listed in the url crate's GitHub issue, it previously used a form of TOML that was actually invalid. Newer versions of Cargo no longer parse that invalid form.
Nothing in your shown dependency list requires url version 0.5.7. url version 0.5.10 has been released, so perform a cargo update to switch to it. Note that 0.5.10 was published on Aug 21, 2016, so it's almost a year old at this point.

Resources