Skip to content

Commit

Permalink
Pre-build flatbuffer files
Browse files Browse the repository at this point in the history
We must add CI to make sure these are always in sync.
  • Loading branch information
emesare committed Oct 24, 2024
1 parent a2a5b2e commit dc51fd5
Show file tree
Hide file tree
Showing 56 changed files with 6,924 additions and 5 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Cargo.lock
# Best practice for something like this, the python scripts are not meant to be "deployed" from this repo state.
poetry.lock

gen_flatbuffers

# These are backup files generated by rustfmt
**/*.rs.bk

Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ bon = "2.3.0"
uuid = { version = "1.11.0", features = ["v5"]}
rand = "0.8.5"

[features]
default = []
gen_flatbuffers = ["dep:flatbuffers-build"]

[dev-dependencies]
criterion = "0.5.1"

[build-dependencies]
flatbuffers-build = { git = "https://github.com/emesare/flatbuffers-build", features = ["vendored"] }
flatbuffers-build = { git = "https://github.com/emesare/flatbuffers-build", features = ["vendored"], optional = true }

[profile.release]
panic = "abort"
Expand Down
8 changes: 6 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#[cfg(not(feature = "gen_flatbuffers"))]
pub fn main() {}

#[cfg(feature = "gen_flatbuffers")]
pub fn main() {
use flatbuffers_build::BuilderOptions;
use std::path::PathBuf;

// Remove leftover symlink dir.
let _ = std::fs::remove_dir_all("src/gen_flatbuffers");
let _ = std::fs::remove_dir_all("rust/gen_flatbuffers");
let workspace_dir: PathBuf = std::env::var("CARGO_MANIFEST_DIR").unwrap().into();
BuilderOptions::new_with_files([
workspace_dir.join("type.fbs"),
workspace_dir.join("symbol.fbs"),
workspace_dir.join("signature.fbs"),
])
.set_symlink_directory("rust/gen_flatbuffers")
.set_output_path("rust/gen_flatbuffers")
.compile()
.expect("flatbuffer compilation failed");
}
115 changes: 115 additions & 0 deletions rust/gen_flatbuffers/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Automatically generated by the Flatbuffers compiler. Do not modify.
// @generated
pub mod sig_bin {
use super::*;
mod basic_block_generated;
pub use self::basic_block_generated::*;
mod function_constraint_generated;
pub use self::function_constraint_generated::*;
mod function_constraints_generated;
pub use self::function_constraints_generated::*;
mod function_generated;
pub use self::function_generated::*;
mod data_generated;
pub use self::data_generated::*;
} // sig_bin
pub mod symbol_bin {
use super::*;
mod symbol_class_generated;
pub use self::symbol_class_generated::*;
mod symbol_modifiers_generated;
pub use self::symbol_modifiers_generated::*;
mod function_symbol_class_generated;
pub use self::function_symbol_class_generated::*;
mod data_symbol_class_generated;
pub use self::data_symbol_class_generated::*;
mod symbol_generated;
pub use self::symbol_generated::*;
} // symbol_bin
pub mod type_bin {
use super::*;
mod type_modifier_class_generated;
pub use self::type_modifier_class_generated::*;
mod type_alignment_generated;
pub use self::type_alignment_generated::*;
mod pointer_addressing_generated;
pub use self::pointer_addressing_generated::*;
mod array_modifiers_generated;
pub use self::array_modifiers_generated::*;
mod structure_member_modifiers_generated;
pub use self::structure_member_modifiers_generated::*;
mod location_class_generated;
pub use self::location_class_generated::*;
mod type_class_generated;
pub use self::type_class_generated::*;
mod unsigned_bit_offset_generated;
pub use self::unsigned_bit_offset_generated::*;
mod bit_offset_generated;
pub use self::bit_offset_generated::*;
mod bit_shift_generated;
pub use self::bit_shift_generated::*;
mod bit_size_generated;
pub use self::bit_size_generated::*;
mod bit_width_generated;
pub use self::bit_width_generated::*;
mod constant_modifier_class_generated;
pub use self::constant_modifier_class_generated::*;
mod volatile_modifier_class_generated;
pub use self::volatile_modifier_class_generated::*;
mod descriptor_modifier_class_generated;
pub use self::descriptor_modifier_class_generated::*;
mod metadata_modifier_class_generated;
pub use self::metadata_modifier_class_generated::*;
mod type_modifier_generated;
pub use self::type_modifier_generated::*;
mod access_alignment_generated;
pub use self::access_alignment_generated::*;
mod fixed_alignment_generated;
pub use self::fixed_alignment_generated::*;
mod void_generated;
pub use self::void_generated::*;
mod boolean_generated;
pub use self::boolean_generated::*;
mod float_generated;
pub use self::float_generated::*;
mod character_generated;
pub use self::character_generated::*;
mod integer_generated;
pub use self::integer_generated::*;
mod pointer_generated;
pub use self::pointer_generated::*;
mod array_generated;
pub use self::array_generated::*;
mod structure_member_generated;
pub use self::structure_member_generated::*;
mod structure_generated;
pub use self::structure_generated::*;
mod enumeration_member_generated;
pub use self::enumeration_member_generated::*;
mod enumeration_generated;
pub use self::enumeration_generated::*;
mod union_member_generated;
pub use self::union_member_generated::*;
mod union_generated;
pub use self::union_generated::*;
mod calling_convention_generated;
pub use self::calling_convention_generated::*;
mod register_location_generated;
pub use self::register_location_generated::*;
mod stack_location_generated;
pub use self::stack_location_generated::*;
mod function_member_location_generated;
pub use self::function_member_location_generated::*;
mod function_member_generated;
pub use self::function_member_generated::*;
mod function_generated;
pub use self::function_generated::*;
mod referrer_generated;
pub use self::referrer_generated::*;
mod type_generated;
pub use self::type_generated::*;
mod computed_type_generated;
pub use self::computed_type_generated::*;
mod data_generated;
pub use self::data_generated::*;
} // type_bin
109 changes: 109 additions & 0 deletions rust/gen_flatbuffers/sig_bin/basic_block_generated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
extern crate flatbuffers;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::mem;
use core::cmp::Ordering;
use self::flatbuffers::{EndianScalar, Follow};
use super::*;
pub enum BasicBlockOffset {}
#[derive(Copy, Clone, PartialEq)]

pub struct BasicBlock<'a> {
pub _tab: flatbuffers::Table<'a>,
}

impl<'a> flatbuffers::Follow<'a> for BasicBlock<'a> {
type Inner = BasicBlock<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}

impl<'a> BasicBlock<'a> {
pub const VT_GUID: flatbuffers::VOffsetT = 4;

#[inline]
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
BasicBlock { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
args: &'args BasicBlockArgs<'args>
) -> flatbuffers::WIPOffset<BasicBlock<'bldr>> {
let mut builder = BasicBlockBuilder::new(_fbb);
if let Some(x) = args.guid { builder.add_guid(x); }
builder.finish()
}


#[inline]
pub fn guid(&self) -> &'a str {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(BasicBlock::VT_GUID, None).unwrap()}
}
}

impl flatbuffers::Verifiable for BasicBlock<'_> {
#[inline]
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.visit_table(pos)?
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("guid", Self::VT_GUID, true)?
.finish();
Ok(())
}
}
pub struct BasicBlockArgs<'a> {
pub guid: Option<flatbuffers::WIPOffset<&'a str>>,
}
impl<'a> Default for BasicBlockArgs<'a> {
#[inline]
fn default() -> Self {
BasicBlockArgs {
guid: None, // required field
}
}
}

pub struct BasicBlockBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> BasicBlockBuilder<'a, 'b, A> {
#[inline]
pub fn add_guid(&mut self, guid: flatbuffers::WIPOffset<&'b str>) {
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(BasicBlock::VT_GUID, guid);
}
#[inline]
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> BasicBlockBuilder<'a, 'b, A> {
let start = _fbb.start_table();
BasicBlockBuilder {
fbb_: _fbb,
start_: start,
}
}
#[inline]
pub fn finish(self) -> flatbuffers::WIPOffset<BasicBlock<'a>> {
let o = self.fbb_.end_table(self.start_);
self.fbb_.required(o, BasicBlock::VT_GUID,"guid");
flatbuffers::WIPOffset::new(o.value())
}
}

impl core::fmt::Debug for BasicBlock<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut ds = f.debug_struct("BasicBlock");
ds.field("guid", &self.guid());
ds.finish()
}
}
Loading

0 comments on commit dc51fd5

Please sign in to comment.