Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ rand = { version = "0.8" }
redb = { version = "2" }
reqwest = { version = "0.12", default-features = false }
#rust-embed = { version = "8.4" }
#serde = { version = "1", features = ["derive"] }
#serde_json = { version = "1" }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
#sieve-cache = { version = "0.2" }
#strum = { version = "0.26" }
syn = { version = "2" }
Expand Down
4 changes: 4 additions & 0 deletions rust/ct-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ publish = false
anyhow = { workspace = true }
async-stream = { workspace = true }
async-trait = { workspace = true }
axum = { workspace = true }
blake3 = { workspace = true }
clap = { workspace = true, features = ["derive"] }
ct-common = { workspace = true }
ct-protos = { workspace = true, features = ["builder"] }
ct-runtime = { workspace = true }
deno_emit = { workspace = true }
deno_graph = { workspace = true }
redb = { workspace = true }
reqwest = { workspace = true, default-features = false, features = ["rustls-tls", "charset", "http2", "macos-system-configuration"] }
serde = { workspace = true }
serde_json = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "io-util", "process", "fs"] }
Expand Down
56 changes: 41 additions & 15 deletions rust/ct-builder/src/bin/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@ pub fn main() {
unimplemented!("Binary not supported for wasm32")
}

#[cfg(not(target_arch = "wasm32"))]
#[derive(clap::Parser)]
#[command(version, about, long_about = None)]
struct Cli {
/// GRPC server port.
#[arg(short = 'g', long, default_value_t = 8082)]
pub grpc_port: u16,
/// HTTP server port.
#[arg(short = 'p', long, default_value_t = 8081)]
pub http_port: u16,
/// HTTP server port.
#[arg(short = 'i', long)]
pub import_map: Option<std::path::PathBuf>,
}

#[cfg(not(target_arch = "wasm32"))]
#[tokio::main]
pub async fn main() -> Result<(), ct_builder::Error> {
use clap::Parser;
use ct_builder::serve;
use ct_builder::{serve, BuildServerConfig, ImportMap};
use std::net::SocketAddr;
use tracing_subscriber::{EnvFilter, FmtSubscriber};

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

#[derive(clap::Parser)]
#[command(version, about, long_about = None)]
struct Cli {
/// Set build server to listen on provided port.
#[arg(short, long, default_value_t = 8082)]
port: u16,
}

let cli = Cli::parse();
let port = cli.port;
let socket_address: SocketAddr = format!("0.0.0.0:{port}").parse()?;
let listener = tokio::net::TcpListener::bind(socket_address).await?;

info!("Server listening on {}", socket_address);

serve(listener).await?;
let grpc_listener = {
let socket_address: SocketAddr = format!("0.0.0.0:{}", cli.grpc_port).parse()?;
info!("GRPC listening on {}", socket_address);
tokio::net::TcpListener::bind(socket_address).await?
};
let http_listener = {
let socket_address: SocketAddr = format!("0.0.0.0:{}", cli.http_port).parse()?;
info!("HTTP listening on {}", socket_address);
tokio::net::TcpListener::bind(socket_address).await?
};
let mut config = BuildServerConfig::default()
.with_grpc(grpc_listener)
.with_http(http_listener);
if let Some(import_map_path) = cli.import_map {
let import_map_path = if import_map_path.is_relative() {
std::env::current_dir()?
.join(import_map_path)
.canonicalize()?
} else {
import_map_path
};
let import_map = ImportMap::from_path(import_map_path).await?;
config = config.with_import_map(import_map);
}
serve(config).await?;

Ok(())
}
14 changes: 10 additions & 4 deletions rust/ct-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
artifact::Artifact,
error::Error,
storage::{JsComponentStorage, PersistedHashStorage},
JavaScriptBundler,
ImportMap, JavaScriptBundler,
};
use async_trait::async_trait;
use blake3::Hash;
Expand All @@ -15,8 +15,9 @@ use std::str::FromStr;
use tonic::{Request, Response, Status};

pub struct BuildComponentConfig {
definition: ModuleDefinition,
bundle_common_imports: bool,
pub definition: ModuleDefinition,
pub bundle_common_imports: bool,
pub import_map: Option<ImportMap>,
}

#[derive(Clone)]
Expand All @@ -33,7 +34,11 @@ impl Builder {
info!("Building source: {:#?}", config.definition.source);
let artifact = match config.definition.content_type {
ContentType::JavaScript => {
JavaScriptBundler::bundle_from_bytes_sync(config.definition.source.into()).await?
JavaScriptBundler::bundle_from_bytes_sync(
config.definition.source.into(),
config.import_map,
)
.await?
}
};
self.storage.write(artifact).await
Expand Down Expand Up @@ -61,6 +66,7 @@ impl BuilderProto for Builder {
.build(BuildComponentConfig {
definition,
bundle_common_imports: false,
import_map: None,
})
.await?;

Expand Down
Loading