Error while building function with KNative

I was trying to build a Serverless application with Knative while using Rust. The program run well locally after calling cargo build. However before deploying the project, I keep ending with the error below.

Installing function v0.1.0 (/workspace)
      error: failed to get `actix-http` as a dependency of package `function v0.1.0 (/workspace)`
      
      Caused by:
        failed to load source for dependency `actix-http`
      
      Caused by:
        Unable to update registry `crates-io`
      
      Caused by:
        usage of sparse registries requires `-Z sparse-registry`
unable to invoke layer creator
unable to contribute application layer
unable to install single
unable to build
exit status 101
ERROR: failed to build: exit status 1

Error: failed to build the function: executing lifecycle: failed with status code: 51
Error: exit status 1

I've been looking for solutions to solve this without any luck. Can someone help me figure out how to resolve this issue.

It looks like you are trying to use the sparse registry feature of cargo, which is still unstable. Unstable features can only be used with nightly rust. Try disabling sparse registry.

Can you explain to me how to do that?? This is new to me.

What is the content of ~/.cargo/config and ~/.cargo/config.toml? Also how are you building it?

Hmmmm for some reason I can't find those files. Also, I'm just building it with Knative using kn func build. I already did cargo build before.

Maybe kn enables sparse registry? Where did you get this kn command you are using from?

I got it from here:

Running cargo build worked, I reckon?

You could try disabling sparse indexing with an environment variable. Could you try running:

CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git kn func build

and see if it works?

  1. Yes, the build completes after calling cargo build
  2. I tried running the command you sent me and it doesn't work.

AFAICT from sifting through the func repo, I'm quite sure functions uses this rust buildpack from the paketo community for creating the container for your function (based on this manifest file from the Rust function templates). That buildpack depends on the cargo buildpack, which enables sparse registries by default. AFAICT they don't offer an environment variable for changing that. Maybe raise an issue with the cargo buildpack? I'm not that good at reading Go and I have no experience with knative functions nor buildpack, so better fact-check my research :sweat_smile:.

@dasnoob Someone who seems to be one of the maintainers replied at Update Cargo/crates.io Sparse Index support by dmikusa · Pull Request #217 · paketo-community/cargo · GitHub. They are asking if an issue can be opened with a project that reproduces the issue.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.