--out-dir=../target/packed-wasm wasm -t no-modules --release
$(stamp)
+# There is some kind of bug in wasm-pack's version of wasm-opt, which
+# can be avoided by running --dev instead (but also then using the
+# debug rust built). IME this happened when trying to return a u64,
+# so maybe bigints are affected? (Which I don't want to use anyway.)
+# See
+# https://github.com/WebAssembly/binaryen/issues/3006
+
#---------- bundle-sources ----------
bundled-sources: $(TARGET_DIR)/bundled-sources
TS_SRCS= script bigfloat
TS_SRC_FILES= \
../webassembly-types/webassembly.d.ts \
- $(addprefix $(WASM_PACKED)/,otter_wasm.d.ts) \
+ templates/otter_wasm.ns.d.ts \
$(addprefix templates/,$(addsuffix .ts,$(TS_SRCS)))
LITFILES= LICENCE AGPLv3
nodejs <$<
@echo 'nodejs check $< ok'
+templates/otter_wasm.ns.d.ts: $(WASM_PACKED)/otter_wasm.d.ts Makefile
+ set -e; exec >$@.tmp; \
+ echo 'declare namespace wasm_bindgen {'; \
+ sed 's/^export default function init/export function init/' <$<; \
+ echo '}'
+ mv -v $@.tmp $@
+
#---------- other templates ----------
$(addprefix templates/,$(LITFILES)): templates/%: %;
Template::render("test",&c)
}
-const RESOURCES : &[(&'static str, ContentType)] = &[
- ("script.js", ContentType::JavaScript),
- ("style.css", ContentType::JavaScript),
- ("LICENCE", ContentType::Plain),
- ("libre", ContentType::HTML),
- ("AGPLv3", ContentType::Plain),
- ("CC-BY-SA-3.0", ContentType::Plain),
- ("CC-BY-SA-4.0", ContentType::Plain),
+#[derive(Copy,Clone,Debug)]
+enum ResourceLocation { Main, Wasm(&'static str), }
+type RL = ResourceLocation;
+
+const RESOURCES : &[(&'static str, ResourceLocation, ContentType)] = &[
+ ("script.js", RL::Main, ContentType::JavaScript),
+ ("style.css", RL::Main, ContentType::JavaScript),
+ ("LICENCE", RL::Main, ContentType::Plain),
+ ("libre", RL::Main, ContentType::HTML),
+ ("AGPLv3", RL::Main, ContentType::Plain),
+ ("CC-BY-SA-3.0", RL::Main, ContentType::Plain),
+ ("CC-BY-SA-4.0", RL::Main, ContentType::Plain),
+ ("wasm.wasm", RL::Wasm("otter_wasm_bg.wasm"), ContentType::WASM),
+ ("wasm.js", RL::Wasm("otter_wasm.js"), ContentType::JavaScript),
];
#[derive(Debug)]
struct CheckedResourceLeaf {
safe_leaf: &'static str,
+ locn: ResourceLocation,
ctype: ContentType,
}
impl<'r> FromParam<'r> for CheckedResourceLeaf {
type Error = UnknownResource;
fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
- for &(safe_leaf, ref ctype) in RESOURCES {
+ for &(safe_leaf, locn, ref ctype) in RESOURCES {
if safe_leaf == param.as_str() {
- return Ok(CheckedResourceLeaf { safe_leaf, ctype: ctype.clone() })
+ return Ok(CheckedResourceLeaf {
+ safe_leaf, locn,
+ ctype: ctype.clone(),
+ })
}
}
Err(UnknownResource{})
#[get("/_/<leaf>")]
#[throws(io::Error)]
fn resource<'r>(leaf : CheckedResourceLeaf) -> impl Responder<'r> {
- let path = format!("{}/{}", config().template_dir, leaf.safe_leaf);
+ let path = match leaf.locn {
+ RL::Main => format!("{}/{}", config().template_dir, leaf.safe_leaf),
+ RL::Wasm(s) => format!("{}/{}", config().wasm_dir, s),
+ };
Content(leaf.ctype, NamedFile::open(path)?)
}
last_seen_moved : DOMHighResTimeStamp | null, // non-0 means halo'd
}
+let wasm : wasm_bindgen.InitOutput;
+
let pieces : { [piece: string]: PieceInfo } = Object.create(null);
type MessageHandler = (op: Object) => void;
}
function startup() {
+ console.log('STARTUP');
+ let mut = wasm_bindgen.mutable('4200000000');
+ let y = mut.next();
+ console.log('FOO', mut, y);
+
var body = document.getElementById("main-body")!;
ctoken = body.dataset.ctoken!;
us = body.dataset.us!;
document.addEventListener('keydown', some_keydown);
}
+declare var wasm_input : any;
+var wasm_promise : Promise<any>;;
+
function doload(){
console.log('DOLOAD');
var elem = document.getElementById('loading_token')!;
xhr_post_then('/_/session',
JSON.stringify({ ptoken : ptoken }),
loaded);
+
+ wasm_promise = wasm_input
+ .then(wasm_bindgen);
}
function loaded(xhr: XMLHttpRequest){
console.log('LOADED');
var body = document.getElementById('loading_body')!;
- body.outerHTML = xhr.response;
- startup();
+ wasm_promise.then((got_wasm) => {
+ wasm = got_wasm;
+ body.outerHTML = xhr.response;
+ startup();
+ });
}
// xxx scroll of log messages to bottom does not always work somehow