Skip to content

Commit 55cdf52

Browse files
committed
feat: embed wrappers into ELF binaries
1 parent 182c37f commit 55cdf52

File tree

29 files changed

+4401
-33
lines changed

29 files changed

+4401
-33
lines changed

packages/std/Cargo.lock

Lines changed: 133 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/std/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
3-
"packages/cc_proxy",
3+
"packages/cc_proxy",
4+
"packages/convert_manifest",
45
"packages/ld_proxy",
56
"packages/strip_proxy",
67
"packages/wrapper",
@@ -26,6 +27,7 @@ pedantic = { level = "warn", priority = -1 }
2627
result_large_err = "allow"
2728

2829
[workspace.dependencies]
30+
bytes = { version = "1", features = ["serde"] }
2931
clap = { version = "4", features = ["derive"] }
3032
fnv = "1"
3133
futures = "0.3"
@@ -35,6 +37,7 @@ libc = "0.2"
3537
serde = { version = "1", features = ["derive"] }
3638
serde_json = "1"
3739
tangram_client = { default-features = false, git = "https://github.com/tangramdotdev/tangram", rev = "17c7b14774e13c07e7e21f25cfa518947de6a65d" }
40+
tangram_serialize = { default-features = false, git = "https://github.com/tangramdotdev/tangram", rev = "17c7b14774e13c07e7e21f25cfa518947de6a65d" }
3841
tempfile = "3"
3942
tokio = { version = "1", default-features = false, features = [
4043
"rt",
@@ -77,10 +80,13 @@ path = "packages/std/lib.rs"
7780
workspace = true
7881

7982
[dependencies]
83+
bytes = { workspace = true }
8084
futures = { workspace = true }
8185
serde = { workspace = true }
8286
serde_json = { workspace = true }
8387
tangram_client = { workspace = true }
88+
tangram_serialize = { workspace = true }
89+
tempfile = { workspace = true }
8490
tracing = { workspace = true, optional = true }
8591
tracing-subscriber = { workspace = true, optional = true }
8692

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "tangram_convert_manifest"
3+
authors.workspace = true
4+
description.workspace = true
5+
edition.workspace = true
6+
homepage.workspace = true
7+
license.workspace = true
8+
publish.workspace = true
9+
repository.workspace = true
10+
rust-version.workspace = true
11+
version.workspace = true
12+
13+
[dependencies]
14+
clap = { workspace = true }
15+
tangram_std = { workspace = true }
16+
tangram_serialize = { workspace = true }
17+
serde_json = { workspace = true }
18+
19+
[lints]
20+
workspace = true
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::io::{Read, Write};
2+
3+
use tangram_std::Manifest;
4+
5+
#[derive(clap::Parser)]
6+
struct Args {
7+
#[arg(short, long)]
8+
output: Output,
9+
}
10+
11+
#[derive(clap::ValueEnum, Copy, Clone)]
12+
enum Output {
13+
Bin,
14+
Json,
15+
}
16+
17+
fn main() -> std::io::Result<()> {
18+
let args = <Args as clap::Parser>::parse();
19+
let mut input = Vec::new();
20+
std::io::stdin().read_to_end(&mut input)?;
21+
22+
let manifest: Manifest = if input.starts_with(b"{") {
23+
serde_json::from_slice(&input).map_err(|error| std::io::Error::other(error.to_string()))?
24+
} else {
25+
tangram_serialize::from_slice(&input)
26+
.map_err(|error| std::io::Error::other(error.to_string()))?
27+
};
28+
29+
let output = match args.output {
30+
Output::Bin => tangram_serialize::to_vec(&manifest)
31+
.map_err(|error| std::io::Error::other(error.to_string()))?,
32+
Output::Json => serde_json::to_vec(&manifest)
33+
.map_err(|error| std::io::Error::other(error.to_string()))?,
34+
};
35+
36+
std::io::stdout().write_all(&output)?;
37+
38+
Ok(())
39+
}

packages/std/packages/ld_proxy/src/main.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ struct Options {
7575
/// If any NEEDED libraries are missing at the end, should we still produce a wrapper?. Will warn if false, error if true. Default: false.
7676
disallow_missing: bool,
7777

78+
/// If enabled, the wrapper will be embedded into the binary.
79+
embed: bool,
80+
7881
/// The interpreter used by the output executable.
7982
interpreter_path: Option<String>,
8083

@@ -122,6 +125,9 @@ fn read_options() -> tg::Result<Options> {
122125
// Get the interpreter path.
123126
let interpreter_path = std::env::var("TANGRAM_LINKER_INTERPRETER_PATH").ok();
124127

128+
// Get the wrap binary.
129+
let mut embed = std::env::var("TANGRAM_LINKER_EMBED_WRAPPER").is_ok();
130+
125131
// Get additional interpreter args, if any.
126132
let interpreter_args = std::env::var("TANGRAM_LINKER_INTERPRETER_ARGS")
127133
.ok()
@@ -176,6 +182,8 @@ fn read_options() -> tg::Result<Options> {
176182
passthrough = true;
177183
} else if arg.starts_with("--tg-disallow-missing") {
178184
disallow_missing = true;
185+
} else if arg.starts_with("--tg-embed-wrapper") {
186+
embed = true;
179187
} else {
180188
command_args.push(arg.clone());
181189
}
@@ -223,6 +231,7 @@ fn read_options() -> tg::Result<Options> {
223231
command_path,
224232
command_args,
225233
disallow_missing,
234+
embed,
226235
interpreter_path,
227236
interpreter_args,
228237
injection_path,
@@ -441,8 +450,15 @@ async fn create_wrapper(options: &Options) -> tg::Result<()> {
441450
create_manifest(output_artifact_id, options, interpreter, library_paths).await?;
442451
tracing::trace!(?manifest);
443452

453+
// If requested, emebd the wrapper.
454+
let new_wrapper = if options.embed {
455+
manifest.embed(&tg, &output_file).await?
456+
} else {
457+
manifest.write(&tg).await?
458+
};
459+
444460
// Write the manifest to a wrapper.
445-
let new_wrapper = manifest.write(&tg).await?;
461+
446462
let new_wrapper_id = new_wrapper.id();
447463
tracing::trace!(?new_wrapper_id);
448464

0 commit comments

Comments
 (0)