Skip to content

Add Rust compiler to build images

Stan Hu requested to merge sh-add-rustc into master

This adds rustc in preparation for Rust-related work:

  1. Rust port of prometheus-client-mmap: gitlab-org/ruby/gems/prometheus-client-mmap!79 (closed)
  2. Other gems like commonmarker: &10074
  3. Ruby 3.2's YJIT

If we want to use a Rust extension with Ruby, we'll need to install libclang-dev since rb-sys uses bindgen, which depends on clang: https://rust-lang.github.io/rust-bindgen/requirements.html

Testing

$ docker run -it registry.gitlab.com/gitlab-org/gitlab-omnibus-builder/staging/ubuntu_20.04_fips:sh-add-rustc bash
root@3d602633a3d5:/# rustc --version
rustc 1.65.0 (897e37553 2022-11-02)
root@3d602633a3d5:/# cargo --version
cargo 1.65.0 (4bc8f24d3 2022-10-20)

With this Gemfile:

source 'https://rubygems.org'

gem 'oxi-test', git: 'https://github.com/oxidize-rb/oxi-test.git'

Run bundle install.

On CentOS 7, you need to use the devtoolset clang:

export PATH=/opt/rh/llvm-toolset-7/root/bin:$PATH
export LIBCLANG_PATH=/opt/rh/llvm-toolset-7/root/usr/lib64

On SLES 12p5, you need to export BINDGEN_EXTRA_CLANG_ARGS to include the clang paths:

export BINDGEN_EXTRA_CLANG_ARGS=-I/usr/lib64/clang/7.0.1/include

Limitations

I should note under QEMU the Rust compilation for the gem above doesn't seem to work for Raspberry Pi:

cargo rustc  --manifest-path /root/oxi-test/ext/Cargo.toml --target-dir /root/oxi-test/target --lib --release -- -C linker=arm-linux-gnueabihf-gcc -L native=/usr/local/lib -C link-arg=-Wl,--no-as-needed -C link-arg=-lm
    Updating crates.io index
warning: spurious network error (2 tries remaining): could not read directory '/root/.cargo/registry/index/github.com-1285ae84e5963aae/.git/refs': Value too large for defined data type; class=Os (2)
warning: spurious network error (1 tries remaining): could not read directory '/root/.cargo/registry/index/github.com-1285ae84e5963aae/.git/refs': Value too large for defined data type; class=Os (2)
error: Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  could not read directory '/root/.cargo/registry/index/github.com-1285ae84e5963aae/.git/refs': Value too large for defined data type; class=Os (2)
make: *** [Makefile:555: /root/oxi-test/target/release/liboxi_test.so] Error 101
rake aborted!
Command failed with status (2): [/usr/bin/make...]
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Tasks: TOP => compile => compile:arm-linux-gnueabihf => compile:oxi-test:arm-linux-gnueabihf => copy:oxi-test:arm-linux-gnueabihf:3.0.5 => tmp/arm-linux-gnueabihf/oxi-test/3.0.5/oxi_test.so
(See full trace by running task with --trace)

It seems this is a known issue with QEMU:

  1. https://github.com/rust-lang/cargo/issues/9545#issuecomment-855282576
  2. qemu-project/qemu#263

Relates to gitlab#381569 (closed)

Edited by Stan Hu

Merge request reports