dalance / bsd-kvm

1 stars 0 forks source link

Build breaks on arm64 and i386 #1

Open yurivict opened 8 months ago

yurivict commented 8 months ago

On arm64 the error is:

Running `CARGO=/usr/local/bin/cargo CARGO_CRATE_NAME=bsd_kvm CARGO_MANIFEST_DIR=/wrkdirs/usr/ports/sysutils/procs/work/procs-0.14.3/cargo-crates/bsd-kvm-0.1.2 CARGO_PKG_AUTHORS='[dalance@gmail.com](mailto:dalance@gmail.com)' CARGO_PKG_DESCRIPTION='BSD Kernel Data Access Library (libkvm) binding' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=bsd-kvm CARGO_PKG_README=README.md CARGO_PKG_REPOSITORY='https://github.com/dalance/bsd-kvm' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.2 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=2 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/wrkdirs/usr/ports/sysutils/procs/work/target/release/deps:/usr/local/lib' /usr/local/bin/rustc --crate-name bsd_kvm --edition=2021 /wrkdirs/usr/ports/sysutils/procs/work/procs-0.14.3/cargo-crates/bsd-kvm-0.1.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C o
pt-level=3 -C panic=abort -C linker-plugin-lto -C codegen-units=1 -C metadata=a49964d6f87c9731 -C extra-filename=-a49964d6f87c9731 --out-dir /wrkdirs/usr/ports/sysutils/procs/work/target/aarch64-unknown-freebsd/release/deps --target aarch64-unknown-freebsd -C linker=/usr/local/llvm15/bin/clang -L dependency=/wrkdirs/usr/ports/sysutils/procs/work/target/aarch64-unknown-freebsd/release/deps -L dependency=/wrkdirs/usr/ports/sysutils/procs/work/target/release/deps --extern bsd_kvm_sys=/wrkdirs/usr/ports/sysutils/procs/work/target/aarch64-unknown-freebsd/release/deps/libbsd_kvm_sys-18fd27defc761218.rmeta --extern libc=/wrkdirs/usr/ports/sysutils/procs/work/target/aarch64-unknown-freebsd/release/deps/liblibc-3fef3e84d519faf9.rmeta --extern thiserror=/wrkdirs/usr/ports/sysutils/procs/work/target/aarch64-unknown-freebsd/release/deps/libthiserror-53aa004348e9ac9c.rmeta --cap-lints warn -C target-cpu= -C link-arg=-fstack-protector-strong`
error[E0308]: arguments to this function are incorrect
   --> /wrkdirs/usr/ports/sysutils/procs/work/procs-0.14.3/cargo-crates/bsd-kvm-0.1.2/src/lib.rs:51:13
    |
