Building ring crate for Rust-based function

I have a Netlify function written in Rust which depends on ring (a crypto library) through reqwest (a HTTP client). It compiles on local environments, but the deploy bot fails to publish the function with the following error message:

5:51:57 PM:   error: failed to run custom build command for `ring v0.16.20`
5:51:57 PM: ​
5:51:57 PM:   Caused by:
5:51:57 PM:     process didn't exit successfully: `/opt/build/repo/.netlify/rust-functions-cache/authorize/release/build/ring-21e09b2e106fab3e/build-script-build` (exit status: 101)
    --- stdout
5:51:57 PM:     OPT_LEVEL = Some("3")
5:51:57 PM:     TARGET = Some("x86_64-unknown-linux-musl")
5:51:57 PM:     HOST = Some("x86_64-unknown-linux-gnu")
5:51:57 PM:     CC_x86_64-unknown-linux-musl = None
5:51:57 PM:     CC_x86_64_unknown_linux_musl = None
5:51:57 PM:     TARGET_CC = Some("****")
5:51:57 PM:     CFLAGS_x86_64-unknown-linux-musl = None
5:51:57 PM:     CFLAGS_x86_64_unknown_linux_musl = None
5:51:57 PM:     TARGET_CFLAGS = None
5:51:57 PM:     CFLAGS = None
5:51:57 PM:     CRATE_CC_NO_DEFAULTS = None
5:51:57 PM:     DEBUG = Some("false")
5:51:57 PM:     CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
5:51:57 PM: ​
5:51:57 PM:     --- stderr
5:51:57 PM:     running "****" "-O3" (snip) aesni-x86_64-elf.S"
5:51:57 PM:     thread 'main' panicked at 'failed to execute ["****" (snip) "aesni-x86_64-elf.S"]: No such file or directory (os error 2)', /opt/buildhome/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:653:9

Note that the compiler path is replaced with **** automatically. I am using musl-cross brew formula and TARGET_CC environment variable is set to /usr/local/opt/musl-cross/bin/x86_64-linux-musl-gcc where musl-gcc should be according to its documentation.

Do you have an idea why this is happening? Any help is appreciated :slight_smile:


Site subdomain: bleachedbird.netlify.app (just for identification; another build might be running but never mind)

Environmental variables on Site Settings:

NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE=true
TARGET_CC=/usr/local/opt/musl-cross/bin/x86_64-linux-musl-gcc

Brewfile.netlify:

tap "FiloSottile/musl-cross"
brew "musl-cross"

The full build log:

