Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm rework #2825

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion Cargo.lock

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

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ web-sys = { version = "0.3", features = [
"Performance",
] }
js-sys = "0.3"
ouroboros = "0.18"

[dev-dependencies]
maplit = "1.0.2"
Expand All @@ -139,6 +140,17 @@ opt-level = 3
lto = true
opt-level = 3

[profile.wasm-dev]
inherits = "dev"
opt-level = 1
lto = "off"

[profile.wasm-release]
inherits = "release"
lto = "off"
panic = "abort"
codegen-units = 256

[[bench]]
name = "run_criterion"
harness = false
Expand Down
15 changes: 14 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
rustToolchainDev = super.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" ];
};
rustToolchainDevWasm = super.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" ];
targets = [ "wasm32-unknown-unknown" ];
};
rustToolchainNightly = super.rust-bin.selectLatestNightlyWith (toolchain:
toolchain.default.override {
extensions = [ "rust-src" "rust-analyzer" "miri" ];
Expand All @@ -38,12 +42,21 @@
in
{
devShells = {
default = pkgs.mkShell {
default = pkgs.mkShell.override { stdenv = pkgs.clangMultiStdenv; } {
nativeBuildInputs = nativeBuildInputs;
buildInputs = buildInputs ++ (with pkgs; [
rustToolchainDev
]);
};
wasm-js = pkgs.mkShell.override { stdenv = pkgs.clangMultiStdenv; } {
nativeBuildInputs = nativeBuildInputs;
buildInputs = buildInputs ++ (with pkgs; [
wasm-pack
rustToolchainDevWasm
]);
TARGET_CC = "${pkgs.clangMultiStdenv.cc}/bin/clang";
hardeningDisable = [ "all" ];
};
# For use with Miri and stuff like it
nightly = pkgs.mkShell {
nativeBuildInputs = nativeBuildInputs;
Expand Down
6 changes: 5 additions & 1 deletion src/bin/scryer-prolog.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
fn main() -> std::process::ExitCode {
scryer_prolog::run_binary()
#[cfg(target_arch = "wasm32")]
return std::process::ExitCode::SUCCESS;

#[cfg(not(target_arch = "wasm32"))]
return scryer_prolog::run_binary();
}
16 changes: 2 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,15 @@ mod repl_helper;
mod targets;
pub(crate) mod types;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

// Re-exports
pub use machine::config::*;
pub use machine::lib_machine::*;
pub use machine::Machine;

/// Eval a source file in Wasm.
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn eval_code(s: &str) -> String {
use machine::mock_wam::*;

console_error_panic_hook::set_once();

let mut wam = MachineBuilder::default().build();
let bytes = wam.test_load_string(s);
String::from_utf8_lossy(&bytes).to_string()
}
pub mod wasm;

#[cfg(not(target_arch = "wasm32"))]
/// The entry point for the Scryer Prolog CLI.
pub fn run_binary() -> std::process::ExitCode {
use crate::atom_table::Atom;
Expand Down
Loading
Loading