51  |             bsd_kvm_sys::kvm_openfiles(
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: expected `*const u8`, found `*const i8`
   --> /wrkdirs/usr/ports/sysutils/procs/work/procs-0.14.3/cargo-crates/bsd-kvm-0.1.2/src/lib.rs:52:17
    |
52  |                 execfile_ptr,
    |                 ^^^^^^^^^^^^
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`
note: expected `*const u8`, found `*const i8`
   --> /wrkdirs/usr/ports/sysutils/procs/work/procs-0.14.3/cargo-crates/bsd-kvm-0.1.2/src/lib.rs:53:17
    |
53  |                 corefile_ptr,
    |                 ^^^^^^^^^^^^
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`
note: expected `*mut u8`, found `*mut i8

rust-1.73.0 FreeBSD 13.2

pkubaj commented 7 months ago

For aarch64 (and also powerpc64 and powerpc64le), the problem is because those architectures use unsigned char by default, but there are lots of signed char definitions, e.g.: pub moretdname: [i8; MAXCOMLEN as usize - TDNAMLEN as usize + 1],

An example for a fix is https://github.com/PonasKovas/rlaunch/commit/2f73499553d4a14840ed4e092a0c93fe1e928c64 Basically, you need to use c_char type instead of i8.

dalance commented 7 months ago

Thank you for your suggestion. I changed from i8 to c_char. Could you try cargo test at the latest revision of this repository?

pkubaj commented 7 months ago

Better, but there are still some errors.

  1. nice is still i8 strictly. See src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs in libc crate.
  2. kvm_openfiles() function as a fifth parameter takes a c_char, but the passed errbuf is i8, which causes similar issue. I tried switching to u8 for my usecase (obviously needs to be done better, but I don't really know Rust) and bsd-kvm compiled, although procs still didn't, but let's fix this one first.
dalance commented 7 months ago

I fixed the type of nice and errbuf. Could you provide the error of procs compilation?

pkubaj commented 7 months ago
error[E0308]: mismatched types
   --> src/./columns/command.rs:111:48
    |
111 |             let comm = crate::util::i8_to_cstr(proc.curr_proc.info.comm.as_ref());
    |                        ----------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&[i8]`, found `&[u8]`
    |                        |
    |                        arguments to this function are incorrect
    |
    = note: expected reference `&[i8]`
               found reference `&[u8]`
note: function defined here
   --> src/util.rs:358:8
    |
358 | pub fn i8_to_cstr(x: &[i8]) -> Result<&std::ffi::CStr, std::ffi::FromBytesUntilNulError> {
    |        ^^^^^^^^^^ --------

error[E0308]: mismatched types
   --> src/./columns/file_name.rs:45:44
    |
45  |         let comm = crate::util::i8_to_cstr(proc.curr_proc.info.comm.as_ref());
    |                    ----------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&[i8]`, found `&[u8]`
    |                    |
    |                    arguments to this function are incorrect
    |
    = note: expected reference `&[i8]`
               found reference `&[u8]`
note: function defined here
   --> src/util.rs:358:8
    |
358 | pub fn i8_to_cstr(x: &[i8]) -> Result<&std::ffi::CStr, std::ffi::FromBytesUntilNulError> {
    |        ^^^^^^^^^^ --------

error[E0308]: mismatched types
   --> src/./columns/state.rs:125:63
    |
125 |         if (flag & libc::P_WEXIT as i64) != 0 && info.stat != libc::SZOMB as i8 {
    |                                                  ---------    ^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
    |                                                  |
    |                                                  expected because this is `u8`
    |
help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
    |
125 |         if (flag & libc::P_WEXIT as i64) != 0 && info.stat != (libc::SZOMB as i8).try_into().unwrap() {
    |                                                               +                 +++++++++++++++++++++

error[E0308]: mismatched types
   --> src/./columns/wchan.rs:48:70
    |
48  |         let raw_content = if let Ok(wmesg) = crate::util::i8_to_cstr(&proc.curr_proc.info.wmesg) {
    |                                              ----------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&[i8]`, found `&[u8; 9]`
    |                                              |
    |                                              arguments to this function are incorrect
    |
    = note: expected reference `&[i8]`
               found reference `&[u8; 9]`
note: function defined here
   --> src/util.rs:358:8
    |
358 | pub fn i8_to_cstr(x: &[i8]) -> Result<&std::ffi::CStr, std::ffi::FromBytesUntilNulError> {
    |        ^^^^^^^^^^ --------

For more information about this error, try `rustc --explain E0308`.
error: could not compile `procs` (bin "procs") due to 4 previous errors
dalance commented 7 months ago

I fixed procs: https://github.com/dalance/procs/commit/ef802bc5cb6ce83ace37d4fe82895f870570a960. Could you try it?

pkubaj commented 7 months ago

Thanks, this makes procs build on powerpc64.

dalance commented 7 months ago

I released bsd-kvm v0.1.3 and procs v0.14.4.

yurivict commented 5 months ago

@dalance Here is the fresh failure of the sysutils/procs port with bsd-kvm-0.1.4.

dalance commented 5 months ago

@yurivict I've released bsd-kvm-0.1.5. Could you try it?

yurivict commented 5 months ago

Unfortunately I don't have access to the i386 system, so I can't try it. The failures occur on the build servers.