Skip to content

Commit d924baf

Browse files
committed
feat: Add an option to the build server to invoke the component's RUN export in a sandbox and return the resulting object.
* Adds an axum/HTTP server alongside the GRPC interface for faster integration with client. * Updates ct-runtime instance interface to optionally provide stringifiable input/output. * Adds an import map configuration for the bundler.
1 parent f00d64c commit d924baf

File tree

30 files changed

+487
-94
lines changed

30 files changed

+487
-94
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ rand = { version = "0.8" }
5959
redb = { version = "2" }
6060
reqwest = { version = "0.12", default-features = false }
6161
#rust-embed = { version = "8.4" }
62-
#serde = { version = "1", features = ["derive"] }
63-
#serde_json = { version = "1" }
62+
serde = { version = "1", features = ["derive"] }
63+
serde_json = { version = "1" }
6464
#sieve-cache = { version = "0.2" }
6565
#strum = { version = "0.26" }
6666
syn = { version = "2" }

rust/ct-builder/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ publish = false
99
anyhow = { workspace = true }
1010
async-stream = { workspace = true }
1111
async-trait = { workspace = true }
12+
axum = { workspace = true }
1213
blake3 = { workspace = true }
1314
clap = { workspace = true, features = ["derive"] }
1415
ct-common = { workspace = true }
1516
ct-protos = { workspace = true, features = ["builder"] }
17+
ct-runtime = { workspace = true }
1618
deno_emit = { workspace = true }
1719
deno_graph = { workspace = true }
1820
redb = { workspace = true }
1921
reqwest = { workspace = true, default-features = false, features = ["rustls-tls", "charset", "http2", "macos-system-configuration"] }
22+
serde = { workspace = true }
23+
serde_json = { workspace = true }
2024
tempfile = { workspace = true }
2125
thiserror = { workspace = true }
2226
tokio = { workspace = true, features = ["rt-multi-thread", "io-util", "process", "fs"] }

rust/ct-builder/src/bin/builder.rs

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@ pub fn main() {
77
unimplemented!("Binary not supported for wasm32")
88
}
99

10+
#[cfg(not(target_arch = "wasm32"))]
11+
#[derive(clap::Parser)]
12+
#[command(version, about, long_about = None)]
13+
struct Cli {
14+
/// GRPC server port.
15+
#[arg(short = 'g', long, default_value_t = 8082)]
16+
pub grpc_port: u16,
17+
/// HTTP server port.
18+
#[arg(short = 'p', long, default_value_t = 8081)]
19+
pub http_port: u16,
20+
/// HTTP server port.
21+
#[arg(short = 'i', long)]
22+
pub import_map: Option<std::path::PathBuf>,
23+
}
24+
1025
#[cfg(not(target_arch = "wasm32"))]
1126
#[tokio::main]
1227
pub async fn main() -> Result<(), ct_builder::Error> {
1328
use clap::Parser;
14-
use ct_builder::serve;
29+
use ct_builder::{serve, BuildServerConfig, ImportMap};
1530
use std::net::SocketAddr;
1631
use tracing_subscriber::{EnvFilter, FmtSubscriber};
1732

@@ -20,22 +35,33 @@ pub async fn main() -> Result<(), ct_builder::Error> {
2035
.finish();
2136
tracing::subscriber::set_global_default(subscriber)?;
2237

23-
#[derive(clap::Parser)]
24-
#[command(version, about, long_about = None)]
25-
struct Cli {
26-
/// Set build server to listen on provided port.
27-
#[arg(short, long, default_value_t = 8082)]
28-
port: u16,
29-
}
30-
3138
let cli = Cli::parse();
32-
let port = cli.port;
33-
let socket_address: SocketAddr = format!("0.0.0.0:{port}").parse()?;
34-
let listener = tokio::net::TcpListener::bind(socket_address).await?;
35-
36-
info!("Server listening on {}", socket_address);
3739

38-
serve(listener).await?;
40+
let grpc_listener = {
41+
let socket_address: SocketAddr = format!("0.0.0.0:{}", cli.grpc_port).parse()?;
42+
info!("GRPC listening on {}", socket_address);
43+
tokio::net::TcpListener::bind(socket_address).await?
44+
};
45+
let http_listener = {
46+
let socket_address: SocketAddr = format!("0.0.0.0:{}", cli.http_port).parse()?;
47+
info!("HTTP listening on {}", socket_address);
48+
tokio::net::TcpListener::bind(socket_address).await?
49+
};
50+
let mut config = BuildServerConfig::default()
51+
.with_grpc(grpc_listener)
52+
.with_http(http_listener);
53+
if let Some(import_map_path) = cli.import_map {
54+
let import_map_path = if import_map_path.is_relative() {
55+
std::env::current_dir()?
56+
.join(import_map_path)
57+
.canonicalize()?
58+
} else {
59+
import_map_path
60+
};
61+
let import_map = ImportMap::from_path(import_map_path).await?;
62+
config = config.with_import_map(import_map);
63+
}
64+
serve(config).await?;
3965

4066
Ok(())
4167
}

rust/ct-builder/src/builder.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
artifact::Artifact,
33
error::Error,
44
storage::{JsComponentStorage, PersistedHashStorage},
5-
JavaScriptBundler,
5+
ImportMap, JavaScriptBundler,
66
};
77
use async_trait::async_trait;
88
use blake3::Hash;
@@ -15,8 +15,9 @@ use std::str::FromStr;
1515
use tonic::{Request, Response, Status};
1616

1717
pub struct BuildComponentConfig {
18-
definition: ModuleDefinition,
19-
bundle_common_imports: bool,
18+
pub definition: ModuleDefinition,
19+
pub bundle_common_imports: bool,
20+
pub import_map: Option<ImportMap>,
2021
}
2122

2223
#[derive(Clone)]
@@ -33,7 +34,11 @@ impl Builder {
3334
info!("Building source: {:#?}", config.definition.source);
3435
let artifact = match config.definition.content_type {
3536
ContentType::JavaScript => {
36-
JavaScriptBundler::bundle_from_bytes_sync(config.definition.source.into()).await?
37+
JavaScriptBundler::bundle_from_bytes_sync(
38+
config.definition.source.into(),
39+
config.import_map,
40+
)
41+
.await?
3742
}
3843
};
3944
self.storage.write(artifact).await
@@ -61,6 +66,7 @@ impl BuilderProto for Builder {
6166
.build(BuildComponentConfig {
6267
definition,
6368
bundle_common_imports: false,
69+
import_map: None,
6470
})
6571
.await?;
6672

0 commit comments

Comments
 (0)