Skip to content

Commit

Permalink
experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrichard committed Dec 4, 2023
1 parent a692bb3 commit 4b426ae
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ exclude = ["/depend/bitcoin/.github/**", "/depend/bitcoin/.tx/**", "/depend/bitc
build = "build.rs"
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["std"]
std = []
Expand All @@ -21,7 +24,7 @@ external-secp = []
[dependencies]

[build-dependencies]
cc = "1.0.28"
cc = "1.0.83"

[dev-dependencies]
rustc-serialize = "0.3"
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM rust:1.70-bookworm as builder

RUN apt-get update \
&& apt-get -y dist-upgrade \
&& apt-get install --no-install-recommends -y \
build-essential \
ca-certificates \
clang \
emscripten \
libc6-dev-i386 \
libstdc++-11-dev \
pkg-config \
sudo \
wasi-libc \
&& apt -y autoremove \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*

ARG UID
RUN useradd -m -u $UID satoshi
USER satoshi
WORKDIR /bitcoinconsensus

RUN cargo install wasm-pack
RUN rustup target add wasm32-unknown-emscripten \
&& rustup target add wasm32-unknown-unknown \
&& rustup target add wasm32-wasi
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
TAG := bitcoinconsensus

DOCKER_RUN := docker run --interactive --rm \
-v ${PWD}:/bitcoinconsensus \

build-emscripten: builder
$(DOCKER_RUN) --tty ${TAG} cargo build --target wasm32-unknown-emscripten

build-unknown: builder
$(DOCKER_RUN) --tty ${TAG} cargo build --target wasm32-unknown-unknown

build-wasi: builder
$(DOCKER_RUN) --tty ${TAG} cargo build --target wasm32-wasi

wasm-pack: builder
$(DOCKER_RUN) --tty ${TAG} wasm-pack build --target web

builder:
docker build --tag ${TAG} \
--build-arg UID="$(shell id -u)" \
.

28 changes: 24 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn main() {
.include("depend/bitcoin/src/secp256k1/include")
.define("__STDC_FORMAT_MACROS", None);

/*
// **Secp256k1**
if !cfg!(feature = "external-secp") {
base_config
Expand Down Expand Up @@ -54,17 +55,36 @@ fn main() {
base_config.define("USE_FIELD_10X26", "1").define("USE_SCALAR_8X32", "1");
}
}

*/
let tool = base_config.get_compiler();
if tool.is_like_msvc() {
base_config.flag("/std:c++14").flag("/wd4100");
base_config.std("c++14").flag("/wd4100");
} else if tool.is_like_clang() || tool.is_like_gnu() {
base_config.flag("-std=c++11").flag("-Wno-unused-parameter");
base_config.std("c++11").flag("-Wno-unused-parameter");
}

if target.contains("windows") {
base_config.define("WIN32", "1");
}

if target.contains("emscripten") {
base_config
.compiler("emcc")
.flag("--no-entry")
.define("ERROR_ON_UNDEFINED_SYMBOLS", "0");
} else if target.contains("wasm") {
if target.contains("wasi") {
base_config
.include("/usr/include/wasm32-wasi");
}

base_config
.include("/usr/include")
.include("/usr/include/c++/11")
.include("/usr/include/x86_64-linux-gnu")
.include("/usr/include/x86_64-linux-gnu/c++/11");
}

base_config
.file("depend/bitcoin/src/util/strencodings.cpp")
.file("depend/bitcoin/src/uint256.cpp")
Expand All @@ -80,5 +100,5 @@ fn main() {
.file("depend/bitcoin/src/script/interpreter.cpp")
.file("depend/bitcoin/src/script/script.cpp")
.file("depend/bitcoin/src/script/script_error.cpp")
.compile("libbitcoinconsensus.a");
.compile("bitcoinconsensus");
}

0 comments on commit 4b426ae

Please sign in to comment.