containerd-shim-spin icon indicating copy to clipboard operation
containerd-shim-spin copied to clipboard

Building for RISCV64?

Open matsbror opened this issue 1 year ago • 11 comments

Did anyone try to build for RISCV64?

The regular Make (with TARGET set to riscv64gc-unknown-linux-gnu) doesn't work.

matsbror avatar May 06 '24 10:05 matsbror

Hey, @matsbror, thank you for reporting this. Would you mind sharing the output of running the build command, please?

For context, we do know at least the Wasmtime / Spin dependency for the shim (the part executing Wasm) does compile and run correctly on RISC-V. I don't have a lot of context for the containerd / youki dependencies, so paging @Mossaka for some help on it.

radu-matei avatar May 06 '24 14:05 radu-matei

I am on v0.13.1. On my RISCV64-board, I try to build it directly like:

cargo build --release --target riscv64gc-unknown-linux-gnu --manifest-path=containerd-shim-spin/Cargo.toml                                                                                            

as I had issues with the Makefile

It fails trying to compile ring.

error: failed to run custom build command for `ring v0.16.20`

I have wasmtime cli running fine so I know that that part is working. I remember I had issues with the ring crate a long time ago when running the sightglass benchmarks in wasmtime. Then I believe I resolved by using a local copy of precision which used ring. Ring 0.17 has resolved the issue on RISCV, but these are the crates in Cargo.lock that refers to ring v0.16.20:

  • aws-config (I don't care about this)
  • rustls

aws-config in turns is used by trigger-sqs and rustls used by wasmtime-wasi-http, which I definitely want.

I will continue to investigate if there is a way to remove or upgrade these dependencies so that ring 0.17.8 is used instead.

EDIT: I should add that I get the same error when cross-compiling on an x86 machine.

matsbror avatar May 06 '24 15:05 matsbror

Adding @tschneidereit who had success running Spin on a RISCV64 board.

radu-matei avatar May 06 '24 15:05 radu-matei

I managed to build runwasi by removing the Cargo.lock file so that cargo could rebuild the dependencies from scratch. That did not work for this repo. However, the issue lies in trigger-sqs. As far as I understand, this is related to AWS and I do not intend to use AWS for this project (now RISCV-instances there :-) so how can I remove that dependency?

matsbror avatar May 07 '24 08:05 matsbror

We should put the other triggers behind Cargo features, to make this kind of thing easier.

Specifically, to unblock your use case, you can:

  • comment the dependency in Cargo.toml: https://github.com/spinkube/containerd-shim-spin/blob/main/containerd-shim-spin/Cargo.toml#L24
  • comment https://github.com/spinkube/containerd-shim-spin/blob/main/containerd-shim-spin/src/engine.rs#L238-L246 and https://github.com/spinkube/containerd-shim-spin/blob/main/containerd-shim-spin/src/engine.rs#L484

radu-matei avatar May 07 '24 08:05 radu-matei

Unfortunately I still do not have success. spin-trigger-http needs tokio-rustls which needs rustls which uses `ring 0.16.20. I tried to force cargo to replace ring 0.16.20 with 0.17.8 using:

[replace]
"ring:0.16.20" = { git = "https://github.com/briansmith/ring" }

at the top-level Cargo.toml, but it failed as rustls required v0.16.20

matsbror avatar May 07 '24 11:05 matsbror

When I experimented with this last Fall, there was no version of Ring released that would've supported RISCV, so I hacked something up that Worked On My Machine.

By now this should all be much easier, luckily: there's a pretty recent release of tokio-rustls that depends on ring 0.17, which should be recent enough, I think. I don't know how involved updating tokio-rustls would be, but I'd hope that it's not too heavy a lift.

tschneidereit avatar May 07 '24 16:05 tschneidereit

Thanks @tschneidereit , but how do I replace the dependency on ring or tokio-rustls as they are not top-level dependencies?

matsbror avatar May 07 '24 18:05 matsbror

it seems like tokio-rustls is the dependency to replace/update here. If we're really lucky, the version of that which (via its updated ring dependency) supports RISCV is API-compatible for our purposes. If that is the case, you should be able to get a build by adding this to your project's Cargo.toml file:

[patch.crates-io]
tokio-rustls = { git = 'https://github.com/rustls/tokio-rustls.git', tag = "v/0.26.0" }

If that doesn't work out of the box, it's possible that slight adjustments would fix it.

If that works, a PR to the spin repo updating the dependency would be fantastic!

tschneidereit avatar May 08 '24 10:05 tschneidereit

I managed to resolve the issue for me.

I updated the dependency in spin/crates/trigger-http/Cargo.toml of tokio-rustls to version 0.24.1. That was enough to push ring to version 0.17.8 without breaking anything else.

This one resolved the issue for containerd-shim-spin also but I had to add a dependency to spin-ecpressions in the spin repo.

However, I cannot (now) make a PR for spin on this as I am not able to run tests (even on main branch) and I know too little to fix it.

matsbror avatar May 10 '24 10:05 matsbror

I can add riscv64gc-unknown-linux-gnu target to the CI pipeline to make sure the shim compiles against this new target. I am not sure what kind of issues you ran into with tests.

Mossaka avatar Feb 14 '25 01:02 Mossaka