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

compiler/base/asm-cleanup/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cargo.lock
2+
target/

compiler/base/asm-cleanup/Cargo.toml

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+
}
Lines changed: 3 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
extern crate serde;
2-
#[macro_use]
3-
extern crate serde_derive;
1+
extern crate modify_cargo_toml;
42
extern crate toml;
53

6-
use std::{collections::BTreeMap, env, ffi::OsString, fs, path::PathBuf};
4+
use modify_cargo_toml::*;
5+
use std::{env, ffi::OsString, fs, path::PathBuf};
76
use toml::Value;
87

98
fn main() {
@@ -41,127 +40,3 @@ fn main() {
4140
fs::write(&output_filename, output)
4241
.unwrap_or_else(|e| panic!("Cannot write to {}: {}", output_filename.display(), e));
4342
}
44-
45-
type Other = BTreeMap<String, Value>;
46-
47-
fn modify<F, T>(cargo_toml: Value, f: F) -> Value
48-
where
49-
F: FnOnce(T) -> T,
50-
T: serde::Serialize + for<'de> serde::Deserialize<'de>,
51-
{
52-
let cargo_toml = cargo_toml.try_into().unwrap();
53-
54-
let cargo_toml = f(cargo_toml);
55-
56-
Value::try_from(cargo_toml).unwrap()
57-
}
58-
59-
fn ensure_string_in_vec(values: &mut Vec<String>, val: &str) {
60-
if !values.iter().any(|f| f == val) {
61-
values.push(val.into());
62-
}
63-
}
64-
65-
fn set_edition(cargo_toml: Value, edition: &str) -> Value {
66-
#[derive(Debug, Serialize, Deserialize)]
67-
#[serde(rename_all = "kebab-case")]
68-
struct CargoToml {
69-
package: Package,
70-
#[serde(flatten)]
71-
other: Other,
72-
}
73-
74-
#[derive(Debug, Serialize, Deserialize)]
75-
#[serde(rename_all = "kebab-case")]
76-
struct Package {
77-
#[serde(default)]
78-
edition: String,
79-
#[serde(flatten)]
80-
other: Other,
81-
}
82-
83-
modify(cargo_toml, |mut cargo_toml: CargoToml| {
84-
cargo_toml.package.edition = edition.into();
85-
cargo_toml
86-
})
87-
}
88-
89-
fn remove_dependencies(cargo_toml: Value) -> Value {
90-
#[derive(Debug, Serialize, Deserialize)]
91-
#[serde(rename_all = "kebab-case")]
92-
struct CargoToml {
93-
dependencies: BTreeMap<String, Value>,
94-
#[serde(flatten)]
95-
other: Other,
96-
}
97-
98-
modify(cargo_toml, |mut cargo_toml: CargoToml| {
99-
cargo_toml.dependencies.clear();
100-
cargo_toml
101-
})
102-
}
103-
104-
fn set_crate_type(cargo_toml: Value, crate_type: &str) -> Value {
105-
#[derive(Debug, Serialize, Deserialize)]
106-
#[serde(rename_all = "kebab-case")]
107-
struct CargoToml {
108-
#[serde(default)]
109-
lib: Lib,
110-
#[serde(flatten)]
111-
other: Other,
112-
}
113-
114-
#[derive(Debug, Default, Serialize, Deserialize)]
115-
#[serde(rename_all = "kebab-case")]
116-
struct Lib {
117-
#[serde(default, skip_serializing_if = "Vec::is_empty")]
118-
crate_type: Vec<String>,
119-
#[serde(default)]
120-
proc_macro: bool,
121-
#[serde(flatten)]
122-
other: Other,
123-
}
124-
125-
modify(cargo_toml, |mut cargo_toml: CargoToml| {
126-
if crate_type == "proc-macro" {
127-
cargo_toml.lib.proc_macro = true;
128-
} else {
129-
ensure_string_in_vec(&mut cargo_toml.lib.crate_type, crate_type);
130-
}
131-
cargo_toml
132-
})
133-
}
134-
135-
fn set_release_lto(cargo_toml: Value, lto: bool) -> Value {
136-
#[derive(Debug, Serialize, Deserialize)]
137-
#[serde(rename_all = "kebab-case")]
138-
struct CargoToml {
139-
#[serde(default)]
140-
profile: Profiles,
141-
#[serde(flatten)]
142-
other: Other,
143-
}
144-
145-
#[derive(Debug, Default, Serialize, Deserialize)]
146-
#[serde(rename_all = "kebab-case")]
147-
struct Profiles {
148-
#[serde(default)]
149-
release: Profile,
150-
#[serde(flatten)]
151-
other: Other,
152-
}
153-
154-
#[derive(Debug, Default, Serialize, Deserialize)]
155-
#[serde(rename_all = "kebab-case")]
156-
struct Profile {
157-
#[serde(default)]
158-
lto: bool,
159-
#[serde(flatten)]
160-
other: Other,
161-
}
162-
163-
modify(cargo_toml, |mut cargo_toml: CargoToml| {
164-
cargo_toml.profile.release.lto = lto;
165-
cargo_toml
166-
})
167-
}

compiler/base/orchestrator/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

0 commit comments

Comments
 (0)