forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request NixOS#12 from railwayapp/jr/rust-provider
Rust provider
- Loading branch information
Showing
11 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/rust | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=rust | ||
|
||
### Rust ### | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/rust | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "rocket" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rocket = "0.5.0-rc.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[macro_use] | ||
extern crate rocket; | ||
|
||
#[get("/")] | ||
fn index() -> &'static str { | ||
"Hello, from Rocket!" | ||
} | ||
|
||
#[launch] | ||
fn rocket() -> _ { | ||
rocket::build().mount("/", routes![index]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use super::Provider; | ||
use crate::{nixpacks::app::App, providers::Pkg}; | ||
use anyhow::{Context, Result}; | ||
|
||
pub struct RustProvider {} | ||
|
||
impl Provider for RustProvider { | ||
fn name(&self) -> &str { | ||
"rust" | ||
} | ||
|
||
fn detect(&self, app: &App) -> Result<bool> { | ||
Ok(app.includes_file("Cargo.toml")) | ||
} | ||
|
||
fn pkgs(&self, _app: &App) -> Vec<Pkg> { | ||
vec![ | ||
Pkg::new("pkgs.stdenv"), | ||
Pkg::new("pkgs.gcc"), | ||
Pkg::new("pkgs.rustc"), | ||
Pkg::new("pkgs.cargo"), | ||
] | ||
} | ||
|
||
fn install_cmd(&self, _app: &App) -> Result<Option<String>> { | ||
Ok(None) | ||
} | ||
|
||
fn suggested_build_cmd(&self, _app: &App) -> Result<Option<String>> { | ||
Ok(Some("cargo build --release".to_string())) | ||
} | ||
|
||
fn suggested_start_command(&self, app: &App) -> Result<Option<String>> { | ||
if app.includes_file("Cargo.toml") { | ||
// Parse name from Cargo.toml so we can run ./target/release/{name} | ||
let toml_file: toml::Value = | ||
app.read_toml("Cargo.toml").context("Reading Cargo.toml")?; | ||
let name = toml_file | ||
.get("package") | ||
.and_then(|package| package.get("name")) | ||
.and_then(|v| v.as_str()); | ||
|
||
if let Some(name) = name { | ||
return Ok(Some(format!( | ||
"ROCKET_ADDRESS=0.0.0.0 ./target/release/{}", | ||
name | ||
))); | ||
} | ||
} | ||
|
||
Ok(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters