From: Kirill A. Korinsky Subject: Re: lang/rust: migrate to getexecpath() To: Sebastien Marie Cc: OpenBSD ports Date: Fri, 04 Sep 2026 08:34:12 +0200 On Fri, 04 Sep 2026 08:17:19 +0200, Sebastien Marie wrote: > > Kirill A. Korinsky writes: > > > Sebastien, > > > > I'd like to migrate our rust to use of getexecpath(), it should allow to > > drop a lot of patches to remove usage of current_exe() > > > > I plan to upstream it as soon as 8.0 is released. > > > > Briefly tested on -current/amd64 > > > > Ok? > > Several comments: > > - the diff is almost fine for ports (it would also need > _SYSTEM_VERSION-rust bump too, as it modifies libstd which is > statically compiled in all rust ports) > > - but the diff is *not* fine for upstream. getexecpath() should be > introduced via libc rust crate. > > Please also note it would be fine if we synchronize as 1.98.1 has been > released and I would like to commit it soon. I would permit to avoid > bumping twice in a row the whole rust ecosystem in ports. > Sure, just include it into your update. And yes, it is not right diff for upstream, but adding it to libc and all friends in ports seems wrong. > Regards. > > > Index: Makefile > > =================================================================== > > RCS file: /home/cvs/ports/lang/rust/Makefile,v > > diff -u -p -r1.252 Makefile > > --- Makefile 26 Aug 2026 17:25:14 -0000 1.252 > > +++ Makefile 3 Sep 2026 20:49:45 -0000 > > @@ -13,6 +13,7 @@ COMMENT-bootstrap = Rust binary bootstra > > COMMENT-src = Rust source component > > > > V = 1.98.0 > > +REVISION = 0 > > DISTNAME = rustc-${V}-src > > > > # always keep REVISION-bootstrap in sync with REVISION-main (if defined) > > Index: patches/patch-library_std_src_sys_paths_unix_rs > > =================================================================== > > RCS file: /home/cvs/ports/lang/rust/patches/patch-library_std_src_sys_paths_unix_rs,v > > diff -u -p -r1.1 patch-library_std_src_sys_paths_unix_rs > > --- patches/patch-library_std_src_sys_paths_unix_rs 3 Jun 2026 11:15:20 -0000 1.1 > > +++ patches/patch-library_std_src_sys_paths_unix_rs 3 Sep 2026 20:48:28 -0000 > > @@ -1,21 +1,37 @@ > > -argv0 isn't suitable as current_exe() in all cases. > > +Implement support of getexecpath() > > > > Index: library/std/src/sys/paths/unix.rs > > --- library/std/src/sys/paths/unix.rs.orig > > +++ library/std/src/sys/paths/unix.rs > > -@@ -240,13 +240,13 @@ pub fn current_exe() -> io::Result { > > - cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, &mut argv_len, ptr::null_mut(), 0))?; > > - argv.set_len(argv_len as usize); > > - if argv[0].is_null() { > > +@@ -231,23 +231,15 @@ pub fn current_exe() -> io::Result { > > + > > + #[cfg(target_os = "openbsd")] > > + pub fn current_exe() -> io::Result { > > ++ unsafe extern "C" { > > ++ fn getexecpath(buf: *mut c_char, bufsize: libc::size_t) -> c_int; > > ++ } > > ++ > > ++ let mut path = vec![0; libc::PATH_MAX as usize]; > > + unsafe { > > +- let mut mib = [libc::CTL_KERN, libc::KERN_PROC_ARGS, libc::getpid(), libc::KERN_PROC_ARGV]; > > +- let mib = mib.as_mut_ptr(); > > +- let mut argv_len = 0; > > +- cvt(libc::sysctl(mib, 4, ptr::null_mut(), &mut argv_len, ptr::null_mut(), 0))?; > > +- let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize); > > +- cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, &mut argv_len, ptr::null_mut(), 0))?; > > +- argv.set_len(argv_len as usize); > > +- if argv[0].is_null() { > > - return Err(io::const_error!(io::ErrorKind::Uncategorized, "no current exe available")); > > -+ return Err(io::const_error!(io::ErrorKind::Uncategorized, "no current exe available (null)")); > > - } > > - let argv0 = CStr::from_ptr(argv[0]).to_bytes(); > > - if argv0[0] == b'.' || argv0.iter().any(|b| *b == b'/') { > > - crate::fs::canonicalize(OsStr::from_bytes(argv0)) > > - } else { > > +- } > > +- let argv0 = CStr::from_ptr(argv[0]).to_bytes(); > > +- if argv0[0] == b'.' || argv0.iter().any(|b| *b == b'/') { > > +- crate::fs::canonicalize(OsStr::from_bytes(argv0)) > > +- } else { > > - Ok(PathBuf::from(OsStr::from_bytes(argv0))) > > -+ Err(io::const_error!(io::ErrorKind::Uncategorized, "no current exe available (short)")) > > - } > > +- } > > ++ cvt(getexecpath(path.as_mut_ptr(), path.len()))?; > > ++ let path = CStr::from_ptr(path.as_ptr()).to_bytes(); > > ++ Ok(PathBuf::from(OsStr::from_bytes(path))) > > } > > } > > + > -- > Sebastien Marie > -- wbr, Kirill