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
116 changes: 112 additions & 4 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [".", "bench"]
members = [".", "coolc-bin", "runtime", "bench"]
default-members = [".", "coolc-bin"]
resolver = "3"

[workspace.package]
Expand All @@ -8,6 +9,8 @@ version = "0.0.1"

[workspace.dependencies]
cool.path = "."
cfg-if = "1.0.0"
clap = { version = "4.5.39", features = ["derive"] }
criterion = "0.5.1"
indoc = "2.0.6"
phf = { version = "0.11.3", features = ["macros"] }
Expand Down
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Forbid (new T) where T is primitive
15 changes: 15 additions & 0 deletions coolc-bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "coolc-bin"
edition.workspace = true
version.workspace = true

[dependencies]
cool.workspace = true
cfg-if.workspace = true
clap.workspace = true

[build-dependencies]
cool.workspace = true

[lints]
workspace = true
46 changes: 46 additions & 0 deletions coolc-bin/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::{path::Path, process::Command};

use cool::codegen::Target;

fn compile_target(target: Target) {
let cargo = env!("CARGO");

let manifest = Path::new(env!("CARGO_MANIFEST_PATH"));
let root = manifest
.parent()
.and_then(|p| p.parent())
.unwrap()
.to_str()
.unwrap();

let target_dir = format!("{root}/target/_coolc/runtime/rt-{target}");

let out = Command::new(cargo)
.arg("build")
.arg("--release")
.arg("--package")
.arg("runtime")
.arg("--target-dir")
.arg(&target_dir)
.arg("--target")
.arg(target.triple())
.output()
.expect("failed to run cargo");
if !out.status.success() {
let error = String::from_utf8_lossy(&out.stderr);
panic!("failed to build {target}:\n{error}");
}

// Cargo creates a folder with the target inside the path specified in
// `--target-dir`. Hence `{target}` appears two times in the path.
let cargo_triple = target.triple();
let runtime_archive_path = format!("{target_dir}/{cargo_triple}/release/libruntime.a");
println!("cargo::rustc-env=COOL_RT_{target}={runtime_archive_path}");
}

fn main() {
println!("cargo::rerun-if-changed=../runtime");
for target in Target::ALL {
compile_target(*target);
}
}
Loading