Skip to content

Commit 486c431

Browse files
authored
Merge pull request #914 from adwinwhite/container-pool
2 parents 64e6953 + 8b8a3dd commit 486c431

File tree

26 files changed

+3626
-169
lines changed

26 files changed

+3626
-169
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ jobs:
185185
run: cargo fmt --manifest-path top-crates/Cargo.toml --check
186186
- name: Build backend
187187
run: |-
188-
mkdir -p ui/target; docker run --rm -v $PWD/ui:/ui -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry --workdir /ui rust:alpine sh -c '
188+
mkdir -p ui/target; docker run --rm -v $PWD/compiler/base/asm-cleanup:/compiler/base/asm-cleanup -v $PWD/compiler/base/orchestrator:/compiler/base/orchestrator -v $PWD/compiler/base/modify-cargo-toml:/compiler/base/modify-cargo-toml -v $PWD/ui:/ui -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry --workdir /ui rust:alpine sh -c '
189189
apk add musl-dev openssl-dev openssl-libs-static
190190
191191
# Adding -C relocation-model=static due to

ci/workflows.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ workflows:
288288
docker
289289
run
290290
--rm
291+
-v $PWD/compiler/base/asm-cleanup:/compiler/base/asm-cleanup
292+
-v $PWD/compiler/base/orchestrator:/compiler/base/orchestrator
293+
-v $PWD/compiler/base/modify-cargo-toml:/compiler/base/modify-cargo-toml
291294
-v $PWD/ui:/ui
292295
-v ~/.cargo/git:/root/.cargo/git
293296
-v ~/.cargo/registry:/root/.cargo/registry

compiler/base/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
asm-cleanup/target
12
modify-cargo-toml/target
3+
orchestrator/target

compiler/base/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,41 @@ FROM bare-sources as munge
6161
ADD --chown=playground modify-cargo-toml /playground/modify-cargo-toml
6262
RUN cargo build --release --manifest-path=/playground/modify-cargo-toml/Cargo.toml
6363

64+
# Set up cargo-chef for faster builds
65+
66+
FROM bare-sources as chef-available
67+
68+
RUN cargo install cargo-chef
69+
70+
WORKDIR /orchestrator
71+
72+
# Prepare the orchestrator's dependencies
73+
74+
FROM chef-available as prepare-orchestrator
75+
76+
COPY --chown=playground asm-cleanup /asm-cleanup
77+
COPY --chown=playground modify-cargo-toml /modify-cargo-toml
78+
COPY --chown=playground orchestrator /orchestrator
79+
RUN cargo chef prepare
80+
81+
# Build the orchestrator
82+
83+
FROM chef-available as build-orchestrator
84+
85+
COPY --chown=playground asm-cleanup /asm-cleanup
86+
COPY --chown=playground modify-cargo-toml /modify-cargo-toml
87+
COPY --chown=playground --from=prepare-orchestrator /orchestrator/recipe.json /orchestrator/recipe.json
88+
RUN cargo chef cook --release
89+
90+
COPY --chown=playground orchestrator /orchestrator
91+
RUN cargo install --path .
92+
6493
# Compiler and sources
6594

6695
FROM bare-sources as sources
6796

6897
COPY --from=munge /playground/modify-cargo-toml/target/release/modify-cargo-toml /playground/.cargo/bin
98+
COPY --from=build-orchestrator /playground/.cargo/bin/worker /playground/.cargo/bin/worker
6999

70100
# Compiler and pre-compiled crates
71101

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cargo.lock
2+
target/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "asm-cleanup"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[workspace]
7+
8+
[dependencies]
9+
lazy_static = "1.0.0"
10+
petgraph = "0.6.0"
11+
regex = "1.0.0"
12+
rustc-demangle = "0.1.5"
File renamed without changes.

compiler/base/cargo-wasm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ for wasm in $(find target/ -name '*wasm' -not -path '*/deps/*'); do
4141
# wasm2wat spits out an error that we don't care about, so hide it
4242
# https://github.com/WebAssembly/wabt/issues/842
4343
# https://stackoverflow.com/a/15936384/155423
44+
45+
# The streaming playground expects the file to be without the
46+
# extension while the original playground expects it to be with
47+
# the extension. Support both for now.
48+
cp "${output}.wat" "${output}"
4449
done

compiler/base/entrypoint.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
set -eu
44

5-
timeout=${PLAYGROUND_TIMEOUT:-10}
5+
if [[ -z "${PLAYGROUND_ORCHESTRATOR:-}" ]]; then
6+
timeout=${PLAYGROUND_TIMEOUT:-10}
67

7-
modify-cargo-toml
8+
modify-cargo-toml
89

