Skip to content

Commit

Permalink
devel/rust-cbindgen: Fix rust errno binding.
Browse files Browse the repository at this point in the history
It looks like that rust-random/getrandom#54 has
wrongly assigned us to Darwin case.  The __error() is not libc callable
function, but rather inline helper implemented at headers level to assist
code that was using errno incorrectly.
It seems that thread_local has still not become stable feature in rust?
If this very useful language feature does not get official support soon
enough in rust, it would be trivial for us to add simple helper function
in libc using the most common __errno_location() variant out there.

Since I could not figure out how to disable -Werror on this warning when
using "extern { #[thread_local] static errno: c_int; }", just bringing
back the previous crate helper that worked (using google search).
  • Loading branch information
zrj-rimwis committed Sep 6, 2019
1 parent 77e9b84 commit e215ca9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
11 changes: 2 additions & 9 deletions ports/devel/rust-cbindgen/Makefile.DragonFly
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
#
# XXX - The current logic in Mk/Uses/cargo.mk will try to append
# LDFLAGS to RUSTFLAGS (via -C link-arg) but it turns out that as
# we don't define LDFLAGS for this port, it will pass an empty arg
# which rustc converts into "" and gcc doesn't like that. It produces
# a 'No such file or directory' error.
#
# Add a dummy argument to the $CC call so that the build succeeds.
LDFLAGS="-v"

CARGO_CRATES+= gcc-0.3.55 errno-dragonfly-0.1.1
10 changes: 10 additions & 0 deletions ports/devel/rust-cbindgen/diffs/distinfo.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- distinfo.orig 2019-08-28 19:53:49 UTC
+++ distinfo
@@ -73,3 +73,7 @@ SHA256 (rust/crates/winapi-i686-pc-windo
SIZE (rust/crates/winapi-i686-pc-windows-gnu-0.4.0.tar.gz) = 2918815
SHA256 (rust/crates/winapi-x86_64-pc-windows-gnu-0.4.0.tar.gz) = 712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f
SIZE (rust/crates/winapi-x86_64-pc-windows-gnu-0.4.0.tar.gz) = 2947998
+SHA256 (rust/crates/gcc-0.3.55.tar.gz) = 8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2
+SIZE (rust/crates/gcc-0.3.55.tar.gz) = 37262
+SHA256 (rust/crates/errno-dragonfly-0.1.1.tar.gz) = 14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067
+SIZE (rust/crates/errno-dragonfly-0.1.1.tar.gz) = 1370
37 changes: 37 additions & 0 deletions ports/devel/rust-cbindgen/dragonfly/patch-temp_errno_fixup
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--- cargo-crates/getrandom-0.1.11/Cargo.toml.intermediate 2019-09-06 14:30:19.000000000 +0000
+++ cargo-crates/getrandom-0.1.11/Cargo.toml
@@ -33,6 +33,9 @@ version = "1.0"
optional = true
package = "rustc-std-workspace-core"

+[dependencies.errno-dragonfly]
+version = "0.1.1"
+
[dependencies.log]
version = "0.4"
optional = true
--- cargo-crates/getrandom-0.1.11/src/util_libc.rs.orig 2019-08-24 23:12:51 UTC
+++ cargo-crates/getrandom-0.1.11/src/util_libc.rs
@@ -10,6 +10,7 @@ use crate::util::LazyUsize;
use crate::Error;
use core::num::NonZeroU32;
use core::ptr::NonNull;
+extern crate errno_dragonfly;

cfg_if! {
if #[cfg(any(target_os = "netbsd", target_os = "openbsd", target_os = "android"))] {
@@ -18,10 +19,13 @@ cfg_if! {
use libc::__errno_location as errno_location;
} else if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
use libc::___errno as errno_location;
- } else if #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly"))] {
+ } else if #[cfg(any(target_os = "macos", target_os = "freebsd"))] {
use libc::__error as errno_location;
} else if #[cfg(target_os = "haiku")] {
use libc::_errnop as errno_location;
+ } else if #[cfg(target_os = "dragonfly")] {
+ // soon will be use libc::__errno_location as errno_location;
+ use errno_dragonfly::errno_location;
}
}

0 comments on commit e215ca9

Please sign in to comment.