Tuesday, October 01, 2024

Re: Bug When Creating a Next.js Project on OpenBSD 7.5 and -current

Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/deno/Makefile,v
diff -u -p -r1.20 Makefile
--- Makefile 16 Sep 2024 15:21:41 -0000 1.20
+++ Makefile 30 Sep 2024 16:43:13 -0000
@@ -7,7 +7,7 @@ DPB_PROPERTIES = parallel
USE_WXNEEDED = Yes

VERSION = 1.45.5
-REVISION = 0
+REVISION = 1
HOMEPAGE = https://deno.com/runtime

DISTNAME = deno-${VERSION}
Index: patches/patch-ext_node_ops_fs_rs
===================================================================
RCS file: /cvs/ports/lang/deno/patches/patch-ext_node_ops_fs_rs,v
diff -u -p -r1.3 patch-ext_node_ops_fs_rs
--- patches/patch-ext_node_ops_fs_rs 31 Jul 2024 17:36:51 -0000 1.3
+++ patches/patch-ext_node_ops_fs_rs 30 Sep 2024 16:43:13 -0000
@@ -8,7 +8,7 @@ Index: ext/node/ops/fs.rs
- #[cfg(not(target_os = "macos"))]
+ #[cfg(not(any(
+ target_os = "macos",
-+ target_os_ = "freebsd",
++ target_os = "freebsd",
+ target_os = "openbsd"
+ )))]
// SAFETY: `cpath` is NUL-terminated and result is pointer to valid statfs memory.
Index: patches/patch-ext_node_ops_os_cpus_rs
===================================================================
RCS file: /cvs/ports/lang/deno/patches/patch-ext_node_ops_os_cpus_rs,v
diff -u -p -r1.2 patch-ext_node_ops_os_cpus_rs
--- patches/patch-ext_node_ops_os_cpus_rs 31 Jul 2024 17:36:51 -0000 1.2
+++ patches/patch-ext_node_ops_os_cpus_rs 30 Sep 2024 16:43:13 -0000
@@ -1,13 +1,54 @@
Index: ext/node/ops/os/cpus.rs
--- ext/node/ops/os/cpus.rs.orig
+++ ext/node/ops/os/cpus.rs
-@@ -294,6 +294,11 @@ pub fn cpu_info() -> Option<Vec<CpuInfo>> {
+@@ -294,6 +294,52 @@ pub fn cpu_info() -> Option<Vec<CpuInfo>> {
Some(cpus)
}

+#[cfg(target_os = "openbsd")]
+pub fn cpu_info() -> Option<Vec<CpuInfo>> {
-+ None
++ // Stub implementation for OpenBSD that returns an array of the correct size
++ // but with dummy values.
++ // Rust's OpenBSD libc bindings don't contain all the symbols needed for a
++ // full implementation.
++ let mut mib = [libc::CTL_HW, libc::HW_NCPUONLINE];
++
++ // SAFETY: Assumes correct behavior of platform-specific
++ // sysctls and data structures. Relies on specific sysctl
++ // names and parameter existence.
++ unsafe {
++ let mut ncpu: libc::c_uint = 0;
++ let mut size = std::mem::size_of_val(&ncpu) as libc::size_t;
++
++ // Get number of CPUs online
++ let res = libc::sysctl(
++ mib.as_mut_ptr(),
++ mib.len() as _,
++ &mut ncpu as *mut _ as *mut _,
++ &mut size,
++ std::ptr::null_mut(),
++ 0,
++ );
++ // If res == 0, the sysctl call was succesful and
++ // ncpu contains the number of online CPUs.
++ if res != 0 {
++ return None;
++ } else {
++ let mut cpus = vec![CpuInfo::new(); ncpu as usize];
++
++ for (_, cpu) in cpus.iter_mut().enumerate() {
++ cpu.model = "Undisclosed CPU".to_string();
++ cpu.speed = 1;
++ cpu.times.user = 1;
++ cpu.times.nice = 1;
++ cpu.times.sys = 1;
++ cpu.times.idle = 1;
++ cpu.times.irq = 1;
++ }
++
++ return Some(cpus);
++ }
++ }
+}
+
#[cfg(test)]
On 2024-09-16 18:16, Volker Schlecht wrote:
>The problem with NextJS is that nobody implemented the NodeJS os.cpus() API for
>deno on OpenBSD ... yet. I plan to, but I haven't gotten around to it.
>I'd be happy to test patches, too :-)

Attached is a patch to fix this and an inconsequential typo.
Upstream has already merged the os.cpus() implementation, but I'd like to commit
this to -stable deno, once it's available.

ok for that?

No comments:

Post a Comment