Skip to content

Commit

Permalink
Running ldw process-model in the solidity build script.
Browse files Browse the repository at this point in the history
Processing the model is currently broken because of some unimplemented features in ldw.
  • Loading branch information
mjoerussell committed Jan 27, 2025
1 parent dbacc7b commit f63609a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
27 changes: 0 additions & 27 deletions crates/infra/cli/src/commands/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ use anyhow::Result;
use clap::{Parser, ValueEnum};
use infra_utils::cargo::CargoWorkspaceCommands;
use infra_utils::commands::Command;
use infra_utils::paths::PathExtensions;
use infra_utils::terminal::Terminal;
use rayon::iter::{ParallelBridge, ParallelIterator};
use strum::IntoEnumIterator;

use crate::toolchains::wasm::WasmPackage;
use crate::utils::{ClapExtensions, OrderedCommand};

use std::path::Path;

#[derive(Clone, Debug, Default, Parser)]
pub struct CheckController {
#[clap(trailing_var_arg = true)]
Expand All @@ -30,7 +27,6 @@ enum CheckCommand {
Cargo,
/// Check NPM packages for any outdated codegen steps.
Npm,
Ldw,
}

impl OrderedCommand for CheckCommand {
Expand All @@ -40,7 +36,6 @@ impl OrderedCommand for CheckCommand {
match self {
CheckCommand::Cargo => check_cargo(),
CheckCommand::Npm => check_npm(),
CheckCommand::Ldw => check_ldw(),
};

Ok(())
Expand All @@ -62,25 +57,3 @@ fn check_npm() {
.par_bridge()
.for_each(|package| package.build().unwrap());
}

/// Process ldw models
fn check_ldw() {
// TODO:
// 1. Iterate over all languages
// 2. We need a way to provide the fully qualified names (FQNs) that each grammar exposes
// - We could probably compute these from the paths themselves, since that's all the FQNs represent. However, finding the
// correct files to look at is probably the exact problem that the FQN is trying to solve, so that might not be so easy.
// 3. Questions about input file structure: Right now we already have crates/<lang>/outputs, and since
// the models are going to be generated it probably makes sense to put them there, even though for this use-case they're
// technically inputs. `outputs/ldw/inputs`?
// 4. Questions about output file structure: We'll need to make sure that the generated passes are put somewhere where they
// can be used by the next stage in the build pipeline, but for now we'll just dump them somewhere convenient.
Command::new("ts-node")
.current_dir(Path::repo_path("crates/codegen/ldw"))
.args(["-P", "./tsconfig.json"])
.arg("src-ts/cli/ldw.ts")
// .args(["--in-dir", "../../crates/testlang/outputs/ldw/"])
// .args(["--out-dir", "../../crates/testlang/outputs/ldw/generated"])
.flag("--help")
.run();
}
31 changes: 28 additions & 3 deletions crates/solidity/outputs/cargo/crate/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! This build script is only used for local development.
//! It is removed when publishing to crates.io.
use std::path::Path;

use anyhow::Result;
use codegen_runtime_generator::RuntimeGenerator;
use infra_utils::cargo::CargoWorkspace;
use infra_utils::{cargo::CargoWorkspace, commands::Command, paths::PathExtensions};
use solidity_language::{render_built_ins, SolidityDefinition};

fn main() -> Result<()> {
Expand All @@ -12,7 +14,8 @@ fn main() -> Result<()> {
let input_dir =
CargoWorkspace::locate_source_crate("codegen_runtime_cargo_crate")?.join("src/runtime");

let output_dir = CargoWorkspace::locate_source_crate("slang_solidity")?.join("src/generated");
let crate_path = CargoWorkspace::locate_source_crate("slang_solidity")?;
let output_dir = crate_path.join("src/generated");

let mut fs = RuntimeGenerator::generate_product(&language, &input_dir, &output_dir)?;
let built_ins_output_dir = output_dir.join("bindings/generated/built_ins");
Expand All @@ -21,5 +24,27 @@ fn main() -> Result<()> {
&language,
&built_ins_output_dir,
render_built_ins,
)
)?;

Command::new("ts-node")
.current_dir(Path::repo_path("crates/codegen/ldw"))
.args(["-P", "./tsconfig.json"])
.arg("src-ts/cli/ldw.ts")
.arg("process-model")
.args([
"--in-dir",
crate_path
.join("src/generated/ldw-models/")
.to_str()
.unwrap(),
])
.args([
"--out-dir",
crate_path.join("src/generated/ldw/").to_str().unwrap(),
])
.args(["--language", "rust"])
.args(["--name", "l0::generated"])
.run();

Ok(())
}

0 comments on commit f63609a

Please sign in to comment.