snewcomer

snewcomer

Phoenix Core Team

Recently, I came across this wonderful blog post on Parsing PDFs (and more) in Elixir using Rust. However, when trying out Github Actions CI with Rustler, I can’t seem to figure out the right steps to get mix compile to work.

ci.yaml
Failed to load NIF Library error

Warning: 04:44:23.229 [warning] The on_load function for module Elixir.RustReader returned:
{:error,
 {:load_failed,
  ~c"Failed to load NIF library /home/runner/work/elixir_pdf_tutorial/elixir_pdf_tutorial/_build/test/lib/elixir_pdf/priv/native/librustreader: 'libtika_native.so: cannot open shared object file: No such file or directory'"}}

How are people setting up their CI environments with Rustler and Phoenix projects?

Showing Posts 1 to 10

mindok

mindok

We have a deps section in our CI yaml that looks something like what’s below. It looks like you are missing the rust tool chain, cargo deps fetch and rust compilation steps.

  deps:
    name: Dependencies
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          submodules: true

      - name: Setup Elixir
        uses: erlef/setup-beam@v1
        with:
          version-file: .tool-versions
          version-type: strict

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable

      - name: Retrieve Mix dependencies
        uses: actions/cache@v4
        id: cache-compiled-deps
        with:
          path: |
            deps
            _build
          key: ${{ runner.os }}-${{ env.MIX_ENV }}-${{ hashFiles('mix.lock') }}-v2

      - name: Retrieve Cargo dependencies
        uses: Swatinem/rust-cache@v2
        with:
          cache-on-failure: true
          shared-key: rustler-v2
          workspaces: native/imagesize -> target

      - name: Install Mix dependencies
        run: mix deps.get

      - name: Compile Mix dependencies.
        run: mix deps.compile

      - name: Compile Rust dependencies
        working-directory: native/imagesize
        run: cargo build --profile release

      - name: Create Dialyzer PLT files
        run: mix dialyzer --plt
        if: ${{ false }}
suchasurge

suchasurge

Hey there.

I think your setup would work with a simpler rust library because looking at your CI output you can see that rust dependencies are downloaded and rust is also compiling stuff.

The extractous rust library is doing (compiling) stuff with GraalVM because of Apache Tika, see extractous/extractous-core/README.md at main · yobix-ai/extractous · GitHub

I also don’t get it running locally, even with a newer rustler version with the deprecations fixed and a GraalVM Java SDK available.

It compiles without errors but also fails with the same Failed to load NIF library error.

Maybe someone has an idea what happens with the libtika_native.so file and how to handle it with a rustler setup.

@codestirring I think you are the article author? Can you tell us how you were able to get it running?

Thx :slight_smile:

Cheers
Frank

snewcomer

snewcomer OP

Phoenix Core Team

Appreciate the response! Oddly still failure to load with mix compile

ci.yaml
failure to load

snewcomer

snewcomer OP

Phoenix Core Team

Great point. This might be specific to this rust package. I can’t figure this out either in CI. I can run it on my Mac but I haven’t discerned why that is.

suchasurge

suchasurge

Ah, ok I only tried on linux.

But I just build a simple rust CLI with extractous usage like in the article which works without complaining about libtika_native.so like with rustler.

So there might be some steps needed when used with rustler I can’t figure our right now.

snewcomer

snewcomer OP

Phoenix Core Team

https://github.com/snewcomer/nif-extractous

Yes I think you are right about rustler. Building it in Github Action is trying to reference that libtika_native.so from that /runner/ folder. At this point, I am at a loss.

[warning] The on_load function for module Elixir.NifExtractous.Native returned:
{:error,
 {:load_failed,
  ~c"Failed to load NIF library: 'dlopen(/Users/snewcomer/github/my_site/_build/dev/lib/nif_extractous/priv/native/libnif_extractous-v0.3.2-nif-2.17-aarch64-apple-darwin.so, 0x0002): Library not loaded: /Users/runner/work/nif-extractous/nif-extractous/target/aarch64-apple-darwin/release/build/extractous-1392444ace32bce9/out/tika-native/build/native/nativeCompile/libtika_native.dylib\n  Referenced from: <D02FBE3D-DA3C-3332-9BD2-76946358E9A3> /Users/snewcomer/github/my_site/_build/dev/lib/nif_extractous/priv/native/libnif_extractous-v0.3.2-nif-2.17-aarch64-apple-darwin.so\n  Reason: tried: '/Users/runner/work/nif-extractous/nif-extractous/target/aarch64-apple-darwin/release/build/extractous-1392444ace32bce9/out/tika-native/build/native/nativeCompile/libtika_native.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/nif-extractous/nif-extractous/target/aarch64-apple-darwin/release/build/extractous-1392444ace32bce9/out/tika-native/build/native/nativeCompile/libtika_native.dylib' (no such file), '/Users/runner/work/nif-extractous/nif-extractous/target/aarch64-apple-darwin/release/build/extractous-1392444ace32bce9/out/tika-native/build/native/nativeCompile/libtika_native.dylib' (no such file)'"}
filmor

filmor

Rustler is not aware of the additional libraries that are copied in extractous’s build.rs. You will have to extend your build process to copy them from Rust’s target directory to priv/native/....

snewcomer

snewcomer OP

Phoenix Core Team

Thanks @filmor! Anybody aware of a precedent in the rustler community that we could pull from for this extractous rust library?

snewcomer

snewcomer OP

Phoenix Core Team

A little more investigation…

 ldd _build/prod/rel/**/priv/native/libdoc_extractor.so
	linux-vdso.so.1 (0x0000ffff82483000)
	libtika_native.so => not found
	libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000ffff82380000)
	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffff821d0000)
	/lib/ld-linux-aarch64.so.1 (0x0000ffff8244a000)

So it is just that one libtika_native.so binary. Nothing else. Extending the build process seems like a good path here.

snewcomer

snewcomer OP

Phoenix Core Team

https://github.com/snewcomer/nif-extractous

Alright this ended up working. See README for what I had to do!

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews