Bug 221378 - lang/rust: libc needs to be patched after `struct kevent` change in 12-CURRENT
Summary: lang/rust: libc needs to be patched after `struct kevent` change in 12-CURRENT
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Jean-Sébastien Pédron
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-09 22:00 UTC by Jean-Sébastien Pédron
Modified: 2018-05-26 16:12 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Sébastien Pédron freebsd_committer freebsd_triage 2017-08-09 22:00:51 UTC
In r320043 (https://svnweb.freebsd.org/changeset/base/320043), `struct kevent` was modified in the following way:

    @@ -62,8 +66,9 @@
     	short		filter;		/* filter for event */
     	unsigned short	flags;
     	unsigned int	fflags;
    -	__intptr_t	data;
    +	__int64_t	data;
     	void		*udata;		/* opaque user data identifier */
    +	__uint64_t	ext[4];
     };

It means we need to patch libc's Rust version of that structure in `src/unix/bsd/freebsdlike/mod.rs`, when built on FreeBSD 12-CURRENT:

    pub struct kevent {
        pub ident: ::uintptr_t,
        pub filter: ::c_short,
        pub flags: ::c_ushort,
        pub fflags: ::c_uint,
        pub data: ::intptr_t,
        pub udata: *mut ::c_void,
    }

I don't know if it's a consequence of this problem, but the `mio` crate doesn't  work on my laptop running HEAD:

    $ cargo test
        Updating registry `https://github.com/rust-lang/crates.io-index`
       Compiling libc v0.2.29
       Compiling slab v0.3.0
       ...
        Finished dev [unoptimized + debuginfo] target(s) in 9.10 secs
         Running target/debug/deps/mio-368f23a642284461

    running 3 tests
    test sys::unix::kqueue::test_coalesce_aio ... ok
    test poll::as_raw_fd ... FAILED
    test sys::unix::kqueue::does_not_register_rw ... FAILED

    failures:

    ---- poll::as_raw_fd stdout ----
    	thread 'poll::as_raw_fd' panicked at 'assertion failed: `(left == right)` (left: `0`, right: `16384`)', src/sys/unix/kqueue.rs:117

    ---- sys::unix::kqueue::does_not_register_rw stdout ----
    	thread 'sys::unix::kqueue::does_not_register_rw' panicked at 'assertion    failed: `(left == right)` (left: `0`, right: `16384`)', src/sys/unix/kqueue.rs:117
    note: Run with `RUST_BACKTRACE=1` for a backtrace.


    failures:
        poll::as_raw_fd
        sys::unix::kqueue::does_not_register_rw

    test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out

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

This is quite problematic because important crates such as `tokio-core` or `hyper` do not work...
Comment 1 Bugzilla Automation freebsd_committer freebsd_triage 2017-08-09 22:00:51 UTC
Maintainer informed via mail
Comment 2 Jean-Sébastien Pédron freebsd_committer freebsd_triage 2017-08-10 21:52:19 UTC
A GitHub issue was opened some time ago in the Rust repository:
https://github.com/rust-lang/rust/issues/42681

And here is the pull request to the `libc` crate to support FreeBSD 12.x:
https://github.com/rust-lang/libc/pull/721

There is a second patch to the `mio` crate to know about the changes in libc:
https://github.com/dumbbell/mio/tree/support-freebsd12-abi

With those two patches, the testsuites of `mio` and `hyper` are successful on FreeBSD 10.3 and FreeBSD 12.0.
Comment 3 Heinz N. Gies 2017-09-07 19:14:11 UTC
Cloning the patched mio + libc does not compile at this point:

# git clone https://github.com/dumbbell/mio -b support-freebsd12-abi
# cd mio

edit the Cargo.tom to include the mentioned libc branch:

libc   = { git = "https://github.com/dumbbell/libc", branch = "support-freebsd12-abi" }

# cargo test
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating git repository `https://github.com/dumbbell/libc`
 Downloading lazycell v0.5.1
 Downloading net2 v0.2.31
 Downloading env_logger v0.4.3
 Downloading bytes v0.3.0
 Downloading iovec v0.1.0
 Downloading log v0.3.8
 Downloading tempdir v0.3.5
 Downloading slab v0.3.0
 Downloading cfg-if v0.1.2
 Downloading rand v0.3.16
 Downloading libc v0.2.30
   Compiling libc v0.2.30
   Compiling log v0.3.8
   Compiling lazycell v0.5.1
   Compiling libc v0.2.29 (https://github.com/dumbbell/libc?branch=support-freebsd12-abi#4bd22611)
   Compiling slab v0.3.0
   Compiling bytes v0.3.0
   Compiling cfg-if v0.1.2
   Compiling env_logger v0.4.3
   Compiling iovec v0.1.0
   Compiling net2 v0.2.31
   Compiling rand v0.3.16
   Compiling mio v0.6.10 (file:///root/mio)
error[E0308]: mismatched types
   --> src/sys/unix/tcp.rs:134:34
    |
134 |                                  slice.as_ptr(),
    |                                  ^^^^^^^^^^^^^^ expected struct `libc::iovec`, found struct `libc::unix::iovec`
    |
    = note: expected type `*const libc::iovec`
               found type `*const libc::unix::iovec`
    = help: here are some functions which might fulfill your needs:
            - .offset(...)
            - .wrapping_offset(...)

error[E0308]: mismatched types
   --> src/sys/unix/tcp.rs:149:35
    |
149 |                                   slice.as_ptr(),
    |                                   ^^^^^^^^^^^^^^ expected struct `libc::iovec`, found struct `libc::unix::iovec`
    |
    = note: expected type `*const libc::iovec`
               found type `*const libc::unix::iovec`
    = help: here are some functions which might fulfill your needs:
            - .offset(...)
            - .wrapping_offset(...)

error: aborting due to previous error(s)

error: Could not compile `mio`.
Build failed, waiting for other jobs to finish...
error: build failed
Comment 4 Jan Beich freebsd_committer freebsd_triage 2018-05-26 00:08:53 UTC
Obsolete after ports r467538 which contains https://github.com/rust-lang/libc/commit/969ad2b73cdc? If so close the bug.
Comment 5 Jean-Sébastien Pédron freebsd_committer freebsd_triage 2018-05-26 16:12:50 UTC
You're right, mio works on FreeBSD 12-CURRENT now.