Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ARM #9

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
2 participants
@Razican
Copy link

Razican commented Jan 20, 2016

I added support for ARM, since the build would fail. It would be great if you could add this change to the crates.io release, thanks!

Note: of course it continues building perfectly in other platforms :)

@@ -55,7 +55,7 @@ impl TTYPort {
Err(_) => return Err(super::error::from_raw_os_error(EINVAL))
};

let fd = unsafe { libc::open(cstr.as_ptr(), O_RDWR | O_NOCTTY | O_NONBLOCK, 0) };
let fd = unsafe { libc::open(cstr.as_ptr() as *const c_char, O_RDWR | O_NOCTTY | O_NONBLOCK, 0) };

This comment has been minimized.

@dcuddeback

dcuddeback Jan 21, 2016

Owner

That's odd. CString::as_ptr() is supposed to return a *const c_char: http://doc.rust-lang.org/std/ffi/struct.CString.html#method.as_ptr. The cast shouldn't be necessary.

@dcuddeback

This comment has been minimized.

Copy link
Owner

dcuddeback commented Jan 21, 2016

@Razican This is an odd one. I've been cross-compiling this for armv6 on Linux (Raspberry Pi) for a while. It almost looks like there are two competing versions of libc. Which version of rustc are you compiling with and what was the error message? Do you have libc as a dependency in your project's Cargo.toml as well? If so, which version?

I'm not sure what's going on with AppVeyor. The build failure doesn't seem related to your change.

@Razican

This comment has been minimized.

Copy link
Author

Razican commented Jan 21, 2016

The issue was the one here: https://users.rust-lang.org/t/solved-issues-using-serial-library-in-arm/4357/2

It could be due to competing libc versions, since wiringpi (a library I was using too) was using libc 0.1. In any case, this should be prevented :/

@dcuddeback

This comment has been minimized.

Copy link
Owner

dcuddeback commented Jan 23, 2016

@Razican Thanks for reporting this. I spent some time digging into the compilation error and tracked it down to an incompatibility between the libc crate and the standard library that ships with the Rust compiler.

The issue is that both libc and libstd define types for c_char. The libc source code is actually included as a Git submodule in Rust's codebase, so the version of libc used by libstd is locked during compilation of the standard library. It appears that the standard library that comes with Rust 1.5 is compatible with libc v0.1 and the version that comes with Rust 1.6 is compatible with libc v0.2.

You can see this by comparing compilation of serial v0.3.0 and v0.3.2 with both versions of the Rust compiler. On Rust 1.5, v0.3.0 compiles fine and v0.3.2 has the compilation error that you reported:

rust15-cross:serial-rs ((v0.3.0)) $ cargo clean && cargo build --target=arm-unknown-linux-gnueabihf
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling libc v0.1.12
   Compiling libc v0.2.5
   Compiling termios v0.2.1
   Compiling ioctl-rs v0.1.4
   Compiling serial v0.3.0 (file:///home/david/src/serial-rs)

rust15-cross:serial-rs ((v0.3.2)) $ cargo clean && cargo build --target=arm-unknown-linux-gnueabihf
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling libc v0.2.5
   Compiling termios v0.2.1
   Compiling ioctl-rs v0.1.4
   Compiling serial v0.3.2 (file:///home/david/src/serial-rs)
src/posix/tty.rs:58:38: 58:51 error: mismatched types:
 expected `*const u8`,
    found `*const i8`
(expected u8,
    found i8) [E0308]
src/posix/tty.rs:58         let fd = unsafe { libc::open(cstr.as_ptr(), O_RDWR | O_NOCTTY | O_NONBLOCK, 0) };
                                                         ^~~~~~~~~~~~~
src/posix/tty.rs:58:38: 58:51 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Could not compile `serial`.

To learn more, run the command again with --verbose.

On Rust 1.6, the results are reversed. v0.3.0 has the opposite compilation error (expecting i8 instead of u8) and v0.3.2 compiles correctly:

rust16-dev:serial-rs ((v0.3.0)) $ cargo clean && cargo build --target=arm-unknown-linux-gnueabihf
   Compiling libc v0.1.12
   Compiling libc v0.2.5
/home/david/.cargo/registry/src/github.com-88ac128001ac3a9a/libc-0.1.12/rust/src/liblibc/lib.rs:81:21: 81:39 warning: lint raw_pointer_derive has been removed: using derive with raw pointers is ok
/home/david/.cargo/registry/src/github.com-88ac128001ac3a9a/libc-0.1.12/rust/src/liblibc/lib.rs:81 #![allow(bad_style, raw_pointer_derive)]
                                                                                                                       ^~~~~~~~~~~~~~~~~~
   Compiling termios v0.2.1
   Compiling ioctl-rs v0.1.4
   Compiling serial v0.3.0 (file:///home/david/src/serial-rs)
src/posix/tty.rs:58:38: 58:51 error: mismatched types:
 expected `*const i8`,
    found `*const u8`
(expected i8,
    found u8) [E0308]
src/posix/tty.rs:58         let fd = unsafe { libc::open(cstr.as_ptr(), O_RDWR | O_NOCTTY | O_NONBLOCK, 0) };
                                                         ^~~~~~~~~~~~~
src/posix/tty.rs:58:38: 58:51 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Could not compile `serial`.

To learn more, run the command again with --verbose.

rust16-dev:serial-rs ((v0.3.2)) $ cargo clean && cargo build --target=arm-unknown-linux-gnueabihf
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling libc v0.2.5
   Compiling ioctl-rs v0.1.4
   Compiling termios v0.2.1
   Compiling serial v0.3.2 (file:///home/david/src/serial-rs)

To summarize:

Rust serial v0.3.0 (libc v0.1) serial v0.3.2 (libc v0.2)
1.5 Success expected u8, got i8
1.6 expected i8, got u8 Success

Ultimately, I think this is an upstream issue that should be address by Rust or Cargo. For example, if we could specify a dependency on a particular version of Rust or libstd, or if libstd declared its dependency on libc in a way that Cargo could resolve, this could be addressed as a dependency issue. For now, the compilation error that you reported is fixed by upgrading to Rust 1.6. Patching this with casts doesn't seem like a scalable solution to me, so I'm closing this PR for now in hopes that the community evolves methods for better managing libstd dependencies.

In retrospect, I probably should have bumped the version to v0.4 when I upgraded the libc dependency. I'm sorry for any inconvenience this has caused you. I hope everything else goes smoothly after upgrading to Rust 1.6.

@dcuddeback dcuddeback closed this Jan 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.