Skip to content

Commit

Permalink
WIP: wasm support for SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
afilini committed Apr 24, 2024
1 parent 615032a commit dcc67f7
Show file tree
Hide file tree
Showing 8 changed files with 729 additions and 423 deletions.
995 changes: 606 additions & 389 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
rustVersion = "1.76.0";
getRust =
# fullAndroid implies withAndroid
{ fullAndroid ? false, withAndroid ? fullAndroid, withIos ? false, withEmbedded ? false }:
{ fullAndroid ? false, withAndroid ? fullAndroid, withIos ? false, withEmbedded ? false, withWasm ? false }:

(pkgs.rust-bin.stable.${rustVersion}.default.override {
extensions = [
"rust-src" # for rust-analyzer
];
targets = []
++ pkgs.lib.optionals withEmbedded ["thumbv7em-none-eabihf"]
++ pkgs.lib.optionals withWasm ["wasm32-unknown-unknown"]
++ pkgs.lib.optionals withAndroid ["x86_64-linux-android" "aarch64-linux-android"]
++ pkgs.lib.optionals fullAndroid ["i686-linux-android" "armv7-linux-androideabi"]
++ pkgs.lib.optionals withIos [ "aarch64-apple-ios-sim" "x86_64-apple-ios" "aarch64-apple-ios" ];
Expand Down Expand Up @@ -76,6 +77,7 @@

defaultDeps = with pkgs; [ cmake SDL2 fltk pango rust-analyzer pkg-config libusb ];
embeddedDeps = with pkgs; [ probe-rs gcc-arm-embedded qemu gdb openocd clang (getRust { withEmbedded = true; }) ];
wasmDeps = with pkgs; [ wasm-bindgen-cli clang (getRust { withWasm = true; }) ];
androidDeps = with pkgs; [ cargo-ndk jdk gnupg (getRust { fullAndroid = true; }) ];
iosDeps = with pkgs; [ (getRust { withIos = true; }) ];
in
Expand All @@ -84,6 +86,14 @@
devShells.default = pkgs.mkShell {
buildInputs = defaultDeps ++ [ rust ];
};
devShells.wasm = pkgs.mkShell {
buildInputs = defaultDeps ++ wasmDeps ++ [ rust ];

shellHook = ''
export CC_wasm32_unknown_unknown="clang"
export CFLAGS_wasm32_unknown_unknown="-I${pkgs.clang}/resource-root/include -fno-stack-protector"
'';
};
devShells.embedded = pkgs.mkShell {
buildInputs = defaultDeps ++ embeddedDeps ++ [ packages.hal ];

Expand Down
5 changes: 5 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ dummy-uniffi = { path = "../dummy-uniffi" }
android_logger = { version = "0.13.3", optional = true }
env_logger = { version = "0.10", optional = true }

wasm-bindgen = { version = "=0.2.91", optional = true }
wasm-bindgen-futures = { version = "0.4", optional = true }
getrandom = { version = "0.2", features = ["js"], optional = true }

model = { path = "../model" }

[features]
Expand All @@ -33,6 +37,7 @@ cli-pcsc = ["pcsc", "cli-common"]
bindings = ["uniffi", "uniffi/cli", "debug"] # Binings needs the debug port enabled because the method cannot be conditionally removed under uniffi
android = ["android_logger"]
ios = []
wasm = ["wasm-bindgen", "wasm-bindgen-futures", "getrandom"]
debug = ["model/emulator"]

[[bin]]
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/bin/cli.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Portal Hardware Wallet firmware and supporting software libraries
//
//
// Copyright (C) 2024 Alekos Filini
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

Expand Down
8 changes: 4 additions & 4 deletions sdk/src/bin/pcsc.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Portal Hardware Wallet firmware and supporting software libraries
//
//
// Copyright (C) 2024 Alekos Filini
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

Expand Down
8 changes: 4 additions & 4 deletions sdk/src/bin/uniffi-bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Portal Hardware Wallet firmware and supporting software libraries
//
//
// Copyright (C) 2024 Alekos Filini
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

Expand Down
8 changes: 4 additions & 4 deletions sdk/src/inner_logic.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Portal Hardware Wallet firmware and supporting software libraries
//
//
// Copyright (C) 2024 Alekos Filini
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

Expand Down
Loading

0 comments on commit dcc67f7

Please sign in to comment.