5:47:23 PM: Build ready to start
5:47:25 PM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
5:47:25 PM: build-image tag: v4.8.0
5:47:25 PM: buildbot version: 4aaa27647e859c2d38cfbb25901ceae1e7f3eeae
5:47:25 PM: Fetching cached dependencies
5:47:25 PM: Failed to fetch cache, continuing with build
5:47:25 PM: Starting to prepare the repo for build
5:47:25 PM: No cached dependencies found. Cloning fresh repo
5:47:25 PM: git clone https://github.com/sei0o/jumpbird
5:47:26 PM: Preparing Git Reference refs/heads/main
5:47:26 PM: Parsing package.json dependencies
5:47:27 PM: Starting build script
5:47:27 PM: Installing dependencies
5:47:27 PM: Python version set to 2.7
5:47:27 PM: Downloading and installing node v16.15.0...
5:47:27 PM: Downloading https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.xz...
5:47:28 PM: Computing checksum with sha256sum
5:47:28 PM: Checksums matched!
5:47:30 PM: Now using node v16.15.0 (npm v8.5.5)
5:47:30 PM: Started restoring cached build plugins
5:47:30 PM: Finished restoring cached build plugins
5:47:30 PM: Attempting ruby version 2.7.2, read from environment
5:47:31 PM: Using ruby version 2.7.2
5:47:31 PM: Using PHP version 8.0
5:47:31 PM: Installing Homebrew dependencies from Brewfile.netlify
5:47:35 PM: Running `brew update --preinstall`...
5:49:25 PM: ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
5:49:25 PM:   https://github.com/Homebrew/brew#donations
5:49:25 PM: ==> Auto-updated Homebrew!
5:49:25 PM: Updated 2 taps (homebrew/bundle and homebrew/core).
5:49:25 PM: ==> New Formulae
5:49:25 PM: age-plugin-yubikey
5:49:25 PM: ansible-language-server
5:49:25 PM: arxiv_latex_cleaner
5:49:25 PM: autocannon
5:49:25 PM: bartib
5:49:25 PM: bore-cli
5:49:25 PM: cpi
5:49:25 PM: criterion
5:49:25 PM: cxgo
5:49:25 PM: dagger
5:49:25 PM: dbml-cli
5:49:25 PM: ddcutil
5:49:25 PM: ddh
5:49:25 PM: difftastic
5:49:25 PM: dotdrop
5:49:25 PM: dtrx
5:49:25 PM: ecflow-ui
5:49:25 PM: erlang@24
5:49:25 PM: fclones
5:49:25 PM: flix
5:49:25 PM: freebayes
5:49:25 PM: gcc@12
5:49:25 PM: git-workspace
5:49:25 PM: glibc@2.13
5:49:25 PM: glider
5:49:25 PM: goctl
5:49:25 PM: gokart
5:49:25 PM: gops
5:49:25 PM: hatch
5:49:25 PM: helmify
5:49:25 PM: highs
5:49:25 PM: httpyac
5:49:25 PM: hut
5:49:25 PM: ifacemaker
5:49:25 PM: imposm3
5:49:25 PM: kmod
5:49:25 PM: libabw
5:49:25 PM: libapplewm
5:49:25 PM: libcython
5:49:25 PM: libmarpa
5:49:25 PM: libtpms
5:49:25 PM: libxcrypt
5:49:25 PM: libxcvt
5:49:25 PM: libxfont2
5:49:25 PM: lndir
5:49:25 PM: localtunnel
5:49:25 PM: mariadb@10.6
5:49:25 PM: mbt
5:49:25 PM: mbw
5:49:25 PM: micro_inetd
5:49:25 PM: minimap2
5:49:25 PM: mkfontscale
5:49:25 PM: mongodb-atlas-cli
5:49:25 PM: monika
5:49:25 PM: naml
5:49:25 PM: nvchecker
5:49:25 PM: octosql
5:49:25 PM: opentelemetry-cpp
5:49:25 PM: pg_partman
5:49:25 PM: pget
5:49:25 PM: primecount
5:49:25 PM: quran
5:49:25 PM: release-it
5:49:25 PM: sdl2_sound
5:49:25 PM: sftpgo
5:49:25 PM: sophus
5:49:25 PM: spirv-headers
5:49:25 PM: sqls
5:49:25 PM: sse2neon
5:49:25 PM: stanc3
5:49:25 PM: terramate
5:49:25 PM: tinysearch
5:49:25 PM: tradcpp
5:49:25 PM: ttmath
5:49:25 PM: tygo
5:49:25 PM: ugit
5:49:25 PM: vcluster
5:49:25 PM: virt-manager
5:49:25 PM: vsce
5:49:25 PM: wb32-dfu-updater_cli
5:49:25 PM: werf
5:49:25 PM: xcode-kotlin
5:49:25 PM: xkbcomp
5:49:25 PM: xpipe
5:49:25 PM: yorkie
5:49:25 PM: ==> Updated Formulae
5:49:25 PM: Updated 2309 formulae.
5:49:25 PM: ==> Deleted Formulae
5:49:25 PM: boost-python
5:49:25 PM: griffon
5:49:25 PM: komposition
5:49:25 PM: szip
5:49:32 PM: Tapping filosottile/musl-cross
5:49:34 PM: Installing musl-cross
5:50:00 PM: ==> Downloading https://ghcr.io/v2/homebrew/core/gnu-sed/manifests/4.8
5:50:00 PM: ==> Downloading https://ghcr.io/v2/homebrew/core/gnu-sed/blobs/sha256:35d0116b6abaa8fe7e51fc955d4f940a3d4ee0fbb0155c3759e3af35cd38bfe2
5:50:00 PM: ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:35d0116b6abaa8fe7e51fc955d4f940a3d4ee0fbb0155c3759e3af35cd38bfe2?se=2022-06-01T08%3A55%3A00Z&sig=1CC%2Bo8JMGLYYLq9%2BfVZqDLmvMSgFRa%2BvFH79JIMtBjI%3D&sp=r&spr=https&sr=b&sv=2019-12-12
5:50:00 PM: ==> Downloading https://ghcr.io/v2/homebrew/core/make/manifests/4.3-1
5:50:00 PM: ==> Downloading https://ghcr.io/v2/homebrew/core/make/blobs/sha256:dd17cdf0a93ef30324250694ea5baec67c037e1d71c1cab8fe6432d66758fd62
5:50:00 PM: ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:dd17cdf0a93ef30324250694ea5baec67c037e1d71c1cab8fe6432d66758fd62?se=2022-06-01T08%3A55%3A00Z&sig=bdh5avf7%2BcOS5RBydxrdOqYvg0xHoNGdCaPnv%2FJKjw4%3D&sp=r&spr=https&sr=b&sv=2019-12-12
5:50:00 PM: ==> Downloading https://github.com/richfelker/musl-cross-make/commit/d6ded50d.patch?full_index=1
5:50:00 PM: ==> Downloading https://github.com/richfelker/musl-cross-make/commit/a54eb56f.patch?full_index=1
5:50:00 PM: ==> Downloading https://github.com/richfelker/musl-cross-make/commit/8d34906.patch?full_index=1
5:50:00 PM: ==> Downloading https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.88.tar.xz
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/mpfr/mpfr-4.0.2.tar.bz2
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.bz2
5:50:00 PM: ==> Downloading https://www.musl-libc.org/releases/musl-1.2.0.tar.gz
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.bz2
5:50:00 PM: ==> Downloading https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=3d5db9ebe860
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz
5:50:00 PM: ==> Downloading https://downloads.sourceforge.net/project/libisl/isl-0.21.tar.bz2
5:50:00 PM: ==> Downloading from https://versaweb.dl.sourceforge.net/project/libisl/isl-0.21.tar.bz2
5:50:00 PM: ==> Downloading https://github.com/richfelker/musl-cross-make/archive/v0.9.9.tar.gz
5:50:00 PM: ==> Downloading from https://codeload.github.com/richfelker/musl-cross-make/tar.gz/refs/tags/v0.9.9
5:50:00 PM: ==> Installing musl-cross from filosottile/musl-cross
5:50:00 PM: ==> Installing dependencies for filosottile/musl-cross/musl-cross: gnu-sed and make
5:50:00 PM: ==> Installing filosottile/musl-cross/musl-cross dependency: gnu-sed
5:50:00 PM: ==> Pouring gnu-sed--4.8.x86_64_linux.bottle.tar.gz
5:50:00 PM: 🍺  /home/linuxbrew/.linuxbrew/Cellar/gnu-sed/4.8: 50 files, 1MB
5:50:00 PM: ==> Installing filosottile/musl-cross/musl-cross dependency: make
5:50:00 PM: ==> Pouring make--4.3.x86_64_linux.bottle.1.tar.gz
5:50:00 PM: 🍺  /home/linuxbrew/.linuxbrew/Cellar/make/4.3: 43 files, 2.2MB
5:50:00 PM: ==> Installing filosottile/musl-cross/musl-cross
5:50:00 PM: ==> Patching
5:50:00 PM: ==> Applying d6ded50d.patch
5:50:00 PM: patching file patches/musl-1.2.0/0001-broken_arm_vdso.diff
5:50:00 PM: ==> Applying a54eb56f.patch
5:50:00 PM: patching file Makefile
5:50:00 PM: ==> Applying 8d34906.patch
5:50:00 PM: patching file patches/gcc-10.3.0/0007-darwin-aarch64-config.diff
5:50:00 PM: patching file patches/gcc-10.3.0/0008-darwin-aarch64-self-host-driver.patch
5:50:00 PM: patching file patches/gcc-6.5.0/0026-darwin-aarch64-config.diff
5:50:00 PM: patching file patches/gcc-6.5.0/0027-darwin-aarch64-self-host-driver.diff
5:50:00 PM: patching file patches/gcc-6.5.0/0028-darwin-align-pch_address_space-to-16k.patch
5:50:00 PM: patching file patches/gcc-7.5.0/0023-darwin-aarch64-config.diff
5:50:00 PM: patching file patches/gcc-7.5.0/0024-darwin-aarch64-self-host-driver.patch
5:50:00 PM: patching file patches/gcc-7.5.0/0025-darwin-align-pch_address_space-to-16k.patch
5:50:00 PM: patching file patches/gcc-8.5.0/0022-darwin-aarch64-config.diff
5:50:00 PM: patching file patches/gcc-8.5.0/0023-darwin-aarch64-self-host-driver.patch
5:50:00 PM: patching file patches/gcc-8.5.0/0024-darwin-align-pch_address_space-to-16k.patch
5:50:00 PM: patching file patches/gcc-9.2.0/0020-darwin-aarch64-config.diff
5:50:00 PM: patching file patches/gcc-9.2.0/0021-darwin-aarch64-self-host-driver.patch
5:50:00 PM: patching file patches/gcc-9.2.0/0022-darwin-align-pch_address_space-to-16k.patch
5:50:00 PM: patching file patches/gcc-9.4.0/0020-darwin-aarch64-config.diff
5:50:00 PM: patching file patches/gcc-9.4.0/0021-darwin-aarch64-self-host-driver.patch
5:50:00 PM: ==> Downloading https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.88.tar.xz
5:50:00 PM: Already downloaded: /opt/buildhome/.cache/Homebrew/downloads/f5440cf7cd8df600bbbc7888d7bfc745681f3e3a3bfa5e1fe0e48c03b54781d0--linux-4.19.88.tar.xz
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/mpfr/mpfr-4.0.2.tar.bz2
5:50:00 PM: Already downloaded: /opt/buildhome/.cache/Homebrew/downloads/7ca7bfe4233494307c2c9b60b79304b8c35b79989d947bcb99eab79a01705eee--mpfr-4.0.2.tar.bz2
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
5:50:00 PM: Already downloaded: /opt/buildhome/.cache/Homebrew/downloads/f46049bc3c7cd6b6d6fd2051c98794ba4977ef0eaa361b6fd3c10b95f9d907f0--mpc-1.1.0.tar.gz
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.bz2
5:50:00 PM: Already downloaded: /opt/buildhome/.cache/Homebrew/downloads/ef6f10b9f951265fe9fca7e4a3f31538df4093f745837530e75c9a88954fe135--gmp-6.1.2.tar.bz2
5:50:00 PM: ==> Downloading https://www.musl-libc.org/releases/musl-1.2.0.tar.gz
5:50:00 PM: Already downloaded: /opt/buildhome/.cache/Homebrew/downloads/f24a4c691121f7b49cb43e4106192242544447ea7990bb8172ad0509d02c4469--musl-1.2.0.tar.gz
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.bz2
5:50:00 PM: Already downloaded: /opt/buildhome/.cache/Homebrew/downloads/742cf2bb3679b7916196d01dd3ea8e87dbafbd6b128d657eccffa1921cbff79b--binutils-2.33.1.tar.bz2
5:50:00 PM: ==> Downloading https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=3d5db9ebe860
5:50:00 PM: Already downloaded: /
opt/buildhome/.cache/Homebrew/downloads/53c623e9fd9ebac8516b8d880b2a1f0e9c9ef2aa08be18ec30d173ba4ca7d1f2--config.sub
5:50:00 PM: ==> Downloading https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz
5:50:00 PM: Already downloaded: /opt/buildhome/.cache/Homebrew/downloads/d826388c1d62d3837abf5966bfcb52111c0fea536be81417ab4718ba089422f1--gcc-9.2.0.tar.xz
5:50:00 PM: ==> Downloading https://downloads.sourceforge.net/project/libisl/isl-0.21.tar.bz2
5:50:00 PM: Already downloaded: /opt/buildhome/.cache/Homebrew/downloads/a9dd57e80e483bb29f553e2c596e73ffb5bf92049f5c09d2d2801bc92287ea84--isl-0.21.tar.bz2
5:50:00 PM: ==> /home/linuxbrew/.linuxbrew/opt/make/bin/gmake install TARGET=x86_64-linux-musl
5:50:00 PM: Last 15 lines from /opt/buildhome/.cache/Homebrew/Logs/musl-cross/01.gmake:
5:50:00 PM: 2022-06-01 08:50:00 +0000
5:50:00 PM: /home/linuxbrew/.linuxbrew/opt/make/bin/gmake
5:50:00 PM: install
5:50:00 PM: TARGET=x86_64-linux-musl
5:50:00 PM: If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
5:50:00 PM:   https://github.com/filosottile/homebrew-musl-cross/issues
5:50:00 PM: Installing musl-cross has failed!
5:50:00 PM: Homebrew Bundle failed! 1 Brewfile dependency failed to install.
5:50:00 PM: Started restoring cached go cache
5:50:00 PM: Finished restoring cached go cache
5:50:00 PM: go version go1.16.5 linux/amd64
5:50:00 PM: go version go1.16.5 linux/amd64
5:50:00 PM: Installing missing commands
5:50:00 PM: Verify run directory
5:50:02 PM: ​
5:50:02 PM: ────────────────────────────────────────────────────────────────5:50:02 PM:   Netlify Build                                                 5:50:02 PM: ────────────────────────────────────────────────────────────────5:50:02 PM: ​5:50:02 PM: ❯ Version5:50:02 PM:   @netlify/build 27.1.35:50:02 PM: ​5:50:02 PM: ❯ Flags5:50:02 PM:   baseRelDir: true5:50:02 PM:   buildId: 6297279b53d0fd000919cb245:50:02 PM:   deployId: 6297279b53d0fd000919cb265:50:02 PM: ​5:50:02 PM: ❯ Current directory5:50:02 PM:   /opt/build/repo5:50:02 PM: ​5:50:02 PM: ❯ Config file5:50:02 PM:   /opt/build/repo/netlify.toml5:50:02 PM: ​5:50:02 PM: ❯ Context5:50:02 PM:   production5:50:02 PM: ​
5:50:02 PM: ────────────────────────────────────────────────────────────────
5:50:02 PM:   1. Functions bundling                                         
5:50:02 PM: ────────────────────────────────────────────────────────────────
5:50:02 PM: ​
5:50:02 PM: Packaging Functions from netlify/functions directory:
5:50:02 PM:  - authorize/src/main.rs
5:50:02 PM: ​
5:51:57 PM: Could not compile Rust function authorize:
5:51:57 PM: ​
5:51:57 PM: ​5:51:57 PM: ────────────────────────────────────────────────────────────────5:51:57 PM:   Bundling of Function "authorize" failed                       5:51:57 PM: ────────────────────────────────────────────────────────────────5:51:57 PM:
5:51:57 PM:   Error message5:51:57 PM:   Command failed with exit code 101: cargo build --target x86_64-unknown-linux-musl --release (https://ntl.fyi/exit-code-101)5:51:57 PM:       Updating crates.io index5:51:57 PM:    Downloading crates ...5:51:57 PM:     Downloaded futures v0.3.155:51:57 PM:     Downloaded futures-sink v0.3.155:51:57 PM:     Downloaded form_urlencoded v1.0.15:51:57 PM:     Downloaded autocfg v1.0.15:51:57 PM:     Downloaded futures-io v0.3.155:51:57 PM:     Downloaded generic-array v0.14.55:51:57 PM:     Downloaded mime v0.3.165:51:57 PM:     Downloaded tower-service v0.3.15:51:57 PM:     Downloaded tokio-macros v1.7.05:51:57 PM:     Downloaded tokio-rustls v0.23.25:51:57 PM:     Downloaded unicode-normalization v0.1.195:51:57 PM:     Downloaded version_check v0.9.45:51:57 PM:     Downloaded base64 v0.13.05:51:57 PM:     Downloaded cc v1.0.735:51:57 PM:     Downloaded tinyvec v1.5.15:51:57 PM:     Downloaded fnv v1.0.75:51:57 PM:     Downloaded idna v0.2.35:51:57 PM:     Downloaded ppv-lite86 v0.2.165:51:57 PM:     Downloaded tokio-util v0.6.95:51:57 PM:     Downloaded postgrest v1.3.05:51:57 PM:     Downloaded oauth2 v4.1.05:51:57 PM:     Downloaded num_threads v0.1.35:51:57 PM:     Downloaded lambda_runtime v0.4.15:51:57 PM:     Downloaded percent-encoding v2.1.05:51:57 PM:     Downloaded tinyvec_macros v0.1.05:51:57 PM:     Downloaded matches v0.1.95:51:57 PM:     Downloaded thread_local v1.1.35:51:57 PM:     Downloaded tracing-attributes v0.1.155:51:57 PM:     Downloaded httparse v1.4.15:51:57 PM:     Downloaded colored v1.9.35:51:57 PM:     Downloaded aws_lambda_events v0.5.05:51:57 PM:     Downloaded pin-utils v0.1.05:51:57 PM:     Downloaded spin v0.5.25:51:57 PM:     Downloaded serde_path_to_error v0.1.75:51:57 PM:     Downloaded syn v1.0.735:51:57 PM:     Downloaded rand_core v0.6.35:51:57 PM:     Downloaded try-lock v0.2.35:51:57 PM:     Downloaded time-macros v0.2.35:51:57 PM:     Downloaded sharded-slab v0.1.15:51:57 PM:     Downloaded lazy_static v1.4.05:51:57 PM:     Downloaded itoa v0.4.75:51:57 PM:     Downloaded opaque-debug v0.3.05:51:57 PM:     Downloaded tracing v0.1.265:51:57 PM:     Downloaded tokio v1.17.05:51:57 PM:     Downloaded tracing-subscriber v0.2.195:51:57 PM:     Downloaded log v0.4.145:51:57 PM:     Downloaded proc-macro-hack v0.5.195:51:57 PM:     Downloaded serde_derive v1.0.1265:51:57 PM:     Downloaded rustls-pemfile v0.2.15:51:57 PM:     Downloaded sha2 v0.9.95:51:57 PM:     Downloaded serde_urlencoded v0.7.15:51:57 PM:     Downloaded tracing-error v0.1.25:51:57 PM:     Downloaded want v0.3.05:51:57 PM:     Downloaded untrusted v0.7.15:51:57 PM:     Downloaded unicode-xid v0.2.25:51:57 PM:     Downloaded tracing-core v0.1.185:51:57 PM:     Downloaded url v2.2.25:51:57 PM:     Downloaded webpki v0.22.05:51:57 PM:     Downloaded time v0.3.75:51:57 PM:     Downloaded rustls v0.20.45:51:57 PM:     Downloaded socket2 v0.4.45:51:57 PM:     Downloaded serde v1.0.1265:51:57 PM:     Downloaded serde_json v1.0.645:51:57 PM:     Downloaded tokio-stream v0.1.75:51:57 PM:     Downloaded thiserror-impl v1.0.305:51:57 PM:     Downloaded webpki-roots v0.22.25:51:57 PM:     Downloaded thiserror v1.0.305:51:57 PM:     Downloaded h2 v0.3.115:51:57 PM:     Downloaded libc v0.2.119
5:51:57 PM:     Downloaded chrono v0.4.19
5:51:57 PM:     Downloaded time v0.1.44
5:51:57 PM:     Downloaded encoding_rs v0.8.30
5:51:57 PM:     Downloaded futures-util v0.3.15
5:51:57 PM:     Downloaded uuid v0.8.2
5:51:57 PM:     Downloaded typenum v1.15.0
5:51:57 PM:     Downloaded http-body v0.4.2
5:51:57 PM:     Downloaded futures-channel v0.3.15
5:51:57 PM:     Downloaded unicode-bidi v0.3.7
5:51:57 PM:     Downloaded ring v0.16.20
5:51:57 PM:     Downloaded slab v0.4.3
5:51:57 PM:     Downloaded simple_asn1 v0.6.1
5:51:57 PM:     Downloaded reqwest v0.11.9
5:51:57 PM:     Downloaded async-stream v0.3.2
5:51:57 PM:     Downloaded num-bigint v0.4.3
5:51:57 PM:     Downloaded rand v0.8.5
5:51:57 PM:     Downloaded http v0.2.6
5:51:57 PM:     Downloaded ryu v1.0.5
5:51:57 PM:     Downloaded memchr v2.4.0
5:51:57 PM:     Downloaded sct v0.7.0
5:51:57 PM:     Downloaded mio v0.8.0
5:51:57 PM:     Downloaded atty v0.2.14
5:51:57 PM:     Downloaded proc-macro2 v1.0.27
5:51:57 PM:     Downloaded num-traits v0.2.14
5:51:57 PM:     Downloaded quote v1.0.9
5:51:57 PM:     Downloaded hashbrown v0.11.2
5:51:57 PM:     Downloaded hyper v0.14.10
5:51:57 PM:     Downloaded jsonwebtoken v8.0.1
5:51:57 PM:     Downloaded http-serde v1.0.3
5:51:57 PM:     Downloaded futures-task v0.3.15
5:51:57 PM:     Downloaded futures-core v0.3.15
5:51:57 PM:     Downloaded pin-project-lite v0.2.7
5:51:57 PM:     Downloaded indexmap v1.8.0
5:51:57 PM:     Downloaded ipnet v2.3.1
5:51:57 PM:     Downloaded proc-macro-nested v0.1.7
5:51:57 PM:     Downloaded num-integer v0.1.44
5:51:57 PM:     Downloaded pem v1.0.2
5:51:57 PM:     Downloaded getrandom v0.2.5
5:51:57 PM:     Downloaded hyper-rustls v0.23.0
5:51:57 PM:     Downloaded bytes v1.0.1
5:52:02 PM: Creating deploy upload records
5:51:57 PM:     Downloaded httpdate v1.0.1
5:51:57 PM:     Downloaded cookie v0.16.0
5:51:57 PM:     Downloaded futures-executor v0.3.15
5:51:57 PM:     Downloaded futures-macro v0.3.15
5:51:57 PM:     Downloaded dotenv v0.15.0
5:52:02 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
5:51:57 PM:     Downloaded digest v0.9.0
5:51:57 PM:     Downloaded cpufeatures v0.2.1
5:51:57 PM:     Downloaded cfg-if v1.0.0
5:51:57 PM:     Downloaded block-buffer v0.9.0
5:51:57 PM:     Downloaded quickcheck v1.0.3
5:51:57 PM:     Downloaded async-stream-impl v0.3.2
5:51:57 PM:     Downloaded once_cell v1.8.0
5:51:57 PM:     Downloaded rand_chacha v0.3.1
5:51:57 PM:     Downloaded num_cpus v1.13.0
5:51:57 PM:     Downloaded itoa v1.0.1
5:51:57 PM:     Downloaded simple_logger v1.16.0
5:51:57 PM:      Compiling proc-macro2 v1.0.27
5:51:57 PM:      Compiling unicode-xid v0.2.2
5:51:57 PM:      Compiling syn v1.0.73
5:51:57 PM:      Compiling libc v0.2.119
5:51:57 PM:      Compiling autocfg v1.0.1
5:51:57 PM:      Compiling cfg-if v1.0.0
5:51:57 PM:      Compiling serde_derive v1.0.126
5:51:57 PM:      Compiling serde v1.0.126
5:51:57 PM:      Compiling log v0.4.14
5:51:57 PM:      Compiling itoa v1.0.1
5:51:57 PM:      Compiling pin-project-lite v0.2.7
5:51:57 PM:      Compiling memchr v2.4.0
5:51:57 PM:      Compiling futures-core v0.3.15
5:51:57 PM:      Compiling once_cell v1.8.0
5:51:57 PM:      Compiling lazy_static v1.4.0
5:51:57 PM:      Compiling cc v1.0.73
5:51:57 PM:      Compiling proc-macro-hack v0.5.19
5:51:57 PM:      Compiling futures-channel v0.3.15
5:51:57 PM:      Compiling futures-task v0.3.15
5:51:57 PM:      Compiling proc-macro-nested v0.1.7
5:51:57 PM:      Compiling futures-sink v0.3.15
5:51:57 PM:      Compiling spin v0.5.2
5:51:57 PM:      Compiling untrusted v0.7.1
5:51:57 PM:      Compiling fnv v1.0.7
5:51:57 PM:      Compiling version_check v0.9.4
5:51:57 PM:      Compiling futures-io v0.3.15
5:51:57 PM:      Compiling ryu v1.0.5
5:51:57 PM:      Compiling slab v0.4.3
5:51:57 PM:      Compiling pin-utils v0.1.0
5:51:57 PM:      Compiling itoa v0.4.7
5:51:57 PM:      Compiling ppv-lite86 v0.2.16
5:51:57 PM:      Compiling serde_json v1.0.64
5:51:57 PM:      Compiling hashbrown v0.11.2
5:51:57 PM:      Compiling httparse v1.4.1
5:51:57 PM:      Compiling base64 v0.13.0
5:51:57 PM:      Compiling tinyvec_macros v0.1.0
5:51:57 PM:      Compiling typenum v1.15.0
5:51:57 PM:      Compiling rustls v0.20.4
5:51:57 PM:      Compiling matches v0.1.9
5:51:57 PM:      Compiling try-lock v0.2.3
5:51:57 PM:      Compiling httpdate v1.0.1
5:51:57 PM:      Compiling percent-encoding v2.1.0
5:51:57 PM:      Compiling tower-service v0.3.1
5:51:57 PM:      Compiling encoding_rs v0.8.30
5:51:57 PM:      Compiling num_threads v0.1.3
5:51:57 PM:      Compiling time-macros v0.2.3
5:51:57 PM:      Compiling unicode-bidi v0.3.7
5:51:57 PM:      Compiling ipnet v2.3.1
5:51:57 PM:      Compiling mime v0.3.16
5:51:57 PM:      Compiling cpufeatures v0.2.1
5:51:57 PM:      Compiling opaque-debug v0.3.0
5:51:57 PM:      Compiling dotenv v0.15.0
5:51:57 PM:      Compiling tracing-core v0.1.18
5:51:57 PM:      Compiling sharded-slab v0.1.1
5:51:57 PM:      Compiling futures-macro v0.3.15
5:51:57 PM:      Compiling futures-util v0.3.15
5:51:57 PM:      Compiling indexmap v1.8.0
5:51:57 PM:      Compiling num-traits v0.2.14
5:51:57 PM:      Compiling num-integer v0.1.44
5:51:57 PM:      Compiling num-bigint v0.4.3
5:51:57 PM:      Compiling thread_local v1.1.3
5:51:57 PM:      Compiling generic-array v0.14.5
5:51:57 PM:      Compiling cookie v0.16.0
5:51:57 PM:      Compiling tinyvec v1.5.1
5:51:57 PM:      Compiling rustls-pemfile v0.2.1
5:51:57 PM:      Compiling pem v1.0.2
5:51:57 PM:      Compiling form_urlencoded v1.0.1
5:51:57 PM:      Compiling ring v0.16.20
5:51:57 PM:      Compiling tracing-subscriber v0.2.19
5:51:57 PM:      Compiling want v0.3.0
5:51:57 PM:      Compiling quote v1.0.9
5:51:57 PM:      Compiling getrandom v0.2.5
5:51:57 PM:      Compiling num_cpus v1.13.0
5:51:57 PM:      Compiling socket2 v0.4.4
5:51:57 PM:      Compiling mio v0.8.0
5:51:57 PM:      Compiling time v0.1.44
5:51:57 PM:      Compiling atty v0.2.14
5:51:57 PM:      Compiling unicode-normalization v0.1.19
5:51:57 PM:   error: failed to run custom build command for `ring v0.16.20`
5:51:57 PM: ​
5:51:57 PM:   Caused by:
5:51:57 PM:     process didn't exit successfully: `/opt/build/repo/.netlify/rust-functions-cache/authorize/release/build/ring-21e09b2e106fab3e/build-script-build` (exit status: 101)
    --- stdout
5:51:57 PM:     OPT_LEVEL = Some("3")
5:51:57 PM:     TARGET = Some("x86_64-unknown-linux-musl")
5:51:57 PM:     HOST = Some("x86_64-unknown-linux-gnu")
5:51:57 PM:     CC_x86_64-unknown-linux-musl = None
5:51:57 PM:     CC_x86_64_unknown_linux_musl = None
5:51:57 PM:     TARGET_CC = Some("****")
5:51:57 PM:     CFLAGS_x86_64-unknown-linux-musl = None
5:51:57 PM:     CFLAGS_x86_64_unknown_linux_musl = None
5:51:57 PM:     TARGET_CFLAGS = None
5:51:57 PM:     CFLAGS = None
5:51:57 PM:     CRATE_CC_NO_DEFAULTS = None
5:51:57 PM:     DEBUG = Some("false")
5:51:57 PM:     CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
5:51:57 PM: ​
5:51:57 PM:     --- stderr
5:51:57 PM:     running "****" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/opt/build/repo/.netlify/rust-functions-cache/authorize/x86_64-unknown-linux-musl/release/build/ring-fea53855345d960a/out/aesni-x86_64-elf.o" "/opt/buildhome/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
5:51:57 PM:     thread 'main' panicked at 'failed to execute ["****" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/opt/build/repo/.netlify/rust-functions-cache/authorize/x86_64-unknown-linux-musl/release/build/ring-fea53855345d960a/out/aesni-x86_64-elf.o" "/opt/buildhome/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"]: No such file or directory (os error 2)', /opt/buildhome/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:653:9
5:51:57 PM:     note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
5:51:57 PM:   warning: build failed, waiting for other jobs to finish...
5:51:57 PM: ​
5:51:57 PM:   Error location
5:51:57 PM:   While bundling Function "authorize"
5:51:57 PM: ​
5:51:57 PM:   Resolved config
5:51:57 PM:   build:
5:51:57 PM:     environment:
5:51:57 PM:       - NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE
5:51:57 PM:       - TARGET_CC
5:51:57 PM:     publish: /opt/build/repo
5:51:57 PM:     publishOrigin: config
5:51:57 PM:   functionsDirectory: /opt/build/repo/netlify/functions
5:51:58 PM: Caching artifacts
5:51:58 PM: Started saving build plugins
5:51:58 PM: Finished saving build plugins
5:51:58 PM: Started saving Rust functions
5:51:58 PM: Finished saving Rust functions
5:51:58 PM: Started saving pip cache
5:51:58 PM: Finished saving pip cache
5:51:58 PM: Started saving emacs cask dependencies
5:51:58 PM: Finished saving emacs cask dependencies
5:51:58 PM: Started saving maven dependencies
5:51:58 PM: Finished saving maven dependencies
5:51:58 PM: Started saving boot dependencies
5:51:58 PM: Finished saving boot dependencies
5:51:58 PM: Started saving rust rustup cache
5:52:01 PM: Finished saving rust rustup cache
5:52:01 PM: Started saving go dependencies
5:52:01 PM: Finished saving go dependencies
5:52:02 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:52:02 PM: Failing build: Failed to build site
5:52:02 PM: Finished processing build request in 4m37.933797924s

Hey @sei0o,

Sadly, Rust Functions is a very very niche area for the time being and the Support Team has little to no knowledge about it yet. We’ve passed on your issue to the engineers and would circle back once we’ve more information.

1 Like

Hey @sei0o,

I wanted to give you a quick update. We are still looking into this and how to solve it.

For the time being, you can also work around this limitation yourself by compiling the function yourself. So either on you local machine or on a CI provider you can compile you rust function and then place and commit the resulting binary in the netlify functions directory (default: ./netlify/functions/). Our build tools will detect the rust binary and deploy it unmodified. As a reference, you can look at the documentation for go functions, which offer the same feature: Deploy functions | Netlify Docs

Once we have more information, we will let you know here.

1 Like

Anyone else having this issue, @chrisbiscardi has a great video explanation: Know this before deploying Rust to Netlify Functions - YouTube

Chris and I discussed this a bit in chat. We are both thinking it’s best to precompile and deploy from another CI system that supports cargo-zigbuild to cross compile the correct target. Netlify could help out by including Zig in the build environment, but not sure if that would happen.

Although there is the option of getting it all setup prior to build process, I’m not sure it’d be worth the effort and would just add to build times. See here

1 Like

Thank you all for replies! Yes, compiling on local environments seems reasonable for now.

@talves Zig is available in Homebrew, won’t that help?

Yeah, here is the post for homebrew: Now in experimental alpha: homebrew access in the build image

@sei0o and others,

If you are interested in using Netlify for the crate cross compile builds on your Rust functions, I created a solution that works fairly well for now using cargo-zigbuild.

tldr;

Basically write a script to install zig binary using yarn (or npm) globally (6s install and only one line);
Check to see if the binary install for cargo-zigbuild already exists, if not cargo install otherwise ignore;
Compile your functions using cargo zigbuild for the correct target and copy to the functions folder. :rocket:

Script and Repo:

Here’s my example repo

Bash script to run inline with your build (./build.sh)

#!/bin/bash
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -euxo pipefail

which zig || yarn global add @ziglang/cli
# /opt/buildhome/.yarn/bin/zig
which cargo-zigbuild || cargo install cargo-zigbuild
mkdir -p netlify/functions
cargo zigbuild --target x86_64-unknown-linux-gnu.2.26 --release
# add copy commands as you add functions
cp target/x86_64-unknown-linux-gnu/release/hello netlify/functions/

Installing @ziglang/cli will install the zig binary for use by cargo-zigbuild

cargo-zigbuild is installed into the .cargo directory and gets cached by Netlify so there isn’t a repeat of the install after the first time. I thought the target directory was cached also, but not sure why that’s not true (I see a message, but a different question for the Netlify devs).

NOTE: I first used cargo-lambda instead, but it’s not really needed and wraps cargo-zigbuild with the same required dependency on zig, so I decided to use a smaller crate install until there is a need to use cargo-lambda.

1 Like

Our build system has been updated and the packages musl and musl-tools are now available. In my tests, the ring crate is now successfully compiling for the target x86_64-unknown-linux-musl.

2 Likes

I’ll test this later, but not sure that will work. Although it might compile, not sure GLIBC_2.28 will be available in AWS?

This did work @danez. I’m curious what was needed to make this work, because locally I’m not able to make musl target correctly. ok, I see how musl-tools contains the musl-gcc wrapper script. :tada:

Note: If you are going to run the build yourself you’ll need to create a rust-toolchain file in the root of the repo that specifies the target if it doesn’t find it:

[toolchain]
channel = "stable"
targets = [ "x86_64-unknown-linux-musl" ]

I want to add an explanation for those new to what is going on here and might be new to what we’re talking about.

First, in this case, we are compiling our Rust function (crate library) to target a specific platform. Since these functions will run on AWS lambda, the operating system is linux on x86_64 architecture. When we target a different platform than the one we are using, it’s called cross compile. The original issue on this thread was a compile error caused by musl libc for the ring crate solved by installing/updating musl-tools.

The issue here is the linked library we are targeting on the system the function will be running on. If we compile targeting a library that isn’t installed on the target, we would get an error at runtime.

Here is an example of functions that compiled correctly but had errors at runtime because they were looking for a specific GLIBC version that isn’t installed on AWS Lambda:

The above errors were compiled targeting x86_64-unknown-linux-gnu using cargo build with a more recent glibc version than exists on the AWS lambda server.

My Solution using cargo-zigbuild allows to specify a different glibc version (2.26) which exists on the AWS lambda instance.

The decision for what method to use is up to you. If you start getting errors with the Netlify solution or don’t want to deal with the setting up of your local env to support the musl target, you have the option to use zigbuild.

Happy Coding :slightly_smiling_face:

2 Likes

Hi Daniel,

After some discussion, I’m of the opinion that the zigbuild solution is probably going to be better for the developer experience. Netlify should consider using it for the auto build deploy due to the fact that having local development and CI using the same solution would be better to start.

Another plus of using zigbuild for developers is there would be one dependency requirement vs a complicated musl setup requirement local for those using mac os etc. Although, I’m using WSL2 and Ubuntu locally and musl and musl-tools was an easy fix for me, I’ll be sticking with the zigbuild solution targeting x86_64-unknown-linux-gnu and the correct glibc version for functions on Netlify.

One last argument is that cargo-lambda is also depending on zigbuild themselves for their own build wrapper to solve cross compile compatibility on all platforms.

Regards,
Tony

1 Like

Thanks, it’s working now on my apps too! Glad to see the safer libc used in more areas.

I have decided to use musl for my original (small = static-link-friendly) task, but yes, there might be some crates other than ring that don’t play well with musl, and there are more local environments running on glibc than on musl yet. Thank you for the detailed guide!

1 Like