zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
20.69k stars 640 forks source link

compilation fails: `reference to packed field is unaligned` #2760

Open selfagency opened 1 year ago

selfagency commented 1 year ago

i realize you don't specifically support windows, but i thought you might be interested to know that cargo installation fails under windows due to the following error:

~ > cargo install zellij                                                                          08/31/2023 10:07:28 AM    Updating crates.io index
  Installing zellij v0.38.1
    Updating crates.io index
   Compiling proc-macro2 v1.0.66
   Compiling unicode-ident v1.0.11
   Compiling autocfg v1.1.0
   Compiling cfg-if v1.0.0
   Compiling version_check v0.9.4
   Compiling serde v1.0.188
   Compiling syn v1.0.109
   Compiling winapi v0.3.9
   Compiling once_cell v1.18.0
   Compiling thiserror v1.0.47
   Compiling windows_x86_64_msvc v0.48.5
   Compiling libc v0.2.147
   Compiling getrandom v0.2.10
   Compiling memchr v2.6.2
   Compiling value-bag v1.4.1
   Compiling crossbeam-utils v0.8.16
   Compiling ahash v0.7.6
   Compiling cc v1.0.83
   Compiling indexmap v1.9.3
   Compiling scopeguard v1.2.0
   Compiling windows-targets v0.48.5
   Compiling rustc-demangle v0.1.23
   Compiling windows-sys v0.48.0
   Compiling smallvec v1.11.0
   Compiling bitflags v1.3.2
   Compiling pin-project-lite v0.2.13
   Compiling ident_case v1.0.1
   Compiling fnv v1.0.7
   Compiling quote v1.0.33
   Compiling hashbrown v0.12.3
   Compiling rustversion v1.0.14
   Compiling num-traits v0.2.16
   Compiling rkyv v0.7.42
   Compiling syn v2.0.29
   Compiling target-lexicon v0.12.11
   Compiling seahash v4.1.0
   Compiling memoffset v0.9.0
   Compiling lazy_static v1.4.0
   Compiling futures-core v0.3.28
   Compiling rand_core v0.6.4
   Compiling more-asserts v0.2.2
   Compiling siphasher v0.3.11
   Compiling rand v0.8.5
   Compiling crossbeam-epoch v0.9.15
   Compiling proc-macro-error-attr v1.0.4
   Compiling phf_shared v0.11.2
   Compiling backtrace v0.3.69
   Compiling concurrent-queue v2.2.0
   Compiling crossbeam-channel v0.5.8
   Compiling memoffset v0.6.5
   Compiling proc-macro-error v1.0.4
   Compiling event-listener v2.5.3
   Compiling phf_generator v0.11.2
   Compiling unicode-width v0.1.10
   Compiling wasmparser v0.83.0
   Compiling futures-io v0.3.28
   Compiling waker-fn v1.1.0
   Compiling fastrand v1.9.0
   Compiling windows_x86_64_msvc v0.33.0
   Compiling parking v2.1.0
   Compiling futures-lite v1.13.0
   Compiling crossbeam-deque v0.8.3
   Compiling async-lock v2.8.0
   Compiling lock_api v0.4.10
   Compiling strsim v0.10.0
   Compiling typenum v1.16.0
   Compiling is-terminal v0.4.9
   Compiling darling_core v0.20.3
   Compiling winapi-util v0.1.5
   Compiling corosensei v0.1.4
   Compiling slab v0.4.9
   Compiling generic-array v0.14.7
   Compiling async-task v4.4.0
   Compiling semver v1.0.18
   Compiling cranelift-codegen-shared v0.82.3
   Compiling io-lifetimes v1.0.11
   Compiling cranelift-codegen-meta v0.82.3
   Compiling windows-sys v0.33.0
   Compiling async-channel v1.9.0
   Compiling polling v2.8.0
   Compiling standback v0.2.17
   Compiling atomic-waker v1.1.1
   Compiling ucd-trie v0.1.6
   Compiling fastrand v2.0.0
   Compiling rustix v0.37.23
   Compiling either v1.9.0
   Compiling proc-macro-hack v0.5.20+deprecated
   Compiling rayon-core v1.11.0
   Compiling utf8parse v0.2.1
   Compiling leb128 v0.2.5
   Compiling parking_lot_core v0.9.8
   Compiling crc32fast v1.3.2
   Compiling tempfile v3.8.0
   Compiling region v3.0.0
   Compiling errno v0.3.3
   Compiling phf_codegen v0.11.2
   Compiling ordered-float v3.9.1
   Compiling async-io v1.13.0
   Compiling nom v5.1.3
   Compiling tracing-core v0.1.31
   Compiling fallible-iterator v0.2.0
   Compiling paste v1.0.14
   Compiling rustc-hash v1.1.0
   Compiling num_cpus v1.16.0
   Compiling cranelift-entity v0.82.3
   Compiling anyhow v1.0.75
   Compiling heck v0.4.1
   Compiling stable_deref_trait v1.2.0
   Compiling byteorder v1.4.3
   Compiling os_str_bytes v6.5.1
   Compiling tinyvec_macros v0.1.1
   Compiling serde_derive v1.0.188
   Compiling thiserror-impl v1.0.47
   Compiling ptr_meta_derive v0.1.4
   Compiling rkyv_derive v0.7.42
   Compiling loupe-derive v0.1.3
   Compiling enum-iterator-derive v0.7.0
   Compiling darling_macro v0.20.3
   Compiling phf_macros v0.11.2
   Compiling ptr_meta v0.1.4
   Compiling wezterm-dynamic-derive v0.1.0
   Compiling enum-iterator v0.7.0
   Compiling tracing-attributes v0.1.26
   Compiling clap_lex v0.2.4
   Compiling darling v0.20.3
   Compiling clap_derive v3.2.25
   Compiling cranelift-codegen v0.82.3
   Compiling enumset_derive v0.8.1
   Compiling tinyvec v1.6.0
   Compiling phf v0.11.2
   Compiling cranelift-bforest v0.82.3
   Compiling pest v2.7.3
   Compiling enumset v1.1.2
   Compiling terminfo v0.7.5
   Compiling rustc_version v0.4.0
   Compiling pest_meta v2.7.3
   Compiling same-file v1.0.6
   Compiling termcolor v1.2.0
   Compiling dirs-sys v0.3.7
   Compiling atty v0.2.14
   Compiling socket2 v0.4.9
   Compiling vte_generate_state_changes v0.1.1
   Compiling hashbrown v0.11.2
   Compiling aho-corasick v1.0.5
   Compiling async-process v1.7.0
   Compiling smawk v0.3.1
   Compiling lab v0.11.0
   Compiling regex-syntax v0.7.5
   Compiling option-ext v0.2.0
   Compiling is_ci v1.1.1
   Compiling crossbeam-queue v0.3.8
   Compiling destructure_traitobject v0.2.0
   Compiling textwrap v0.16.0
   Compiling serde_json v1.0.105
   Compiling unicode-linebreak v0.1.5
   Compiling linked-hash-map v0.5.6
   Compiling memmap2 v0.5.10
   Compiling ryu v1.0.15
   Compiling const_fn v0.4.9
   Compiling ntapi v0.3.7
   Compiling windows_x86_64_msvc v0.42.2
   Compiling regex-automata v0.3.7
   Compiling itertools v0.10.5
   Compiling textwrap v0.15.2
   Compiling yaml-rust v0.4.5
   Compiling supports-color v2.0.0
   Compiling unsafe-any-ors v1.0.0
   Compiling dirs-sys v0.4.1
   Compiling csscolorparser v0.6.2
   Compiling log v0.4.20
   Compiling serde_bytes v0.11.12
   Compiling time-macros-impl v0.1.2
   Compiling blocking v1.3.1
   Compiling regalloc v0.0.34
   Compiling tracing v0.1.37
   Compiling wezterm-dynamic v0.1.0
   Compiling loupe v0.1.3
   Compiling gimli v0.26.2
   Compiling wasmer-types v2.3.0
   Compiling clap v3.2.25
   Compiling object v0.28.4
   Compiling pest_generator v2.7.3
   Compiling walkdir v2.3.3
   Compiling dirs v4.0.0
   Compiling interprocess v1.2.1
   Compiling parking_lot v0.12.1
   Compiling semver-parser v0.10.2
   Compiling rayon v1.7.0
   Compiling unicode-normalization v0.1.22
   Compiling wasmer-compiler v2.3.0
   Compiling wasmer-artifact v2.3.0
   Compiling miette-derive v5.10.0
   Compiling wasmer-vm v2.3.0
   Compiling digest v0.9.0
   Compiling block-buffer v0.9.0
   Compiling async-executor v1.5.1
   Compiling wasm-encoder v0.32.0
   Compiling wasmer-engine v2.3.0
   Compiling terminal_size v0.1.17
   Compiling time v0.1.45
   Compiling supports-hyperlinks v2.1.0
   Compiling supports-unicode v2.0.0
   Compiling filetime v0.2.22
   Compiling phf_shared v0.10.0
   Compiling backtrace-ext v0.2.1
   Compiling ordered-float v2.10.0
   Compiling time v0.2.27
   Compiling cpufeatures v0.2.9
   Compiling arrayvec v0.5.2
   Compiling percent-encoding v2.3.0
   Compiling signal-hook v0.3.17
   Compiling wasmer-compiler-cranelift v2.3.0
   Compiling opaque-debug v0.3.0
   Compiling unicode-segmentation v1.10.1
   Compiling unicode-bidi v0.3.13
   Compiling owo-colors v3.5.0
   Compiling deltae v0.3.2
   Compiling minimal-lexical v0.2.1
   Compiling itoa v1.0.9
   Compiling wezterm-color-types v0.2.0
   Compiling nom v7.1.3
   Compiling miette v5.10.0
   Compiling heck v0.3.3
   Compiling idna v0.4.0
   Compiling cranelift-frontend v0.82.3
   Compiling sha2 v0.9.9
   Compiling vte v0.10.1
   Compiling form_urlencoded v1.2.0
   Compiling serde-value v0.7.0
   Compiling phf v0.10.1
   Compiling notify v6.1.1
   Compiling chrono v0.4.28
   Compiling wast v64.0.0
   Compiling async-global-executor v2.3.1
   Compiling wasmer-engine-universal-artifact v2.3.0
   Compiling prost-derive v0.11.9
   Compiling rmp v0.8.12
   Compiling wasmer-object v2.3.0
   Compiling semver v0.11.0
   Compiling pest_derive v2.7.3
   Compiling time-macros v0.1.1
   Compiling regex v1.9.4
   Compiling wezterm-bidi v0.2.2
   Compiling serde_yaml v0.8.26
   Compiling kv-log-macro v1.0.7
   Compiling typemap-ors v1.0.0
   Compiling dirs v5.0.1
   Compiling filedescriptor v0.8.2
   Compiling derivative v2.2.0
   Compiling num-derive v0.3.3
