Skip to content
Draft
143 changes: 102 additions & 41 deletions simplicity-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,106 @@ fn main() {
// rerun if changes to the C code
println!("cargo:rerun-if-changed=depend");
let simplicity_path = Path::new("depend/simplicity");
let jet_files: Vec<_> = vec![
"frame.c",
"jets.c",
"jets-secp256k1.c",
"rsort.c",
"sha256.c",
"elements/env.c",
"elements/ops.c",
"elements/elementsJets.c",
"elements/txEnv.c",
]
.into_iter()
.map(|x| simplicity_path.join(x))
.collect();

let mut files = vec![];

// 1. Base files.
files.extend(
[
"frame.c",
"jets.c",
"jets-secp256k1.c",
"rsort.c",
"sha256.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
// 2. Test files.
if cfg!(feature = "test-utils") {
files.extend(
[
"bitstream.c",
"dag.c",
"deserialize.c",
"eval.c",
"type.c",
"typeInference.c",
"ctx8Pruned.c",
"ctx8Unpruned.c",
"hashBlock.c",
"schnorr0.c",
"schnorr6.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
}

// Split into Bitcoin and Elements.
let mut elements_files = files.clone();
let mut bitcoin_files = files;

// 3B. Bitcoin base files.
bitcoin_files.extend(
[
"bitcoin/env.c",
"bitcoin/ops.c",
"bitcoin/bitcoinJets.c",
"bitcoin/txEnv.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
bitcoin_files.push("depend/bitcoin_env.c".into());

// 3E. Elements base files.
elements_files.extend(
[
"elements/env.c",
"elements/ops.c",
"elements/elementsJets.c",
"elements/txEnv.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
elements_files.push("depend/elements_env.c".into());

if cfg!(feature = "test-utils") {
// 4B. Bitcoin base files.
bitcoin_files.extend(
[
"bitcoin/exec.c",
"bitcoin/primitive.c",
// "bitcoin/checkSigHashAllTx1.c", // no sighashall test
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);

// 4E. Elements base files.
elements_files.extend(
[
"elements/exec.c",
"elements/primitive.c",
"elements/checkSigHashAllTx1.c",
]
.into_iter()
.map(|x| simplicity_path.join(x)),
);
}

// General build
let mut build = cc::Build::new();
build
.std("c11")
.flag_if_supported("-fno-inline-functions")
.opt_level(2)
.files(jet_files)
.file(Path::new("depend/wrapper.c"))
.file(Path::new("depend/env.c"))
.file(Path::new("depend/jets_wrapper.c"))
.include(simplicity_path.join("include"));

if cfg!(feature = "test-utils") {
let test_files: Vec<_> = vec![
"bitstream.c",
"dag.c",
"deserialize.c",
"eval.c",
"type.c",
"typeInference.c",
"elements/exec.c",
"elements/primitive.c",
"ctx8Pruned.c",
"ctx8Unpruned.c",
"hashBlock.c",
"schnorr0.c",
"schnorr6.c",
"elements/checkSigHashAllTx1.c",
]
.into_iter()
.map(|x| simplicity_path.join(x))
.collect();

build.files(test_files);
}

if cfg!(not(fuzzing)) {
build.define("PRODUCTION", None);
}
Expand All @@ -66,5 +116,16 @@ fn main() {
build.include("wasm-sysroot");
}

build.compile("ElementsSimplicity");
let mut bitcoin_build = build.clone();
let mut elements_build = build;

// Bitcoin build
bitcoin_build
.files(bitcoin_files)
.compile("BitcoinSimplicity");

// Elements build
elements_build
.files(elements_files)
.compile("ElementsSimplicity");
}
31 changes: 31 additions & 0 deletions simplicity-sys/depend/bitcoin_env.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdlib.h>
#include <stdalign.h>
#include "simplicity/bitcoin/env.h"
#include "simplicity/bitcoin/txEnv.h"
#include "simplicity/bitcoin/primitive.h"

typedef rawBitcoinBuffer rawBuffer;
typedef rawBitcoinBuffer rawBuffer;
typedef rawBitcoinOutput rawOutput;
typedef rawBitcoinInput rawInput;
typedef rawBitcoinTransaction rawTransaction;
typedef rawBitcoinTapEnv rawTapEnv;

const size_t rustsimplicity_0_6_c_sizeof_rawBitcoinBuffer = sizeof(rawBitcoinBuffer);
const size_t rustsimplicity_0_6_c_sizeof_rawBitcoinOutput = sizeof(rawBitcoinOutput);
const size_t rustsimplicity_0_6_c_sizeof_rawBitcoinInput = sizeof(rawBitcoinInput);
const size_t rustsimplicity_0_6_c_sizeof_rawBitcoinTransaction = sizeof(rawBitcoinTransaction);
const size_t rustsimplicity_0_6_c_sizeof_rawBitcoinTapEnv = sizeof(rawBitcoinTapEnv);
const size_t rustsimplicity_0_6_c_sizeof_bitcoinTxEnv = sizeof(txEnv);

const size_t rustsimplicity_0_6_c_alignof_rawBitcoinBuffer = alignof(rawBitcoinBuffer);
const size_t rustsimplicity_0_6_c_alignof_rawBitcoinOutput = alignof(rawBitcoinOutput);
const size_t rustsimplicity_0_6_c_alignof_rawBitcoinInput = alignof(rawBitcoinInput);
const size_t rustsimplicity_0_6_c_alignof_rawBitcoinTransaction = alignof(rawBitcoinTransaction);
const size_t rustsimplicity_0_6_c_alignof_rawBitcoinTapEnv = alignof(rawBitcoinTapEnv);
const size_t rustsimplicity_0_6_c_alignof_bitcoinTxEnv = alignof(txEnv);

void rustsimplicity_0_6_c_bitcoin_set_txEnv(txEnv *result, const bitcoinTransaction *tx, const bitcoinTapEnv *taproot, unsigned int ix)
{
*result = rustsimplicity_0_6_bitcoin_build_txEnv(tx, taproot, ix);
}
33 changes: 33 additions & 0 deletions simplicity-sys/depend/elements_env.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdlib.h>
#include <stdalign.h>
#include "simplicity/elements/env.h"
#include "simplicity/elements/txEnv.h"
#include "simplicity/elements/primitive.h"

typedef rawElementsBuffer rawBuffer;
typedef rawElementsBuffer rawBuffer;
typedef rawElementsOutput rawOutput;
typedef rawElementsInput rawInput;
typedef rawElementsTransaction rawTransaction;
typedef rawElementsTapEnv rawTapEnv;

const size_t rustsimplicity_0_6_c_sizeof_rawElementsBuffer = sizeof(rawElementsBuffer);
const size_t rustsimplicity_0_6_c_sizeof_rawElementsOutput = sizeof(rawElementsOutput);
const size_t rustsimplicity_0_6_c_sizeof_rawElementsInput = sizeof(rawElementsInput);
const size_t rustsimplicity_0_6_c_sizeof_rawElementsTransaction = sizeof(rawElementsTransaction);
const size_t rustsimplicity_0_6_c_sizeof_rawElementsTapEnv = sizeof(rawElementsTapEnv);
const size_t rustsimplicity_0_6_c_sizeof_elementsTxEnv = sizeof(txEnv);

const size_t rustsimplicity_0_6_c_alignof_rawElementsBuffer = alignof(rawElementsBuffer);
const size_t rustsimplicity_0_6_c_alignof_rawElementsOutput = alignof(rawElementsOutput);
const size_t rustsimplicity_0_6_c_alignof_rawElementsInput = alignof(rawElementsInput);
const size_t rustsimplicity_0_6_c_alignof_rawElementsTransaction = alignof(rawElementsTransaction);
const size_t rustsimplicity_0_6_c_alignof_rawElementsTapEnv = alignof(rawElementsTapEnv);
const size_t rustsimplicity_0_6_c_alignof_elementsTxEnv = alignof(txEnv);

void rustsimplicity_0_6_c_elements_set_txEnv(txEnv *result, const elementsTransaction *tx, const elementsTapEnv *taproot, const unsigned char *genesisHash, unsigned int ix)
{
sha256_midstate genesis;
sha256_toMidstate(genesis.s, genesisHash);
*result = rustsimplicity_0_6_elements_build_txEnv(tx, taproot, &genesis, ix);
}
Loading
Loading