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

Hello World example #39

Closed
toinbis opened this issue Sep 11, 2021 · 10 comments
Closed

Hello World example #39

toinbis opened this issue Sep 11, 2021 · 10 comments

Comments

@toinbis
Copy link

toinbis commented Sep 11, 2021

Current examples in https://github.com/cloudflare/workers-rs/blame/main/README.md#L9, https://blog.cloudflare.com/workers-rust-sdk/ and project generated by wrangler generate --type=rust all provide some advanced usage of using router, console_log, DO, POST handling. None of them worked out of the box for me.

For those whose just start out, like me, would it be possible to provide and example worker that just returns Hello world string so we could start from there? Thanks a lot!

@nilslice
Copy link
Contributor

Hi @toinbis -

The project generated with --type rust should definitely work out of the box. Can you share any detail about what failed?

I'll double check the README examples for completeness - they could be missing something. Those aren't really meant to be copy/pasted but I suppose if we put any code out there it should work 😄

@StephenHaney
Copy link

Just in case it's helpful — I had to update Rust to 1.55 using rustup update before the out-of-the-box project would build/deploy.

@nilslice
Copy link
Contributor

Thanks, @StephenHaney, do you recall which version you upgrade from?

I don't think 1.55 is the minimum required, but I could be wrong. I tend to stay on the latest version available - but recognize not everyone does!

@StephenHaney
Copy link

StephenHaney commented Sep 15, 2021

Looks like I was on 1.49... I'm not a regular rust user (yet!), so I was a bit behind. It was throwing syntax errors in worker-build-0.0.1/src/main.rs until I updated.

Also, related to getting the example project to deploy... on Mac ARM CPU, wasm-pack doesn't work (no prebuilt wasm-opt binaries are available for this platform: Unrecognized target!). I had to follow the workaround here: rustwasm/wasm-pack#913 (comment)

From what I was reading, it sounds like wasm-pack just needs to release its newest merged code before that'll start working automatically on M1 CPUs (unconfirmed, just what I read).

Once I figured those two bits out, I was able to wrangler publisher the project template without issue. Very cool!

@nilslice
Copy link
Contributor

Ah, that would explain it -- there are some features we use that are ahead of that release. We're still trying to determine the minimum version required, and it's probably around 1.53. Anyway, glad its working now!

Yea the M1 support is a little tricky with the dependencies we don't control.. and I haven't determined a way to just tell wasm-pack to install an x86 binary and let Rosetta2 do it's thing if we detect an M1 system.

@nilslice
Copy link
Contributor

I think this is mostly resolved from the recommendation to upgrade rust versions. I will do another pass though ASAP to ensure everything we publish is buildable. Thanks!

@TRomesh
Copy link

TRomesh commented Sep 18, 2021

I'm quite new to Rust and Workers as well and I have the same issue as @toinbis. @nilslice it would be great if you can provide examples for GET, POST, PUT requests and working with params and queries.

@nilslice
Copy link
Contributor

Sure thing - we'll get some more examples up ASAP.

@TRomesh
Copy link

TRomesh commented Sep 29, 2021

Hi @nilslice any update on the examples? :)

@nilslice
Copy link
Contributor

Hi @TRomesh -

I just returned from vacation and getting back into the swing of things, but it's definitely on my list.

In the meantime, take a look at the worker-sandbox directory in this repo which might have more "how-to" usage examples. It's a bit messy, but it's used to test most of the features in workers-rs.

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

4 participants