Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run build on Mac #1

Open
benjinus opened this issue Jun 30, 2021 · 5 comments
Open

How to run build on Mac #1

benjinus opened this issue Jun 30, 2021 · 5 comments

Comments

@benjinus
Copy link

This is a great project. For a long time, I have been looking for a compression library that can be used in both the browser and the node environment. I also tested multiple similar libraries. I found that your library is currently more suitable for me. Sincere thanks。
Now I need to port the compilation process of this library to my project compilation process, but I don't know much about the compilation process of webassembly. I tried to use the build command in this library without success. Is there a way to help me compile this library on my mac? If possible, it would be a great help.

截屏2021-06-30 09 41 39

@pimterry
Copy link
Member

Under the hood, the compilation is really all powered by wasm-pack, which automates pretty much the whole rust -> wasm compilation process.

Have you run npm install before running npm run build? Do you have wasm-pack available in node_modules/.bin/ afterwards? That should be all that's required I think.

If that's installed, then building should print something like this:

> [email protected] build /.../brotli-wasm
> node ./build.js

[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
    Finished release [optimized] target(s) in 0.03s
[INFO]: Installing wasm-bindgen...
[INFO]: Optimizing wasm binaries with `wasm-opt`...
...

Internally, that's just running this script which runs wasm-pack with various arguments and copies files in and out, there's not much else involved. From your logs, it looks like wasm-pack isn't being found or run at all for some reason.

@benjinus
Copy link
Author

benjinus commented Jul 1, 2021

After installing rust, I have compiled successfully. thank you very much.
截屏2021-07-01 14 08 13

@pimterry
Copy link
Member

pimterry commented Jul 1, 2021

Aha! Of course, yes, that makes sense.

Is there a specific command that was missing? I guess rustc? If there's a quick way to check for the missing components (or one that works for your case at least) then I'd really appreciate a PR to add that at the top of https://github.com/httptoolkit/brotli-wasm/blob/main/build.js to help out the next person who runs into this.

@jameswomack
Copy link

FWIW, even after installing rustc I saw this:

> $ npm run build                                                                                                                                                                                                                 ⬡ 20.9.0 [±main ✓]

> [email protected] build
> node ./build.js

[INFO]: Checking for the Wasm target...
Error: wasm32-unknown-unknown target not found in sysroot: "/opt/homebrew/Cellar/rust/1.77.2"

Used rustc from the following path: "/opt/homebrew/bin/rustc"
It looks like Rustup is not being used. For non-Rustup setups, the wasm32-unknown-unknown target needs to be installed manually. See https://rustwasm.github.io/wasm-pack/book/prerequisites/non-rustup-setups.html on how to do this.

mv: no such file or directory: pkg
rm: no such file or directory: pkg.bundler/{LICENSE,package.json,README.md,.gitignore}
[INFO]: Checking for the Wasm target...
Error: wasm32-unknown-unknown target not found in sysroot: "/opt/homebrew/Cellar/rust/1.77.2"

Used rustc from the following path: "/opt/homebrew/bin/rustc"
It looks like Rustup is not being used. For non-Rustup setups, the wasm32-unknown-unknown target needs to be installed manually. See https://rustwasm.github.io/wasm-pack/book/prerequisites/non-rustup-setups.html on how to do this.

mv: no such file or directory: pkg
rm: no such file or directory: pkg.node/{LICENSE,package.json,README.md,.gitignore}
[INFO]: Checking for the Wasm target...
Error: wasm32-unknown-unknown target not found in sysroot: "/opt/homebrew/Cellar/rust/1.77.2"

Used rustc from the following path: "/opt/homebrew/bin/rustc"
It looks like Rustup is not being used. For non-Rustup setups, the wasm32-unknown-unknown target needs to be installed manually. See https://rustwasm.github.io/wasm-pack/book/prerequisites/non-rustup-setups.html on how to do this.

mv: no such file or directory: pkg
rm: no such file or directory: pkg.web/{LICENSE,package.json,README.md,.gitignore}

And trying to then install Rustup resulted in

> $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh                                                                                                                                                                ⬡ 20.9.0 [±main ✓]
info: downloading installer
warning: it looks like you have an existing installation of Rust at:
warning: /opt/homebrew/bin
warning: It is recommended that rustup be the primary Rust installation.
warning: Otherwise you may have confusion unless you are careful with your PATH
warning: If you are sure that you want both rustup and your already installed Rust
warning: then please reply `y' or `yes' or set RUSTUP_INIT_SKIP_PATH_CHECK to yes
warning: or pass `-y' to ignore all ignorable checks.
error: cannot install while Rust is installed

Continue? (y/N) n

error: cannot install while Rust is installed

So it appears not just Rust, but a specific style of installing Rust is required (curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh).

Also needed to manually as $HOME/.cargo/bin to $PATH,

@pimterry
Copy link
Member

So it appears not just Rust, but a specific style of installing Rust is required (curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh).

Worth noting that this isn't just an arbitrary style - it's the officially recommended way to install rust for all users: https://www.rust-lang.org/tools/install.

They do offer other installation methods for special cases, including Homebrew (I think that's what you've used here?) but in general you shouldn't use them unless you know what you're doing - without rustup you can't easily manage a rust toolchain to add extra targets etc.

PRs to the docs for this welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants