Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetBSD port #70

Open
0-wiz-0 opened this issue Sep 14, 2024 · 10 comments
Open

NetBSD port #70

0-wiz-0 opened this issue Sep 14, 2024 · 10 comments

Comments

@0-wiz-0
Copy link

0-wiz-0 commented Sep 14, 2024

I've started a NetBSD port based mostly on the FreeBSD one. My work is here.

It currently fails to build:

   Compiling sysctl v0.6.0 (sysctl-rs-fork)
error[E0425]: cannot find function `sysctlnametomib` in crate `libc`
  --> src/unix/funcs.rs:26:15
   |
26 |         libc::sysctlnametomib(
   |               ^^^^^^^^^^^^^^^ not found in `libc`

error[E0599]: no method named `is_temperature` found for struct `ctl_info::CtlInfo` in the current scope
   --> src/unix/funcs.rs:199:13
    |
199 |     if info.is_temperature() {
    |             ^^^^^^^^^^^^^^ method not found in `CtlInfo`
    |
   ::: src/ctl_info.rs:8:1
    |
8   | pub struct CtlInfo {
    | ------------------ method `is_temperature` not found for this struct

error[E0425]: cannot find function `temperature` in this scope
   --> src/unix/funcs.rs:200:16
    |
200 |         return temperature(&info, &val);
    |                ^^^^^^^^^^^ not found in this scope

The first is a problem in the libc crate which @0323pin is working on fixing.
I'm a bit confused by the other too - how do these work on other non-FreeBSD systems? I don't see is_temperature() defined except for FreeBSD, but I must have overlooked something.

@0323pin
Copy link

0323pin commented Sep 18, 2024

The first is a problem in the libc crate which @0323pin is working on fixing.

For reference, rust-lang/libc#3927

@johalun
Copy link
Owner

johalun commented Sep 18, 2024

First, I assume that NetBSD doesn't have the temperature type? If that's the case, check src/unix/funcs.rs:200 where it returns the temperature. We might have to make

    // Special treatment for temperature ctls.
    if info.is_temperature() {
        return temperature(&info, &val);
    }

only run on FreeBSD. If NetBSD does have it, we need to enable the type for NetBSD, in addition to FreeBSD.

@0-wiz-0
Copy link
Author

0-wiz-0 commented Sep 18, 2024

NetBSD provides temperature information using envsys, not sysctl. Here's some example rust code.
I was confused because I assumed that the unix code was for macOS and Linux too, and then I didn't understand why it worked on those systems.
Yes, we'll need to make this part FreeBSD-only, what's the best way to do that?

@johalun
Copy link
Owner

johalun commented Sep 18, 2024

You could try something like

    // Special treatment for temperature ctls.
    #[cfg(target_os = "freebsd")]
    if info.is_temperature() {
        return temperature(&info, &val);
    }

If this works, that's good for now. Although, I rather we test for features (like #[cfg(feature = "temperature")] or similar), than target_os all over the place but that's out of the scope for this work. Maybe something I'll work on later.

@0-wiz-0
Copy link
Author

0-wiz-0 commented Sep 18, 2024

Thanks. I just pushed a change based on your suggestion, now I'm down to the mib issue.

   Compiling sysctl v0.6.0 (/disk/storage-202004/archive/foreign/sysctl-rs-fork)
error[E0425]: cannot find function `sysctlnametomib` in crate `libc`
  --> src/unix/funcs.rs:26:15
   |
26 |         libc::sysctlnametomib(
   |               ^^^^^^^^^^^^^^^ not found in `libc`

warning: unreachable pattern
   --> src/unix/funcs.rs:227:9
    |
227 |         _ => Err(SysctlError::UnknownType),
    |         ^
    |
    = note: `#[warn(unreachable_patterns)]` on by default

For more information about this error, try `rustc --explain E0425`.
warning: `sysctl` (lib) generated 1 warning
error: could not compile `sysctl` (lib) due to 1 previous error; 1 warning emitted

so we'll have to wait to get that merged first.

@johalun
Copy link
Owner

johalun commented Sep 18, 2024

In your pull request, please also add NetBSD to Cirrus CI in the file .cirrus.yml.

@0323pin
Copy link

0323pin commented Sep 18, 2024

@0-wiz-0 you could try to apply my libc patch locally to overcome the sysctlnametomib issue.

@0-wiz-0
Copy link
Author

0-wiz-0 commented Sep 18, 2024

I don't see how to add NetBSD to the Cirrus image.
On https://cirrus-ci.org/guide/FreeBSD/ I get docs for FreeBSD and next to it for Linux and macOS.
Other project use crosscompilation:
trippy
trash-rs

@johalun
Copy link
Owner

johalun commented Sep 18, 2024

I found https://github.com/haskell/bytestring/blob/master/.cirrus.yml which uses their custom VM instances. Maybe that'll work?

https://cirrus-ci.org/guide/custom-vms/

Apparently their FreeBSD instance is already of this type

Already things like Docker Builder and freebsd_instance are basically a syntactic sugar for launching Compute Engine instances from a particular limited set of images.

@0-wiz-0
Copy link
Author

0-wiz-0 commented Sep 18, 2024

Using @0323pin 's libc and after adapting the example code, I get, for cargo test:

running 11 tests
test ctl_value::tests_unix::ctl_struct_type ... ok
test sys::ctl::tests::ctl_new ... ok
test ctl_flags::tests::ctl_flags ... FAILED
test sys::ctl_iter::tests::ctl_iter_iterate_all ... FAILED
test sys::funcs::tests::ctl_name ... FAILED
test sys::funcs::tests::name2oid_invalid_name ... ok
test ctl_value::tests_unix::ctl_value_string ... FAILED
test sys::ctl::tests::ctl_description ... FAILED
test ctl_value::tests_unix::ctl_value_int ... FAILED
test ctl_value::tests_unix::ctl_value_oid_int ... FAILED
test sys::funcs::tests::ctl_type ... FAILED

failures:

---- ctl_flags::tests::ctl_flags stdout ----
thread 'ctl_flags::tests::ctl_flags' panicked at src/ctl_flags.rs:84:50:
called `Result::unwrap()` on an `Err` value: IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- sys::ctl_iter::tests::ctl_iter_iterate_all stdout ----
thread 'sys::ctl_iter::tests::ctl_iter_iterate_all' panicked at src/unix/ctl_iter.rs:86:9:
assertion `left != right` failed
  left: 0
 right: 0

---- sys::funcs::tests::ctl_name stdout ----
thread 'sys::funcs::tests::ctl_name' panicked at src/unix/funcs.rs:869:42:
Could not get name of kern.osrevision sysctl.: IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" })

---- ctl_value::tests_unix::ctl_value_string stdout ----
thread 'ctl_value::tests_unix::ctl_value_string' panicked at src/ctl_value.rs:118:9:
assertion `left == right` failed
  left: "..."
 right: "NetBSD 10.99.12 (GENERIC) #1: Tue Sep 10 14:25:35 CEST 2024\n\[email protected]:/disk/storage-202004/archive/foreign/src/sys/arch/amd64/compile/obj/GENERIC"

---- sys::ctl::tests::ctl_description stdout ----
thread 'sys::ctl::tests::ctl_description' panicked at src/unix/ctl.rs:299:9:
assertion failed: descp.is_ok()

---- ctl_value::tests_unix::ctl_value_int stdout ----
thread 'ctl_value::tests_unix::ctl_value_int' panicked at src/ctl_value.rs:145:9:
assertion `left == right` failed
  left: 0
 right: 1099001200

---- ctl_value::tests_unix::ctl_value_oid_int stdout ----
thread 'ctl_value::tests_unix::ctl_value_oid_int' panicked at src/ctl_value.rs:162:9:
assertion `left == right` failed
  left: 0
 right: 1099001200

---- sys::funcs::tests::ctl_type stdout ----
thread 'sys::funcs::tests::ctl_type' panicked at src/unix/funcs.rs:883:39:
called `Result::unwrap()` on an `Err` value: IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" })


failures:
    ctl_flags::tests::ctl_flags
    ctl_value::tests_unix::ctl_value_int
    ctl_value::tests_unix::ctl_value_oid_int
    ctl_value::tests_unix::ctl_value_string
    sys::ctl::tests::ctl_description
    sys::ctl_iter::tests::ctl_iter_iterate_all
    sys::funcs::tests::ctl_name
    sys::funcs::tests::ctl_type

test result: FAILED. 3 passed; 8 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

error: test failed, to rerun pass `--lib`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants