All Projects → mike-engel → Vercel Rust

mike-engel / Vercel Rust

Licence: mit
Community based builder for using rust on the now/zeit platform

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Vercel Rust

now-custom-runtime
ZEIT Now v2.0 builder for custom AWS Lambda runtimes
Stars: ✭ 21 (-87.5%)
Mutual labels:  builder, now, zeit
Now Builders
Official Now Builders created by the ZEIT team
Stars: ✭ 483 (+187.5%)
Mutual labels:  builder, now, zeit
Vercel Php
▲ Vercel PHP runtime • vercel-php • now-php • 🐘+ λ = ❤
Stars: ✭ 429 (+155.36%)
Mutual labels:  now, zeit
Vercel Builder
Vercel Builder for Nuxt.js
Stars: ✭ 437 (+160.12%)
Mutual labels:  now, zeit
Jwt Example
Playing with user registration, login/logout, auth, etc using JWTs, serverless functions & faunadb as the data store.
Stars: ✭ 22 (-86.9%)
Mutual labels:  now, zeit
Now Pipeline
Simple CI pipeline with goal to deploy new version at Zeit Now cloud if tests pass
Stars: ✭ 143 (-14.88%)
Mutual labels:  now, zeit
Meteor Now
Instantly deploy your Meteor apps with `meteor-now`
Stars: ✭ 339 (+101.79%)
Mutual labels:  now, zeit
Deploy.now
One click deploys to △ now
Stars: ✭ 121 (-27.98%)
Mutual labels:  now, zeit
now-docs
[WIP] Deploy docs with a single command using Now
Stars: ✭ 45 (-73.21%)
Mutual labels:  now, zeit
Create React App Now
Hello, create-react-app, meet Zeit's awesome now.sh service.
Stars: ✭ 137 (-18.45%)
Mutual labels:  now, zeit
Now Storage
Use Now static deployments to upload and store files.
Stars: ✭ 91 (-45.83%)
Mutual labels:  now, zeit
Nextjs Vercel Firebase
Next.js app using API routes to connect with Firestore.
Stars: ✭ 133 (-20.83%)
Mutual labels:  now, zeit
Covid19 Brazil Api
API com dados atualizados sobre o status do COVID-19 🦠
Stars: ✭ 300 (+78.57%)
Mutual labels:  now, zeit
now-course
Proyecto para el curso de Now.sh en Platzi
Stars: ✭ 19 (-88.69%)
Mutual labels:  now, zeit
Micro Proxy
[DEPRECATED] Simplest proxy server for microservices
Stars: ✭ 358 (+113.1%)
Mutual labels:  now, zeit
notion-custom-domain
📝 Custom domains for your public Notion pages
Stars: ✭ 23 (-86.31%)
Mutual labels:  now, zeit
Stage Ci
Automatic deploy previews for your PRs using zeit.co/now.
Stars: ✭ 132 (-21.43%)
Mutual labels:  now, zeit
docker-craft-nginx
🐳 A minimal Docker container for Craft CMS, intended for use with zeit-now.
Stars: ✭ 26 (-84.52%)
Mutual labels:  now, zeit
now dashboard
▲ZEIT dashboard written in elm
Stars: ✭ 52 (-69.05%)
Mutual labels:  now, zeit
Now Clear
A utility to delete all zeit now instances that aren't aliased
Stars: ✭ 12 (-92.86%)
Mutual labels:  now, zeit

vercel-rust

Community based builder for using rust on the Vercel platform


Looking for maintainers

I don't use this project any longer, and the time I can dedicate to maintaining this project is very low. If you'd like to help maintain the project, please contact me via an issue or email.


This is a vercel builder which allows you to run your rust code as lambdas on the vercel platform!

This was originally provided officially by Vercel's now archived now-builders monorepo, but has since been moved to a community-maintained project.

Usage

If you're unfamiliar with vercel runtimes, please read the runtime docs first. This runtime can be used like any other Community Runtime.

{
	"functions": {
		"api/**/*.rs": {
			"runtime": "[email protected]"
		}
	}
}

That's the simplest way to use this runtime!

