-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve DX around statically linked bytecodes, add example (#37)
* feat: improve DX around statically linked bytecodes, add example * chore: clippy
- Loading branch information
Showing
8 changed files
with
135 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
fn main() { | ||
// Emit the configuration to run compiled bytecodes. | ||
revmc_build::emit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
fn main() { | ||
use revmc::{new_llvm_backend, primitives::SpecId, EvmCompiler, OptimizationLevel, Result}; | ||
use std::path::PathBuf; | ||
|
||
fn main() -> Result<()> { | ||
// Emit the configuration to run compiled bytecodes. | ||
// This not used if we are only using statically linked bytecodes. | ||
revmc_build::emit(); | ||
|
||
// Compile and statically link a bytecode. | ||
let name = "fibonacci"; | ||
let bytecode = revmc::primitives::hex!( | ||
"5f355f60015b8215601a578181019150909160019003916005565b9150505f5260205ff3" | ||
); | ||
println!("cargo:rustc-env=FIB_HASH={}", revmc::primitives::keccak256(bytecode)); | ||
|
||
let out_dir = PathBuf::from(std::env::var("OUT_DIR")?); | ||
let context = revmc::llvm::inkwell::context::Context::create(); | ||
let backend = new_llvm_backend(&context, true, OptimizationLevel::Aggressive)?; | ||
let mut compiler = EvmCompiler::new(backend); | ||
compiler.translate(Some(name), &bytecode, SpecId::CANCUN)?; | ||
let object = out_dir.join(name).with_extension("o"); | ||
compiler.write_object_to_file(&object)?; | ||
|
||
cc::Build::new().object(&object).static_flag(true).compile(name); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters