From 681b2f1a3fe4775b0ad04e9fe3fe95c78f592dfa Mon Sep 17 00:00:00 2001 From: programmingkidx Date: Thu, 5 Mar 2026 09:13:01 -0500 Subject: [PATCH] runtime: fix issues with nr_cpus() (#26679) * Statically link Macport legacy library * Handle error with sysconf() in nr_cpus * Fix formatting issue with runtime.c.v --- GNUmakefile | 2 +- vlib/runtime/runtime_nix.c.v | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index aad6d140e..1d40eefe8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -47,7 +47,7 @@ LDFLAGS += -lMacportsLegacySupport VFLAGS += -cc $(CC) VFLAGS += -cflags "$(CFLAGS)" VFLAGS += -ldflags -L$(LEGACYLIBS)/lib -VFLAGS += -ldflags -lMacportsLegacySupport +VFLAGS += -cflags $(LEGACYLIBS)/lib/libMacportsLegacySupport.a endif endif diff --git a/vlib/runtime/runtime_nix.c.v b/vlib/runtime/runtime_nix.c.v index ef61d1e7c..b5005bd10 100644 --- a/vlib/runtime/runtime_nix.c.v +++ b/vlib/runtime/runtime_nix.c.v @@ -4,7 +4,12 @@ fn C.sysconf(name i32) i64 // nr_cpus returns the number of virtual CPU cores found on the system. pub fn nr_cpus() int { - return int(C.sysconf(C._SC_NPROCESSORS_ONLN)) + mut cpus := int(C.sysconf(C._SC_NPROCESSORS_ONLN)) + if cpus < 1 { + eprintln('Warning: sysconf(_SC_NPROCESSORS_ONLN) returned -1, returning CPU count as 1') + cpus = 1 + } + return cpus } // total_memory returns total physical memory found on the system. -- 2.39.5