Skip to content

Commit

Permalink
Merge #99: Fix WASM
Browse files Browse the repository at this point in the history
7c91cab fix: Debug symbols override each other (Christian Lewe)
439a133 fix: Debug symbol CMRs differ by architecture (Christian Lewe)
81803d4 test: Check that WASM builds in CI (Christian Lewe)
1114654 fix: WASM doesn't build (Christian Lewe)

Pull request description:

  This crate was broken on WASM; make it compile again. Check WASM compilation in CI. Fix broken debug symbols on WASM.

ACKs for top commit:
  apoelstra:
    ACK 7c91cab; successfully ran local tests

Tree-SHA512: d8efa3c62b289db23e17f638218ed7c45e45944971a139eb20b64b3737feeed5f052df0718ed72bd4f22deea93943d50fba00e0324733cb92548761090c83814
  • Loading branch information
apoelstra committed Oct 25, 2024
2 parents 2d5e1b1 + 7c91cab commit 21ce1a5
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 75 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,24 @@ jobs:
- name: Build each integration test
run: |
nix develop .#ci --command bash -c "just build_integration"
build-wasm:
name: Build - WASM
runs-on: ubuntu-latest
needs: test-stable

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install nix
uses: cachix/install-nix-action@v24
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Enable Rust cache
uses: Swatinem/rust-cache@v2

