Closed phntxx closed 1 year ago
Hello!
Did you use cargo generate
from a different folder, not a nested folder of this repo?
cargo generate
seems to get confused if nesting the git repos.
I ran cargo generate -g https://github.com/kubewarden/rust-policy-template.git
in a normal folder (and on my desktop) to confirm this behavior.
I filled out the metadata, just as cargo generate
prompted me to.
I don't think the issue lies in the fact that this is a template (shouldn't an empty project still compile without error?), but rather the fact that this might not be entirely compatible with macOS.
When trying to run make policy.wasm
just now, I got the following error:
$ make policy.wasm
sed: illegal option -- -
usage: sed script [-Ealnru] [-i extension] [file ...]
sed [-Ealnu] [-i extension] [-e script] ... [-f script_file] ... [file ...]
cargo build --target=wasm32-wasi --release
Compiling proc-macro2 v1.0.60
Compiling num-traits v0.2.15
Compiling num-integer v0.1.45
Compiling num-bigint v0.4.3
Compiling quote v1.0.28
Compiling serde v1.0.164
Compiling libc v0.2.146
Compiling lock_api v0.4.10
Compiling tinyvec_macros v0.1.1
Compiling parking_lot_core v0.9.8
Compiling num-rational v0.4.1
error[E0463]: can't find crate for `core`
|
= note: the `wasm32-wasi` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-wasi`
error[E0463]: can't find crate for `compiler_builtins`
For more information about this error, try `rustc --explain E0463`.
error: could not compile `tinyvec_macros` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error[E0432]: unresolved imports `super::Send`, `super::Sync`, `ffi::c_void`
--> /Users/phntxx/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.146/src/wasi.rs:1:13
|
1 | use super::{Send, Sync};
| ^^^^ ^^^^
2 |
3 | pub use ffi::c_void;
| ^^^^^^^^^^^
Some errors have detailed explanations: E0432, E0463.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `libc` due to 3 previous errors
make: *** [policy.wasm] Error 101
Despite the fact that wasm32-wasi
is installed and up-to-date:
$ rustup target add wasm32-wasi
info: component 'rust-std' for target 'wasm32-wasi' is up to date
The sed
-error at the very beginning of the error message comes from this string in the Makefile:
VERSION := $(shell sed --posix -n 's,^version = \"\(.*\)\",\1,p' Cargo.toml)
Replacing this with VERSION = "0.1.0"
yields no improvement.
but rather the fact that this might not be entirely compatible with macOS. ... Replacing this with VERSION = "0.1.0" yields no improvement.
Indeed, there seem to be 2 issues here.
The first is incompatibilities between Macos sed
(from OpenBSD), and GNU sed
on Linux (CI, devs machines).
A workaround is to hardcode the version in the Makefile with VERSION := "0.1.0"
as you have done. Another one would be to install GNU sed in Macos.
Once you applied that workaround, it seems it continued to the compilation step.
This is a legitimate issue, I will look into a solution. This possibly applies to the other rust policy repositories too.
The second issue seems to be that your rust installation is not finding your std lib for wasm32-wasi as you see.
Given that rustup
says it is there, I'm inclined to think that the rust installation is somehow broken.
Are you using a nigthly install of rust? Do you maybe have installed rust both from brew
and rustup
? (I recommend only having from rustup)
Have you had a look at the workarounds from rustc --explain E0432
the compiler points?
(shouldn't an empty project still compile without error?)
Yet this isn't an empty project, is a template. E.g., notice the Jinja templating in https://github.com/kubewarden/rust-policy-template/blob/main/Cargo.toml or https://github.com/kubewarden/rust-policy-template/blob/main/metadata.yml. One can always skip cargo generate
and edit those by hand though.
Thank you very much for your help!
The issue was that I had both the rustup-init
and rust
packages installed at the same time.
Once I removed both, removed my ~/.cargo
directory and reinstalled rust using rustup-init
, the project compiles without a hitch.
Once again: thank you very much for assisting me in this layer 8 issue!
Is there an existing issue for this?
Current Behavior
When trying to run
make policy.wasm
, the compiler just throws a bunch of errors.Expected Behavior
make policy.wasm
returns a WebAssembly file.Steps To Reproduce
make policy.wasm
Environment
Anything else?
No response