9-
# Don't use `exec` here. The shell is what prints out the useful
10-
# "Killed" message
11-
timeout --signal=KILL ${timeout} "$@"
10+
# Don't use `exec` here. The shell is what prints out the useful
11+
# "Killed" message
12+
timeout --signal=KILL ${timeout} "$@"
13+
else
14+
exec "$@"
15+
fi
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
extern crate serde;
2+
#[macro_use]
3+
extern crate serde_derive;
4+
extern crate toml;
5+
6+
use std::collections::BTreeMap;
7+
use toml::Value;
8+
9+
type Other = BTreeMap<String, Value>;
10+
11+
fn modify<F, T>(cargo_toml: Value, f: F) -> Value
12+
where
13+
F: FnOnce(T) -> T,
14+
T: serde::Serialize + for<'de> serde::Deserialize<'de>,
15+
{
16+
let cargo_toml = cargo_toml.try_into().unwrap();
17+
18+
let cargo_toml = f(cargo_toml);
19+
20+
Value::try_from(cargo_toml).unwrap()
21+
}
22+
23+
fn ensure_string_in_vec(values: &mut Vec<String>, val: &str) {
24+
if !values.iter().any(|f| f == val) {
25+
values.push(val.into());
26+
}
27+
}
28+
29+
pub fn set_edition(cargo_toml: Value, edition: &str) -> Value {
30+
#[derive(Debug, Serialize, Deserialize)]
31+
#[serde(rename_all = "kebab-case")]
32+
struct CargoToml {
33+
package: Package,
34+
#[serde(flatten)]
35+
other: Other,
36+
}
37+
38+
#[derive(Debug, Serialize, Deserialize)]
39+
#[serde(rename_all = "kebab-case")]
40+
struct Package {
41+
#[serde(default)]
42+
edition: String,
43+
#[serde(flatten)]
44+
other: Other,
45+
}
46+
47+
modify(cargo_toml, |mut cargo_toml: CargoToml| {
48+
cargo_toml.package.edition = edition.into();
49+
cargo_toml
50+
})
51+
}
52+
53+
pub fn remove_dependencies(cargo_toml: Value) -> Value {
54+
#[derive(Debug, Serialize, Deserialize)]
55+
#[serde(rename_all = "kebab-case")]
56+
struct CargoToml {
57+
dependencies: BTreeMap<String, Value>,
58+
#[serde(flatten)]
59+
other: Other,
60+
}
61+
62+
modify(cargo_toml, |mut cargo_toml: CargoToml| {
63+
cargo_toml.dependencies.clear();
64+
cargo_toml
65+
})
66+
}
67+
68+
pub fn set_crate_type(cargo_toml: Value, crate_type: &str) -> Value {
69+
#[derive(Debug, Serialize, Deserialize)]
70+
#[serde(rename_all = "kebab-case")]
71+
struct CargoToml {
72+
#[serde(default)]
73+
lib: Lib,
74+
#[serde(flatten)]
75+
other: Other,
76+
}
77+
78+
#[derive(Debug, Default, Serialize, Deserialize)]
79+
#[serde(rename_all = "kebab-case")]
80+
struct Lib {
81+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
82+
crate_type: Vec<String>,
83+
#[serde(default)]
84+
proc_macro: bool,
85+
#[serde(flatten)]
86+
other: Other,
87+
}
88+
89+
modify(cargo_toml, |mut cargo_toml: CargoToml| {
90+
if crate_type == "proc-macro" {
91+
cargo_toml.lib.proc_macro = true;
92+
} else {
93+
ensure_string_in_vec(&mut cargo_toml.lib.crate_type, crate_type);
94+
}
95+
cargo_toml
96+
})
97+
}
98+
99+
pub fn set_release_lto(cargo_toml: Value, lto: bool) -> Value {
100+
#[derive(Debug, Serialize, Deserialize)]
101+
#[serde(rename_all = "kebab-case")]
102+
struct CargoToml {
103+
#[serde(default)]
104+
profile: Profiles,
105+
#[serde(flatten)]
106+
other: Other,
107+
}
108+
109+
#[derive(Debug, Default, Serialize, Deserialize)]
110+
#[serde(rename_all = "kebab-case")]
111+
struct Profiles {
112+
#[serde(default)]
113+
release: Profile,
114+
#[serde(flatten)]
115+
other: Other,
116+
}
117+
118+
#[derive(Debug, Default, Serialize, Deserialize)]
119+
#[serde(rename_all = "kebab-case")]
120+
struct Profile {
121+
#[serde(default)]
122+
lto: bool,
123+
#[serde(flatten)]
124+
other: Other,
125+
}
126+
127+
modify(cargo_toml, |mut cargo_toml: CargoToml| {
128+
cargo_toml.profile.release.lto = lto;
129+
cargo_toml
130+
})
131+
}

0 commit comments

Comments
 (0)