JoNil / elf2uf2-rs

BSD Zero Clause License
81 stars 31 forks source link

Cannot compile? #17

Closed GitHobi closed 1 year ago

GitHobi commented 1 year ago

Hi, I tried to install elf2uf2 using the following command: cargo install elf2uf2-rs Several packages are downloaded and (successfully) compiled, but at the end I get:

 ...  
 Compiling zerocopy v0.6.1
error[E0793]: reference to packed field is unaligned
    --> C:\Users\hobi\.cargo\registry\src\github.com-1ecc6299db9ec823\ntapi-0.3.6\src\ntexapi.rs:2785:52
     |
2785 |         *tick_count.QuadPart_mut() = read_volatile(&(*USER_SHARED_DATA).u.TickCountQuad);
     |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)

error[E0793]: reference to packed field is unaligned
    --> C:\Users\hobi\.cargo\registry\src\github.com-1ecc6299db9ec823\ntapi-0.3.6\src\ntexapi.rs:2809:25
     |
2809 |         ((read_volatile(&(*USER_SHARED_DATA).u.TickCountQuad)
     |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)

   Compiling clap v3.0.0-rc.4
For more information about this error, try `rustc --explain E0793`.
error: could not compile `ntapi` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `elf2uf2-rs v1.3.7`, intermediate artifacts can be found at `C:\temp\cargo-installT72YiO`

I'm using rust 1.69.0-nightly (2023-02-22). How can I fix this issue?

Thanks

wowkster commented 1 year ago

I had this problem as well but it worked when I compiled with the stable toolchain as the default

rspeir commented 1 year ago

I'm getting the same error. I'm running the latest stable rustc 1.69.0 (84c898d65 2023-04-16)

Looks like something changed between 1.68 and 1.69

[Edit] Just submitted a PR to correct this issue. The sysinfo dependency listed in this project's Cargo.toml file requests an outdated version. I updated the version from 0.20 to 0.28. The project now compiles on my machine.

coffeenotfound commented 1 year ago

@wowkster Yes, that seems to work!

Just for reference for future people, you can run cargo +stable install elf2uf2-rs --locked (Seems to only work for 1.68 and below)

super-saturn commented 1 year ago

Same issue, the +stable option does not solve it. Now that 1.69.0 is live it seems only @rspeir 's solution works.

vallentin commented 1 year ago

As long as @rspeir keeps the repository up, then alternatively elf2uf2-rs can be installed by doing:

cargo install --git https://github.com/rspeir/elf2uf2-rs --branch branch2
Finomnis commented 1 year ago

A quick workaround until it is fixed properly:

rustup toolchain add 1.68.0
cargo +1.68.0 install elf2uf2-rs

Notice that it builds, but prints a warning:

warning: the following packages contain code that will be rejected by a future version of Rust: ntapi v0.3.7
schmettow commented 1 year ago

+1 I found an explanation here: https://stackoverflow.com/questions/70551050/run-code-with-cargo-run-on-raspberry-pi-pico-using-elf2uf2-rs

hlavaatch commented 1 year ago

You need to update the sysinfo dependency to 0.29, that solves this. While at it, do cargo update of the other deps ;)

hlavaatch commented 1 year ago

Here is how to build it until the dependency is fixed:

git clone https://github.com/JoNil/elf2uf2-rs.git
cd elf2uf2-rs
cargo add sysinfo@0.29
cargo install --path .
JoNil commented 1 year ago

Should work now with the newly published version :)