error[E0793]: reference to packed field is unaligned
    --> C:\Users\dsieradski\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ntapi-0.3.7\src\ntexapi.rs:2783:52
     |
2783 |         *tick_count.QuadPart_mut() = read_volatile(&(*USER_SHARED_DATA).u.TickCountQuad);
     |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: packed structs are only aligned by one byte, and many modern architectures penalize unaligned field accesses
     = note: 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\dsieradski\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ntapi-0.3.7\src\ntexapi.rs:2807:25
     |
2807 |         ((read_volatile(&(*USER_SHARED_DATA).u.TickCountQuad)
     |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: packed structs are only aligned by one byte, and many modern architectures penalize unaligned field accesses
     = note: 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 vtparse v0.6.2
   Compiling which v4.4.0
For more information about this error, try `rustc --explain E0793`.
error: could not compile `ntapi` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `zellij v0.38.1`, intermediate artifacts can be found at `C:\Users\DSIERA~1\AppData\Local\Temp\cargo-install3kPK0X`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
CptFrikadel commented 1 year ago

Seems to be related to this: https://github.com/MSxDOS/ntapi/issues/19.

The error was fixed in ntapi 0.4, but one of the dependencies still uses 0.3.7

oenu commented 11 months ago

Also experiencing on Windows

endereyewxy commented 8 months ago

Also experiencing on Windows. It's wierd since cargo -i ntapi shows ntapi has been updated to 0.4.1, but Rust still uses 0.3.7 to build. cargo update doesn't help either.

endereyewxy commented 8 months ago

Solved. Turned out that I'm so dumb that I forget to add the --path . to cargo install.

abhi-k9 commented 6 months ago

@endereyewxy Can you post the entire process and commands for the workaround? Thanks!

tgross35 commented 6 months ago

I think @endereyewxy is saying that they cloned the repo then installed from that directory (--path .) rather than installing from the published version on crates.io. But I am not sure why this would make a difference.

I think the actual fix for this involves updating sysinfo, notify-debouncer-full and mio, which depend on ntapi. I opened a PR to update mio in https://github.com/zellij-org/zellij/pull/3214 which is pretty straightforward. I tried doing sysinfo too but it was more painful since it more or less requires bumping nix.