Skip to content

Commit

Permalink
Add support for building rust with linked c libraries (#218)
Browse files Browse the repository at this point in the history
* add support for building rust with linked c libraries

* debug

* ready for review

* only install musl-tools when `NO_MUSL` isn't set
  • Loading branch information
Tomio authored Jun 20, 2022
1 parent c50a748 commit 2be1cb6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/rust-ring/.gitignore
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

9 changes: 9 additions & 0 deletions examples/rust-ring/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rust-ring"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ring = "0.16.20"
5 changes: 5 additions & 0 deletions examples/rust-ring/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use ring as _;

fn main() {
println!("Hello from rust");
}
4 changes: 4 additions & 0 deletions src/providers/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ impl Provider for RustProvider {
setup_phase.add_file_dependency(toolchain_file);
}

if !env.is_config_variable_truthy("NO_MUSL") {
setup_phase.add_apt_pkgs(vec!["musl-tools".to_string()]);
}

Ok(Some(setup_phase))
}

Expand Down
7 changes: 7 additions & 0 deletions tests/docker_run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ fn test_rust_custom_version() {
assert!(output.contains("cargo 1.56.0"));
}

#[test]
fn test_rust_ring() {
let name = simple_build("./examples/rust-ring");
let output = run_image(name, None);
assert!(output.contains("Hello from rust"));
}

#[test]
fn test_go() {
let name = simple_build("./examples/go");
Expand Down

0 comments on commit 2be1cb6

Please sign in to comment.