- name: Build WASM library
run: |
nix develop .#wasm --command bash -c "just build_wasm"
36 changes: 10 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
pkgs = import nixpkgs {
inherit system overlays;
};
mkRust = stable: version: profile: extensions: pkgs.rust-bin.${stable}.${version}.${profile}.override {
mkRust = stable: version: profile: targets: extensions: pkgs.rust-bin.${stable}.${version}.${profile}.override {
inherit targets;
inherit extensions;
};
defaultRust = mkRust "stable" "latest" "default" ["rust-src"];
defaultRust = mkRust "stable" "latest" "default" ["wasm32-unknown-unknown"] ["rust-src"];
elementsd-simplicity = pkgs.callPackage ./bitcoind-tests/elementsd-simplicity.nix {};
CC_wasm32_unknown_unknown = "${pkgs.llvmPackages_16.clang-unwrapped}/bin/clang-16";
AR_wasm32_unknown_unknown = "${pkgs.llvmPackages_16.libllvm}/bin/llvm-ar";
Expand All @@ -43,6 +44,9 @@
] ++ (
if with_elements then [ elementsd-simplicity ] else []
);
inherit CC_wasm32_unknown_unknown;
inherit AR_wasm32_unknown_unknown;
inherit CFLAGS_wasm32_unknown_unknown;
# Constants for IDE
RUST_TOOLCHAIN = "${defaultRust}/bin";
RUST_STDLIB = "${defaultRust}/lib/rustlib/src/rust";
Expand All @@ -56,28 +60,33 @@
# Temporary shells until CI has its nix derivations
ci = pkgs.mkShell {
buildInputs = [
(mkRust "stable" "latest" "default" [])
(mkRust "stable" "latest" "default" [] [])
pkgs.just
pkgs.cargo-hack
];
};
msrv = pkgs.mkShell {
buildInputs = [
(mkRust "stable" "1.63.0" "minimal" [])
(mkRust "stable" "1.63.0" "minimal" [] [])
pkgs.just
];
};
fuzz = pkgs.mkShell.override {
stdenv = pkgs.clang16Stdenv;
} {
buildInputs = [
(mkRust "nightly" "2024-07-01" "minimal" ["llvm-tools-preview"])
(mkRust "nightly" "2024-07-01" "minimal" [] ["llvm-tools-preview"])
pkgs.just
pkgs.cargo-fuzz
pkgs.cargo-binutils
pkgs.rustfilt
];
# Constants for compiler
};
wasm = pkgs.mkShell {
buildInputs = [
(mkRust "stable" "latest" "default" ["wasm32-unknown-unknown"] [])
pkgs.just
];
inherit CC_wasm32_unknown_unknown;
inherit AR_wasm32_unknown_unknown;
inherit CFLAGS_wasm32_unknown_unknown;
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ build_fuzz:
build_integration:
cargo test --no-run --manifest-path ./bitcoind-tests/Cargo.toml

# Build code for the WASM target
build_wasm:
cargo check --target wasm32-unknown-unknown

# Remove all temporary files
clean:
rm -rf target
Expand Down
31 changes: 16 additions & 15 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use either::Either;
use miniscript::iter::{Tree, TreeLike};
use simplicity::jet::Elements;

use crate::debug::{DebugSymbols, TrackedCallName};
use crate::debug::{CallTracker, DebugSymbols, TrackedCallName};
use crate::error::{Error, RichError, Span, WithSpan};
use crate::num::{NonZeroPow2Usize, Pow2Usize};
use crate::parse::MatchPattern;
Expand Down Expand Up @@ -39,7 +39,7 @@ impl WitnessTypes {
pub struct Program {
main: Expression,
witness_types: WitnessTypes,
tracked_calls: Arc<[(Span, TrackedCallName)]>,
call_tracker: Arc<CallTracker>,
}

impl Program {
Expand All @@ -57,11 +57,12 @@ impl Program {

/// Access the debug symbols of the program.
pub fn debug_symbols(&self, file: &str) -> DebugSymbols {
let mut debug_symbols = DebugSymbols::default();
for (span, name) in self.tracked_calls.iter() {
debug_symbols.insert(*span, name.clone(), file);
}
debug_symbols
self.call_tracker.with_file(file)
}

/// Access the tracker of function calls.
pub(crate) fn call_tracker(&self) -> &Arc<CallTracker> {
&self.call_tracker
}
}

Expand Down Expand Up @@ -485,7 +486,7 @@ struct Scope {
witnesses: HashMap<WitnessName, ResolvedType>,
functions: HashMap<FunctionName, CustomFunction>,
is_main: bool,
tracked_calls: Vec<(Span, TrackedCallName)>,
call_tracker: CallTracker,
}

impl Scope {
Expand Down Expand Up @@ -602,9 +603,9 @@ impl Scope {
/// Consume the scope and return its contents:
///
/// 1. The map that assigns witness names to their expected type.
/// 2. The list of tracked function calls.
pub fn destruct(self) -> (WitnessTypes, Vec<(Span, TrackedCallName)>) {
(WitnessTypes(self.witnesses), self.tracked_calls)
/// 2. The function call tracker.
pub fn destruct(self) -> (WitnessTypes, CallTracker) {
(WitnessTypes(self.witnesses), self.call_tracker)
}

/// Insert a custom function into the global map.
Expand Down Expand Up @@ -633,7 +634,7 @@ impl Scope {

/// Track a call expression with its span.
pub fn track_call<S: AsRef<Span>>(&mut self, span: &S, name: TrackedCallName) {
self.tracked_calls.push((*span.as_ref(), name));
self.call_tracker.track_call(*span.as_ref(), name);
}
}

Expand All @@ -660,7 +661,7 @@ impl Program {
.map(|s| Item::analyze(s, &unit, &mut scope))
.collect::<Result<Vec<Item>, RichError>>()?;
debug_assert!(scope.is_topmost());
let (witness_types, tracked_calls) = scope.destruct();
let (witness_types, call_tracker) = scope.destruct();
let mut iter = items.into_iter().filter_map(|item| match item {
Item::Function(Function::Main(expr)) => Some(expr),
_ => None,
Expand All @@ -672,7 +673,7 @@ impl Program {
Ok(Self {
main,
witness_types,
tracked_calls: tracked_calls.into_iter().collect(),
call_tracker: Arc::new(call_tracker),
})
}
}
Expand Down Expand Up @@ -1110,7 +1111,7 @@ impl AbstractSyntaxTree for Call {
check_argument_types(from.args(), &args_tys).with_span(from)?;
let args = analyze_arguments(from.args(), &args_tys, scope)?;
let [arg_ty] = args_tys;
scope.track_call(from.args().first().unwrap(), TrackedCallName::Debug(arg_ty));
scope.track_call(from, TrackedCallName::Debug(arg_ty));
args
}
CallName::TypeCast(source) => {
Expand Down
Loading

0 comments on commit 21ce1a5

Please sign in to comment.