diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-03-28 08:22:39 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-03-28 08:42:05 +0000 |
| commit | 5d6bede7b4c44a80ec0a15aa49bbc85cbd1126d0 (patch) | |
| tree | 154b2d81826289fd468b787e5e86c9339658475c | |
| parent | 63b6d0d8db9f6621ceb20fd64475b54a0f66bc46 (diff) | |
Add skeleton of patio-to-cranelift
| -rw-r--r-- | makefile | 6 | ||||
| -rw-r--r-- | patio-to-cranelift/.gitignore | 2 | ||||
| -rw-r--r-- | patio-to-cranelift/Cargo.lock | 285 | ||||
| -rw-r--r-- | patio-to-cranelift/Cargo.toml | 14 | ||||
| -rw-r--r-- | patio-to-cranelift/src/main.rs | 44 |
5 files changed, 351 insertions, 0 deletions
@@ -40,3 +40,9 @@ protobuf: flatbuffers: python3 generate-flatbuffers.py + +.PHONY: patio-to-cranelift + +patio-to-cranelift: + flatc-25.12.19 -o patio-to-cranelift/src/gen --rust flatbuffers/* + cd patio-to-cranelift; cargo build diff --git a/patio-to-cranelift/.gitignore b/patio-to-cranelift/.gitignore new file mode 100644 index 00000000..a70986fd --- /dev/null +++ b/patio-to-cranelift/.gitignore @@ -0,0 +1,2 @@ +/src/gen +/target diff --git a/patio-to-cranelift/Cargo.lock b/patio-to-cranelift/Cargo.lock new file mode 100644 index 00000000..1c7f0645 --- /dev/null +++ b/patio-to-cranelift/Cargo.lock @@ -0,0 +1,285 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "cc" +version = "1.2.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "clap" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flatbuffers" +version = "25.12.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35f6839d7b3b98adde531effaf34f0c2badc6f4735d26fe74709d8e513a96ef3" +dependencies = [ + "bitflags", + "rustc_version", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "paste-complete" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a4cf96a295ab7f0ec2334fa557745c0e9526595f6ebabbb129563a98dfc1b2a" + +[[package]] +name = "patio-to-cranelift" +version = "0.1.0" +dependencies = [ + "clap", + "flatbuffers", + "protobuf-codegen", + "protobuf-well-known-types", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "protobuf" +version = "4.34.1-release" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5af3157e12bb2193b1ee85fd61fe9ebe737b63a22ab3774d7cbb7fb5f32b6425" +dependencies = [ + "cc", + "paste-complete", + "protobuf-macros", +] + +[[package]] +name = "protobuf-codegen" +version = "4.34.1-release" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eae99d63994a6a24b8903140dba6ee369c68933faaf09679655b4aaba4e798f" + +[[package]] +name = "protobuf-macros" +version = "4.34.1-release" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b19d8dd07383acc9acc88034d66dec66da7ef87f54df25c8c924e5245606409" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "protobuf-well-known-types" +version = "4.34.1-release" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94d5d9bc1d6651280e9e0dfa75eba54b26f40de6f0a7d08e57f69806ebb887d5" +dependencies = [ + "protobuf", + "protobuf-codegen", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] diff --git a/patio-to-cranelift/Cargo.toml b/patio-to-cranelift/Cargo.toml new file mode 100644 index 00000000..4520dae2 --- /dev/null +++ b/patio-to-cranelift/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "patio-to-cranelift" +version = "0.1.0" +edition = "2024" + +[dependencies] +clap = { version = "4.6.0", features = ["derive"] } +flatbuffers = "25.12.19" +protobuf-codegen = "4.34.1-release" +protobuf-well-known-types = "4.34.1-release" + +[build-dependencies] +protobuf-codegen = "4.34.1-release" +protobuf-well-known-types = "4.34.1-release" diff --git a/patio-to-cranelift/src/main.rs b/patio-to-cranelift/src/main.rs new file mode 100644 index 00000000..19c9c271 --- /dev/null +++ b/patio-to-cranelift/src/main.rs @@ -0,0 +1,44 @@ +use std::path::{Path, PathBuf}; + +use clap::Parser; + +#[allow(dead_code, unused_imports)] +#[path = "./gen/patio_generated.rs"] +mod patio_generated; + +#[allow(dead_code, unused_imports)] +#[path = "./gen/sources_generated.rs"] +mod sources_generated; + +/// Compile Patio compilation units into object files using Cranelift. +#[derive(clap::Parser, Debug)] +struct Args { + /// The Patio compilation unit to compile. + source_paths: Vec<PathBuf>, +} + +fn main() { + let args = Args::parse(); + + for source_path in args.source_paths { + compile(&source_path).unwrap(); + } +} + +fn compile(source_path: &Path) -> Result<(), CompileError> { + let source_bytes = std::fs::read(source_path).map_err(CompileError::ReadSourceBytes)?; + + let _compilation_unit = patio_generated::patio::root_as_patio_compilation_unit(&source_bytes) + .map_err(CompileError::InvalidFlatbuffer)?; + + Ok(()) +} + +#[derive(Debug)] +enum CompileError { + /// Reading the bytes of the patio source file failed. + ReadSourceBytes(#[allow(dead_code)] std::io::Error), + + /// The bytes of the patio source were an invalid flatbuffer. + InvalidFlatbuffer(#[allow(dead_code)] flatbuffers::InvalidFlatbuffer), +} |