Entrypoint

The entrypoint, in this case every file that matches api/**/*.rs, is used to create a Serverless Function for you. Note that the Cargo.toml file must exist on the same level as the .rs files.

Dependencies

This Builder supports installing dependencies defined in the Cargo.toml file.

Furthermore, more system dependencies can be installed at build time with the presence of a shell build.sh file in the same directory as the entrypoint file.

Unlisted Utility Functions

Utility functions could be created as described in Prevent Endpoint Listing. To make use of them make sure to include them in the Cargo.toml under [lib].

Example

This could be our api/user.rs file:

use util::print_foo;
use http::{StatusCode};
use vercel_lambda::{lambda, error::VercelError, IntoResponse, Request, Response};
use std::error::Error;

fn handler(_: Request) -> Result<impl IntoResponse, VercelError> {
	print_foo();
	let response = Response::builder()
		.status(StatusCode::OK)
		.header("Content-Type", "text/plain")
		.body("user endpoint")
		.expect("Internal Server Error");

		Ok(response)
}

// Start the runtime with the handler
fn main() -> Result<(), Box<dyn Error>> {
	Ok(lambda!(handler))
}

Our helper utilities api/_util.rs file:

pub fn print_foo() {
	println!("foo");
}

Our api/Cargo.toml could look like this:

[package]
name = "index"
version = "2.0.0"
authors = ["Mike Engel <[email protected]>"]
edition = "2018"

[dependencies]
http = "0.1"
vercel_lambda = "*"

[lib]
name = "util"
path = "_util.rs"

Finally we need a vercel.json file to specify the runtime for api/user.rs:

{
	"functions": {
		"api/**/*.rs": {
			"runtime": "[email protected]"
		}
	}
}

FAQ

Are cargo workspaces supported?

Not quite. Cargo's workspaces feature is a great tool when working on multiple binaries and libraries in a single project. If a cargo workspace is found in the entrypoint, however, vercel-rust will fail to build.

To get around this limitation, create build entries in your vercel.json file for each Cargo.toml that represents a lambda function within your workspace. In your .vercelignore, you'll want to add any binary or library project folders that aren't needed for your lambdas to speed up the build process like your Cargo.toml workspace.

It's also recommended to have a Cargo.lock alongside your lambda Cargo.toml files to speed up the build process. You can do this by running cargo check or a similar command within each project folder that contains a lambda.

If you have a compelling case for workspaces to be supported by vercel-rust which are too cumbersome with this workaround, please submit an issue! We're always looking for feedback.

How do I use this during local development?

The vercel dev command allows you to develop lambdas locally on your machine. With vercel dev and vercel-rust you can develop your rust-based lamdas on your own machine.

During local development with vercel dev, the assumption is that rust and cargo are already installed and available in your PATH since they will not be installed automatically. The recommended way to install rust and cargo on your machine is with rustup.

Can I use musl/static linking?

Unfortunately, the AWS lambda runtime for rust relies (tangentially) on proc_macro, which won't compile on musl targets. Without musl, all linking must be dynamic. If you have a crate that relies on system libraries like postgres or mysql, you can include those library files with the includeFiles config option and set the proper environment variables, config, etc. that you need to get the library to compile.

For more info, please see issue #2.

Why does this project use tabs over spaces?

Please refer to this tweet.

Contibuting

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Issues and pull requests are welcome!

Setup

Since this project contains both rust and node code, you need to install the relevant dependencies. If you're only working on the javascript side, you only need to install those dependencies. The oppoosite is true for the rust side.

# install node dependencies
npm install

# install cargo dependencies
cargo fetch

At this point, you're all set up and can start making edits!

Note: During the migration period, tests will be broken until we get CI set up!

License

MIT

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Mike Engel
Mike Engel

💬 💻 📖 💡 ⚠️ 👀 🚧 🎨 🚇 🤔 🖋
Antonio Nuno Monteiro
Antonio Nuno Monteiro

💬 💻 📖 💡 ⚠️ 👀 🚧 🎨 🚇 🤔 🖋
Jacob Mischka
Jacob Mischka

💻
Endre
Endre

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].