Skip to content

Commit

Permalink
feat: Autoreload (wasmerio#31)
Browse files Browse the repository at this point in the history
* docs: Add hello-world example

* feat: Use clap for CLI argument parsing

Switches arg parsing to the clap crate.

Also adds a "serve" subcommand, in preparation for adding additional
commands.

For backwards compatibility, not specifying a subcommand still works.

* feat: Javascript code autoreload

Adds a new watch mode that will auto-reload the Javascript app code and
re-initialize the runner on changes.

Activated with the --watch flag.

Also renames --interface argument to --ip

* build: Nix devshell improvements

Add additional dependencies to the Nix devshell.
  • Loading branch information
theduke authored Nov 13, 2023
1 parent af8fe47 commit 4d32a96
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 89 deletions.
113 changes: 113 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ rand = "0.8.5"
sha1 = "0.10.6"
sha2 = "0.10.8"
md5 = "0.7.0"
clap = { version = "4.4.7", features = ["derive", "env"] }

[patch.crates-io]
tokio = { git = "https://github.com/wasix-org/tokio.git", branch = "epoll" }
Expand Down
11 changes: 11 additions & 0 deletions examples/hello-world.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


function handler(req) {
return new Response('Hello, world!', {
headers: {
'content-type': 'text/plain',
},
});
}

addEventListener('fetch', (ev) => ev.respondWith(handler(ev.request)));
83 changes: 58 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
description = "app";
description = "winterjs - A Javascript runtime following the WinterCG spec.";

inputs = {
flakeutils = {
Expand All @@ -11,13 +11,14 @@
outputs = { self, nixpkgs, flakeutils }:
flakeutils.lib.eachDefaultSystem (system:
let
NAME = "app";
VERSION = "0.1";
NAME = "winterjs";
VERSION = "0.1.0";

pkgs = import nixpkgs {
inherit system;
};

llvm = pkgs.llvmPackages_latest;
in
rec {

Expand All @@ -36,35 +37,67 @@
# };
# defaultApp = apps.${NAME};

devShell = pkgs.stdenv.mkDerivation {
name = NAME;
src = self;
buildInputs = with pkgs; [
# rustup
# python3
# perl

llvmPackages_16.bintools-unwrapped
devShell = pkgs.mkShell.override { stdenv = pkgs.llvmPackages_latest.stdenv; } rec {
packages = with pkgs; [
# llvmPackages_16.bintools-unwrapped
pkg-config
gnum4

# builder
gnumake
cmake
bear

# debugger
llvmPackages_latest.lldb
gdb

# fix headers not found
clang-tools

# LSP and compiler
llvmPackages_latest.libstdcxxClang

# other tools
cppcheck
llvmPackages_latest.libllvm
valgrind

# stdlib for cpp
llvmPackages_latest.libcxx

# libs
llvmPackages_latest.libclang
zlib
llvmPackages_16.libclang
];
runtimeDependencies = with pkgs; [ ];

LD_LIBRARY_PATH= pkgs.lib.makeLibraryPath (with pkgs; [
zlib
llvmPackages_16.libclang
]);

# standalone as(1) doesn’t treat -DNDEBUG as -D NDEBUG (define), but rather -D (produce
# assembler debugging messages) + -N (invalid option); see also <https://bugs.gentoo.org/732190>
# /nix/store/a64w6zy8w9hcj6b4g5nz0dl6zyd24c1x-gcc-wrapper-11.3.0/bin/as: invalid option -- 'N'
# make[4]: *** [/path/to/mozjs/mozjs/mozjs/config/rules.mk:664: icu_data.o] Error 1
# make[3]: *** [/path/to/mozjs/mozjs/mozjs/config/recurse.mk:72: config/external/icu/data/target-objects] Error 2
AS="$CC -c";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath packages;


shellHook = ''
export AS="$CC -c"
'';
};

# devShell = pkgs.stdenv.mkDerivation {
# name = NAME;
# src = self;
# buildInputs = with pkgs; [
# ];
# runtimeDependencies = with pkgs; [ ];

# LD_LIBRARY_PATH= pkgs.lib.makeLibraryPath (with pkgs; [
# zlib
# llvmPackages_16.libclang
# ]);

# # standalone as(1) doesn’t treat -DNDEBUG as -D NDEBUG (define), but rather -D (produce
# # assembler debugging messages) + -N (invalid option); see also <https://bugs.gentoo.org/732190>
# # /nix/store/a64w6zy8w9hcj6b4g5nz0dl6zyd24c1x-gcc-wrapper-11.3.0/bin/as: invalid option -- 'N'
# # make[4]: *** [/path/to/mozjs/mozjs/mozjs/config/rules.mk:664: icu_data.o] Error 1
# # make[3]: *** [/path/to/mozjs/mozjs/mozjs/config/recurse.mk:72: config/external/icu/data/target-objects] Error 2
# AS="$CC -c";
# };
}
);
}
5 changes: 5 additions & 0 deletions src/ion_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ mod fetch_event;
mod performance;
mod request;

mod watch;
pub use watch::WatchRunner;

use std::{
path::Path,
str::FromStr,
Expand Down Expand Up @@ -313,6 +316,8 @@ pub struct IonRunner {
user_code: String,
}

pub type SharedIonRunner = Arc<Mutex<IonRunner>>;

impl IonRunner {
pub fn new(max_threads: usize, user_code: String) -> Self {
if max_threads == 0 {
Expand Down
Loading

0 comments on commit 4d32a96

Please sign in to comment.