From 52dd0f132a6805c7e198bab360ea51c345dd21db Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 28 Dec 2019 16:11:15 -0500 Subject: [PATCH] Remove emscripten build. Prefer using custom toolchain with amalgmated build. --- CHANGELOG.md | 1 + Makefile | 29 --------- README.md | 9 --- src/webclient/main.c | 126 ------------------------------------ src/webclient/webinit.janet | 12 ---- 5 files changed, 1 insertion(+), 176 deletions(-) delete mode 100644 src/webclient/main.c delete mode 100644 src/webclient/webinit.janet diff --git a/CHANGELOG.md b/CHANGELOG.md index 3571892f..da8fb68e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. - Let abstract types define a hash function and comparison/equality semantics. This lets abstract types much better represent value types. This adds more fields to abstract types, which will generate warnings when compiled against other versions. +- Remove Emscripten build. Instead, use the amalgamated source code with a custom toolchain. - Update documentation. ### 1.6.0 - 2019-12-22 diff --git a/Makefile b/Makefile index 5f88c7f1..b9b55e45 100644 --- a/Makefile +++ b/Makefile @@ -166,35 +166,6 @@ $(JANET_LIBRARY): $(JANET_CORE_OBJECTS) $(JANET_STATIC_LIBRARY): $(JANET_CORE_OBJECTS) $(AR) rcs $@ $^ -###################### -##### Emscripten ##### -###################### - -EMCC=emcc -EMCFLAGS=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -O2 \ - -s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' \ - -s ALLOW_MEMORY_GROWTH=1 \ - -s AGGRESSIVE_VARIABLE_ELIMINATION=1 \ - -DJANET_BUILD=$(JANET_BUILD) -JANET_EMTARGET=build/janet.js -JANET_WEB_SOURCES=$(JANET_CORE_SOURCES) $(JANET_WEBCLIENT_SOURCES) -JANET_EMOBJECTS=$(patsubst src/%.c,build/%.bc,$(JANET_WEB_SOURCES)) \ - build/webinit.gen.bc build/core_image.bc - -%.gen.bc: %.gen.c - $(EMCC) $(EMCFLAGS) -o $@ -c $< - -build/core_image.bc: build/core_image.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) - $(EMCC) $(EMCFLAGS) -o $@ -c $< - -build/%.bc: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) - $(EMCC) $(EMCFLAGS) -o $@ -c $< - -$(JANET_EMTARGET): $(JANET_EMOBJECTS) - $(EMCC) $(EMCFLAGS) -shared -o $@ $^ - -emscripten: $(JANET_EMTARGET) - ############################# ##### Generated C files ##### ############################# diff --git a/README.md b/README.md index fb4dd8eb..426fb355 100644 --- a/README.md +++ b/README.md @@ -114,15 +114,6 @@ gmake repl 3. Run `build_win` to compile janet. 4. Run `build_win test` to make sure everything is working. -### Emscripten - -To build janet for the web via [Emscripten](https://kripken.github.io/emscripten-site/), make sure you -have `emcc` installed and on your path. On a linux or macOS system, use `make emscripten` to build -`janet.js` and `janet.wasm` - both are needed to run janet in a browser or in node. -The JavaScript build is what runs the repl on the main website, -but really serves mainly as a proof of concept. Janet will run slower in a browser. -Building with emscripten on windows is currently unsupported. - ### Meson Janet also has a build file for [Meson](https://mesonbuild.com/), a cross platform build diff --git a/src/webclient/main.c b/src/webclient/main.c deleted file mode 100644 index 44bca45b..00000000 --- a/src/webclient/main.c +++ /dev/null @@ -1,126 +0,0 @@ -/* -* Copyright (c) 2019 Calvin Rose -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to -* deal in the Software without restriction, including without limitation the -* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -* sell copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -* IN THE SOFTWARE. -*/ - -#include -#include - -extern const unsigned char *janet_gen_webinit; -extern int32_t janet_gen_webinit_size; - -static JanetFiber *repl_fiber = NULL; -static JanetBuffer *line_buffer = NULL; -static const uint8_t *line_prompt = NULL; - -/* Yield to JS event loop from janet. Takes a repl prompt - * and a buffer to fill with input data. */ -static Janet repl_yield(int32_t argc, Janet *argv) { - janet_fixarity(argc, 2); - line_prompt = janet_getstring(argv, 0); - line_buffer = janet_getbuffer(argv, 1); - return janet_wrap_nil(); -} - -/* Re-enter the loop */ -static int enter_loop(void) { - Janet ret; - JanetSignal status = janet_continue(repl_fiber, janet_wrap_nil(), &ret); - if (status == JANET_SIGNAL_ERROR) { - janet_stacktrace(repl_fiber, ret); - janet_deinit(); - repl_fiber = NULL; - return 1; - } - return 0; -} - -/* Allow JS interoperation from within janet */ -static Janet cfun_js(int32_t argc, Janet *argv) { - janet_fixarity(argc, 1); - JanetByteView bytes = janet_getbytes(argv, 0); - emscripten_run_script((const char *)bytes.bytes); - return janet_wrap_nil(); -} - -/* Initialize the repl */ -EMSCRIPTEN_KEEPALIVE -void repl_init(void) { - int status; - JanetTable *env; - - /* Set up VM */ - janet_init(); - janet_register("repl-yield", repl_yield); - janet_register("js", cfun_js); - env = janet_core_env(NULL); - - janet_def(env, "repl-yield", janet_wrap_cfunction(repl_yield), NULL); - janet_def(env, "js", janet_wrap_cfunction(cfun_js), NULL); - - /* Run startup script */ - Janet ret; - status = janet_dobytes(env, janet_gen_webinit, janet_gen_webinit_size, "webinit.janet", &ret); - if (status == JANET_SIGNAL_ERROR) { - printf("start up error.\n"); - janet_deinit(); - repl_fiber = NULL; - return; - } - janet_gcroot(ret); - repl_fiber = janet_unwrap_fiber(ret); - - /* Start repl */ - if (enter_loop()) return; -} - -/* Deinitialize the repl */ -EMSCRIPTEN_KEEPALIVE -void repl_deinit(void) { - if (!repl_fiber) { - return; - } - repl_fiber = NULL; - line_buffer = NULL; - janet_deinit(); -} - -/* Get the prompt to show in the repl */ -EMSCRIPTEN_KEEPALIVE -const char *repl_prompt(void) { - return line_prompt ? ((const char *)line_prompt) : ""; -} - -/* Restart the repl calling from JS. Pass in the input for the next line. */ -EMSCRIPTEN_KEEPALIVE -void repl_input(char *input) { - - /* Create the repl if we haven't yet */ - if (!repl_fiber) { - printf("initialize the repl first"); - } - - /* Now fill the pending line_buffer and resume the repl loop */ - if (line_buffer) { - janet_buffer_push_cstring(line_buffer, input); - line_buffer = NULL; - enter_loop(); - } -} diff --git a/src/webclient/webinit.janet b/src/webclient/webinit.janet deleted file mode 100644 index 3dc59eb9..00000000 --- a/src/webclient/webinit.janet +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2017-2019 (C) Calvin Rose - -(print (string "Janet " janet/version "-" janet/build " Copyright (C) 2017-2019 Calvin Rose")) - -(fiber/new (fn webrepl [] - (setdyn :pretty-format "%.20P") - (repl (fn get-line [buf p] - (def [offset] (parser/where p)) - (def prompt (string "janet:" offset ":" (parser/state p :delimiters) "> ")) - (repl-yield prompt buf) - (yield) - buf))))