railcar icon indicating copy to clipboard operation
railcar copied to clipboard

Unable to build on armv7 device

Open DazWilkin opened this issue 7 years ago • 2 comments

I'm entirely unfamiliar with Rust (!) but was intrigued to try building railcar on an armv7 device.

If I'm headed down a dead-end, please let me know.

During the build, I'm encountering 2 errors:

  • CAPGET|CAPSET not found in caps-rs: https://github.com/lucab/caps-rs/issues/2
  • incorrect u_longlong with libc (!?) on armv7 (below)
error[E0308]: mismatched types
  --> src/nix_ext.rs:46:19
   |
46 |         rlim_cur: soft,
   |                   ^^^^ expected u32, found u64
   |
   = help: here are some functions which might fulfill your needs:
           - .count_ones()
           - .count_zeros()
           - .leading_zeros()
           - .trailing_zeros()

error[E0308]: mismatched types
  --> src/nix_ext.rs:47:19
   |
47 |         rlim_max: hard,
   |                   ^^^^ expected u32, found u64
   |
   = help: here are some functions which might fulfill your needs:
           - .count_ones()
           - .count_zeros()
           - .leading_zeros()
           - .trailing_zeros()

error: aborting due to 2 previous errors

error: Could not compile `railcar`.

This second issue may be a consequence of (my solution to) the first? The armv7 is 32-bit not 64-bit and, IIUC, libc:c_ulonglong is (defaulting) to 64-bit

nix_ext.rs:

#[inline]
pub fn setrlimit(
    resource: libc::c_int,
    soft: libc::c_ulonglong,
    hard: libc::c_ulonglong,
) -> Result<()> {
    let rlim = &libc::rlimit {
        rlim_cur: soft,
        rlim_max: hard,
    };
    let res = unsafe { libc::setrlimit(resource, rlim) };
    Errno::result(res).map(drop)
}

Installation

curl https://sh.rustup.rs -sSf | sh
cargo install cargo-when
rustup toolchain install stable-armv7-unknown-linux-gnueabihf
rustup default stable-armv7-unknown-linux-gnueabihf
git clone https://github.com/oracle/railcar.git
cd railcar
TARGET=armv7-unknown-linux-gnueabihf ./build.sh

Configuration

cargo --version
cargo 0.19.0 (28d1d60d4 2017-05-16)
lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 8.8 (jessie)
Release:	8.8
Codename:	jessie
rustc --version
rustc 1.18.0 (03fc9d622 2017-06-06)

Aside: I tried using armv7-unknown-linux-musleabihf but realize that target is effectively not available

DazWilkin avatar Jul 09 '17 19:07 DazWilkin

Hi. Very cool that you are trying this. I have not ever compiled any rust code for arm so I have no idea how far you will get. It looks like you could make an alternative implementation of setrlimit with different types for arm. It could be protected by a cfg checking the architecture similarly to how we have two implementations of putenv.

vishvananda avatar Jul 10 '17 02:07 vishvananda

Thanks for the reply!

I was successful with only minor, wonky hacking involved ;-)

src/nix_ext.rs:

42: soft: u32,
43: hard: u32,

src/main.rs:

1061: setrlimit(rlimit.typ as i32, rlimit.soft as u32, rlimit.hard as u32)?;

Then:

TARGET=armv7-unknown-linux-gnueabihf ./build.sh
       Fresh cfg-if v0.1.2
       Fresh serde v0.9.15
       Fresh void v1.0.2
       Fresh unicode-xid v0.0.4
       Fresh quote v0.3.15
       Fresh itoa v0.3.1
       Fresh log v0.3.8
       Fresh num-traits v0.1.39
       Fresh getopts v0.2.14
       Fresh rustc-demangle v0.1.4
       Fresh libc v0.2.26
       Fresh enum_derive v0.1.7
       Fresh bitflags v0.7.0
       Fresh lazy_static v0.2.8
       Fresh scopeguard v0.3.2
       Fresh gcc v0.3.51
       Fresh dtoa v0.4.1
       Fresh synom v0.11.3
       Fresh seccomp-sys v0.1.2
       Fresh custom_derive v0.1.7
       Fresh nix v0.8.1
       Fresh serde_json v0.9.10
       Fresh syn v0.11.11
       Fresh prctl v1.0.0
       Fresh serde_codegen_internals v0.14.2
       Fresh backtrace-sys v0.1.11
       Fresh serde_derive v0.9.15
       Fresh backtrace v0.3.2
       Fresh oci v0.1.0 (file:///root/railcar/oci)
       Fresh error-chain v0.10.0
       Fresh error-chain v0.8.1
       Fresh caps v0.0.1
   Compiling railcar v0.1.0 (file:///root/railcar)
     Running `rustc --crate-name railcar src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=5752f99c0cbe481e -C extra-filename=-5752f99c0cbe481e --out-dir /root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps --target armv7-unknown-linux-gnueabihf -L dependency=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps -L dependency=/root/railcar/target/debug/deps --extern prctl=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/libprctl-863e0faec48aeddc.rlib --extern log=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/liblog-8bfc22ae92af9303.rlib --extern seccomp_sys=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/libseccomp_sys-07f1ac3db5af0136.rlib --extern lazy_static=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/liblazy_static-ac885201a6a9ce28.rlib --extern nix=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/libnix-29eefe77698812ea.rlib --extern scopeguard=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/libscopeguard-c3c32272f0a8e612.rlib --extern num_traits=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/libnum_traits-0befceedb1d7da35.rlib --extern libc=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/liblibc-7d398f5f7f488669.rlib --extern caps=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/libcaps-e4b415ff3969f9eb.rlib --extern error_chain=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/liberror_chain-5493a0039e331fd7.rlib --extern getopts=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/libgetopts-678d72fbddce3f43.rlib --extern oci=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/deps/liboci-9f5882ad5e093512.rlib -L native=/root/railcar/target/armv7-unknown-linux-gnueabihf/debug/build/backtrace-sys-a6eb48af1cf084d7/out/.libs`
    Finished dev [unoptimized + debuginfo] target(s) in 36.9 secs

and:

./railcar
Usage: railcar [options] <command> <container-id> [bundle-dir='.']

Next challenge is to generate a rootfs without Docker and without another armv7 device

DazWilkin avatar Jul 10 '17 04:07 DazWilkin