From f78ec9b4a8f8b48e7d569732e74035bf9600a814 Mon Sep 17 00:00:00 2001 From: Tomio Date: Mon, 20 Jun 2022 14:22:44 +0800 Subject: [PATCH 1/4] add support for building rust with linked c libraries --- examples/rust-ring/.gitignore | 14 ++++++++++++++ examples/rust-ring/Cargo.toml | 9 +++++++++ examples/rust-ring/src/main.rs | 5 +++++ src/providers/rust.rs | 2 ++ tests/docker_run_tests.rs | 7 +++++++ 5 files changed, 37 insertions(+) create mode 100644 examples/rust-ring/.gitignore create mode 100644 examples/rust-ring/Cargo.toml create mode 100644 examples/rust-ring/src/main.rs diff --git a/examples/rust-ring/.gitignore b/examples/rust-ring/.gitignore new file mode 100644 index 000000000..4bb7fbcf1 --- /dev/null +++ b/examples/rust-ring/.gitignore @@ -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 + diff --git a/examples/rust-ring/Cargo.toml b/examples/rust-ring/Cargo.toml new file mode 100644 index 000000000..9ae04cd79 --- /dev/null +++ b/examples/rust-ring/Cargo.toml @@ -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" diff --git a/examples/rust-ring/src/main.rs b/examples/rust-ring/src/main.rs new file mode 100644 index 000000000..869006dbc --- /dev/null +++ b/examples/rust-ring/src/main.rs @@ -0,0 +1,5 @@ +use ring as _; + +fn main() { + println!("Hello from rust"); +} diff --git a/src/providers/rust.rs b/src/providers/rust.rs index 86edd4f64..f66c6fe87 100644 --- a/src/providers/rust.rs +++ b/src/providers/rust.rs @@ -52,6 +52,8 @@ impl Provider for RustProvider { setup_phase.add_file_dependency(toolchain_file); } + setup_phase.add_apt_pkgs(vec!["musl-tools".to_string()]); + Ok(Some(setup_phase)) } diff --git a/tests/docker_run_tests.rs b/tests/docker_run_tests.rs index 42d5a84e9..8a5011069 100644 --- a/tests/docker_run_tests.rs +++ b/tests/docker_run_tests.rs @@ -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"); From f1c7d0d76b796698f60bf256a038adbead1cb9d2 Mon Sep 17 00:00:00 2001 From: Tomio Date: Mon, 20 Jun 2022 14:29:46 +0800 Subject: [PATCH 2/4] debug --- tests/docker_run_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker_run_tests.rs b/tests/docker_run_tests.rs index 8a5011069..7aeb9be1e 100644 --- a/tests/docker_run_tests.rs +++ b/tests/docker_run_tests.rs @@ -115,7 +115,7 @@ fn simple_build(path: &str) -> String { }, &DockerBuilderOptions { name: Some(name.clone()), - quiet: true, + quiet: false, ..Default::default() }, ) From e2303ffd99103f51bebe09649c7e060f4cfbbb8f Mon Sep 17 00:00:00 2001 From: Tomio Date: Mon, 20 Jun 2022 14:34:52 +0800 Subject: [PATCH 3/4] ready for review --- tests/docker_run_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker_run_tests.rs b/tests/docker_run_tests.rs index 7aeb9be1e..8a5011069 100644 --- a/tests/docker_run_tests.rs +++ b/tests/docker_run_tests.rs @@ -115,7 +115,7 @@ fn simple_build(path: &str) -> String { }, &DockerBuilderOptions { name: Some(name.clone()), - quiet: false, + quiet: true, ..Default::default() }, ) From 6c57a20f0acfbce05efcbcb20b48f9e06f0f19b1 Mon Sep 17 00:00:00 2001 From: Tomio Date: Mon, 20 Jun 2022 18:08:18 +0800 Subject: [PATCH 4/4] only install musl-tools when `NO_MUSL` isn't set --- src/providers/rust.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/providers/rust.rs b/src/providers/rust.rs index f66c6fe87..d87aab736 100644 --- a/src/providers/rust.rs +++ b/src/providers/rust.rs @@ -52,7 +52,9 @@ impl Provider for RustProvider { setup_phase.add_file_dependency(toolchain_file); } - setup_phase.add_apt_pkgs(vec!["musl-tools".to_string()]); + if !env.is_config_variable_truthy("NO_MUSL") { + setup_phase.add_apt_pkgs(vec!["musl-tools".to_string()]); + } Ok(Some(setup_phase)) }