Skip to content

Commit

Permalink
Merge pull request #118 from ocpmax/wasm-binding
Browse files Browse the repository at this point in the history
wasm binding skeleton
  • Loading branch information
lefessan authored Jan 25, 2021
2 parents 1af194e + f8003fc commit b1b5f22
Show file tree
Hide file tree
Showing 40 changed files with 413 additions and 96 deletions.
30 changes: 15 additions & 15 deletions .drom
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# hash of toml configuration files
# used for generation of all files
42a6a0e0c25a89f1894856d401f8f02e:.
278dd51e1b58745b985a0d2ef237e412:.
# end context for .

# begin context for .github/workflows/doc-deploy.yml
Expand Down Expand Up @@ -32,7 +32,7 @@ ae6a87df5770f4f6a09196ec38906d5a:.gitignore

# begin context for LICENSE.md
# file LICENSE.md
c4286e88f0dca20a879274e23cf2cb8e:LICENSE.md
a6eab40337af2e76a38e4c8d30866c0b:LICENSE.md
# end context for LICENSE.md

# begin context for Makefile
Expand All @@ -42,7 +42,7 @@ c4286e88f0dca20a879274e23cf2cb8e:LICENSE.md

# begin context for README.md
# file README.md
5d523350230459e853bc57803b729e29:README.md
1ff0ab35f115b004da7c51828b5d92af:README.md
# end context for README.md

# begin context for docs/README.txt
Expand All @@ -62,7 +62,7 @@ e739f3026aa997af4026bc428f4c9ef6:docs/favicon.png

# begin context for docs/index.html
# file docs/index.html
b9a0f9e7e370fe84b6e7d3e90ceb9ba4:docs/index.html
ed28d2e07e40a7874cbc18bbc06f1e2d:docs/index.html
# end context for docs/index.html

# begin context for docs/sphinx/index.html
Expand All @@ -82,17 +82,17 @@ c8281f46ba9a11d0b61bc8ef67eaa357:docs/style.css

# begin context for drom.opam
# file drom.opam
29806d41b658c1110972b0b1f7576022:drom.opam
d5855df69929294839ca6f0728f52c27:drom.opam
# end context for drom.opam

# begin context for drom.toml
# file drom.toml
a1640359a014ab959a9798639997a921:drom.toml
179c8354c2b44c8de53a607146742626:drom.toml
# end context for drom.toml

# begin context for drom_lib.opam
# file drom_lib.opam
c11460be4cb80485ad3772b5301c6941:drom_lib.opam
7b5671645f7a7334a5cb8c2b75aa1d9a:drom_lib.opam
# end context for drom_lib.opam

# begin context for dune
Expand All @@ -102,7 +102,7 @@ c11460be4cb80485ad3772b5301c6941:drom_lib.opam

# begin context for dune-project
# file dune-project
a202354a3c0a360d9279fff87a67922d:dune-project
70849131d65433a9c6ba0c1ea930197b:dune-project
# end context for dune-project

# begin context for scripts/after.sh
Expand Down Expand Up @@ -147,7 +147,7 @@ dc4cee7810778bedcd7b9bfa95338ac4:sphinx/conf.py

# begin context for sphinx/license.rst
# file sphinx/license.rst
bba8067487813e5ef74a6ecfecfc7ac9:sphinx/license.rst
6f8d8b2e533aaf4e245bb45f36589235:sphinx/license.rst
# end context for sphinx/license.rst

# begin context for src/drom/dune
Expand All @@ -157,17 +157,17 @@ b2467739c3fd8542338ce53133b3fefd:src/drom/dune

# begin context for src/drom/index.mld
# file src/drom/index.mld
2818d15f527a37c2cfafe85ef89f675b:src/drom/index.mld
155ff396ec5ab6ff5deb5f290c25634e:src/drom/index.mld
# end context for src/drom/index.mld

# begin context for src/drom/main.ml
# file src/drom/main.ml
13a81bf0db841e7d20b3ef4a846e91bc:src/drom/main.ml
46f55db0ab1ffc429e105af60218f0c8:src/drom/main.ml
# end context for src/drom/main.ml

# begin context for src/drom/package.toml
# file src/drom/package.toml
74b32a0ebe66d431cd5a1a75e52c8093:src/drom/package.toml
0df6a7d101efd463b801a3c71f967ed2:src/drom/package.toml
# end context for src/drom/package.toml

# begin context for src/drom_lib/dune
Expand All @@ -177,17 +177,17 @@ b2467739c3fd8542338ce53133b3fefd:src/drom/dune

# begin context for src/drom_lib/index.mld
# file src/drom_lib/index.mld
3e03ec5e98f99c1d5b09dd366177ad13:src/drom_lib/index.mld
410f9035731da781d0c50b063d81f834:src/drom_lib/index.mld
# end context for src/drom_lib/index.mld

# begin context for src/drom_lib/package.toml
# file src/drom_lib/package.toml
393ea67e568f7326e7be36ee21a9aafc:src/drom_lib/package.toml
44e05f9ed47a68f1c619629becf277d5:src/drom_lib/package.toml
# end context for src/drom_lib/package.toml

# begin context for src/drom_lib/version.mlt
# file src/drom_lib/version.mlt
e2b5cde78b7715f604ce360b478884e2:src/drom_lib/version.mlt
1e501a85255c8330e7be2911d58f03d8:src/drom_lib/version.mlt
# end context for src/drom_lib/version.mlt

# begin context for test/expect-tests/dune
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2021 OCamlPro SAS & Origin Labs SAS
Copyright (c) 2020-2021 OCamlPro SAS & Origin Labs SAS

This software is distributed under the terms of the
GNU Lesser General Public License (LGPL) version 2.1 (included below).
Expand Down Expand Up @@ -170,7 +170,7 @@ If you develop a new library, and you want it to be of the greatest possible use
To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.

one line to give the library's name and an idea of what it does.
Copyright (C) year name of author
Copyright (C) years name of author

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# drom


The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like
user experience. It can be used to create full OCaml projects with
sphinx and odoc documentation. It has specific knowledge of Github and
Expand Down
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<div class="content">
<div class="header">
<h1>drom</h1>
<p>The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like
<p>
The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like
user experience. It can be used to create full OCaml projects with
sphinx and odoc documentation. It has specific knowledge of Github and
will generate files for Github Actions CI and Github pages.
Expand Down
5 changes: 3 additions & 2 deletions drom.opam
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# Do not modify, or add to the `skip` field of `drom.toml`.
opam-version: "2.0"
name: "drom"
version: "0.2.2"
version: "0.3.0"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis:
"The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience"
description: """\
description: """

The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like
user experience. It can be used to create full OCaml projects with
sphinx and odoc documentation. It has specific knowledge of Github and
Expand Down
14 changes: 4 additions & 10 deletions drom.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ license = "LGPL2"
min-edition = "4.07.0"
name = "drom"
synopsis = "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience"
version = "0.2.2"
year = 2020
version = "0.3.0"

# keys that you could also define:
# odoc-target = "...odoc-target..."
Expand All @@ -24,8 +25,7 @@ version = "0.2.2"
# homepage = "...homepage..."

[project]
description = """
The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like
description = """\nThe drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like
user experience. It can be used to create full OCaml projects with
sphinx and odoc documentation. It has specific knowledge of Github and
will generate files for Github Actions CI and Github pages.
Expand Down Expand Up @@ -69,18 +69,12 @@ ocaml-flags = "-w -a"

# project-wide fields (depends on project skeleton)
[fields]
dot-gitattributes-trailer = """
share/drom/skeletons/projects/virtual/scripts/before*.sh text=lf
share/drom/skeletons/projects/virtual/scripts/after*.sh text=lf
"""

# ...

[[package]]
dir = "src/drom"
# edit 'src/drom/package.toml' for package-specific options


[[package]]
dir = "src/drom_lib"
# edit 'src/drom_lib/package.toml' for package-specific options

5 changes: 3 additions & 2 deletions drom_lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# Do not modify, or add to the `skip` field of `drom.toml`.
opam-version: "2.0"
name: "drom_lib"
version: "0.2.2"
version: "0.3.0"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis:
"The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience"
description: """\
description: """

The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like
user experience. It can be used to create full OCaml projects with
sphinx and odoc documentation. It has specific knowledge of Github and
Expand Down
26 changes: 26 additions & 0 deletions dune
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,28 @@
as "skeletons/packages/vue_library/templates/dune_")
( "share/drom/skeletons/packages/vue_library/templates/hello.html"
as "skeletons/packages/vue_library/templates/hello.html")
( "share/drom/skeletons/packages/wasm_binding/build_wasm.sh"
as "skeletons/packages/wasm_binding/build_wasm.sh")
( "share/drom/skeletons/packages/wasm_binding/dune_"
as "skeletons/packages/wasm_binding/dune_")
( "share/drom/skeletons/packages/wasm_binding/index.mld"
as "skeletons/packages/wasm_binding/index.mld")
( "share/drom/skeletons/packages/wasm_binding/main.c"
as "skeletons/packages/wasm_binding/main.c")
( "share/drom/skeletons/packages/wasm_binding/main.h"
as "skeletons/packages/wasm_binding/main.h")
( "share/drom/skeletons/packages/wasm_binding/main.ml"
as "skeletons/packages/wasm_binding/main.ml")
( "share/drom/skeletons/packages/wasm_binding/package.toml"
as "skeletons/packages/wasm_binding/package.toml")
( "share/drom/skeletons/packages/wasm_binding/skeleton.toml"
as "skeletons/packages/wasm_binding/skeleton.toml")
( "share/drom/skeletons/packages/wasm_binding/stubs.c"
as "skeletons/packages/wasm_binding/stubs.c")
( "share/drom/skeletons/packages/wasm_binding/stubs.js"
as "skeletons/packages/wasm_binding/stubs.js")
( "share/drom/skeletons/packages/wasm_binding/wasm_utils.js"
as "skeletons/packages/wasm_binding/wasm_utils.js")
( "share/drom/skeletons/projects/c_binding/drom.toml"
as "skeletons/projects/c_binding/drom.toml")
( "share/drom/skeletons/projects/c_binding/skeleton.toml"
Expand Down Expand Up @@ -332,6 +354,10 @@
as "skeletons/projects/vue/index.html")
( "share/drom/skeletons/projects/vue/skeleton.toml"
as "skeletons/projects/vue/skeleton.toml")
( "share/drom/skeletons/projects/wasm_binding/drom.toml"
as "skeletons/projects/wasm_binding/drom.toml")
( "share/drom/skeletons/projects/wasm_binding/skeleton.toml"
as "skeletons/projects/wasm_binding/skeleton.toml")
)
(section share)
(package drom))
Expand Down
6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
(name drom)
(allow_approximate_merlin)
(generate_opam_files false)
(version 0.2.2)
(version 0.3.0)
(formatting (enabled_for ocaml reason))

(package
(name drom)
(synopsis "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience")
(description "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like\nuser experience. It can be used to create full OCaml projects with\nsphinx and odoc documentation. It has specific knowledge of Github and\nwill generate files for Github Actions CI and Github pages.\n")
(description "\nThe drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like\nuser experience. It can be used to create full OCaml projects with\nsphinx and odoc documentation. It has specific knowledge of Github and\nwill generate files for Github Actions CI and Github pages.\n")
(depends
(ocaml (>= 4.07.0))
(drom_lib (= version))
Expand All @@ -22,7 +22,7 @@
(package
(name drom_lib)
(synopsis "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience")
(description "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like\nuser experience. It can be used to create full OCaml projects with\nsphinx and odoc documentation. It has specific knowledge of Github and\nwill generate files for Github Actions CI and Github pages.\n")
(description "\nThe drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like\nuser experience. It can be used to create full OCaml projects with\nsphinx and odoc documentation. It has specific knowledge of Github and\nwill generate files for Github Actions CI and Github pages.\n")
(depends
(ocaml (>= 4.07.0))
(toml (and (>= 6.0.0) (< 7.0.0)))
Expand Down
4 changes: 2 additions & 2 deletions share/drom/licenses/GPL3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
Copyright (C) <years> <name of author>
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
Expand All @@ -662,7 +662,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
<program> Copyright (C) <years> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
2 changes: 1 addition & 1 deletion share/drom/licenses/LGPL2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ If you develop a new library, and you want it to be of the greatest possible use
To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
one line to give the library's name and an idea of what it does.
Copyright (C) year name of author
Copyright (C) years name of author
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
75 changes: 75 additions & 0 deletions share/drom/skeletons/packages/wasm_binding/build_wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

path=src
output=dist/main.js
optimize="-O3"

while getopts o:p:O: flag; do
case $flag in
o) output=${OPTARG};;
p) path=${OPTARG};;
O) optimize="-O"${OPTARG};;
esac
done

src=( !(c-names-dot-c) )

src=(${src[@]/#/$path/})

emcc \
$optimize \
-o $output \
${src[@]} \
-DKRML_NOUINT128 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s EXPORT_NAME=wasm_loader \
-s WASM_BIGINT=1 \
-s EXPORTED_FUNCTIONS='[ "_malloc", "_free", "_reverse"]'

sed -i '1s/^/\/\/Provides: wasm_loader const/' $output
sed -i '3i\
var ArrayBuffer = joo_global_object.ArrayBuffer;\
var Browser = joo_global_object.Browser;\
var Buffer = joo_global_object.Buffer;\
var Float32Array = joo_global_object.Float32Array;\
var Float64Array = joo_global_object.Float64Array;\
var Int16Array = joo_global_object.Int16Array;\
var Int32Array = joo_global_object.Int32Array;\
var Int8Array = joo_global_object.Int8Array;\
var Promise = joo_global_object.Promise;\
var TextDecoder = joo_global_object.TextDecoder;\
var Uint16Array = joo_global_object.Uint16Array;\
var Uint32Array = joo_global_object.Uint32Array;\
var Uint8Array = joo_global_object.Uint8Array;\
var WebAssembly = joo_global_object.WebAssembly;\
var __dirname = joo_global_object.__dirname;\
var __filename = joo_global_object.__filename;\
var clearInterval = joo_global_object.clearInterval;\
var console = joo_global_object.console;\
var crypto = joo_global_object.crypto;\
var fetch = joo_global_object.fetch;\
var importScripts = joo_global_object.importScripts;\
var print = joo_global_object.print;\
var printErr = joo_global_object.printErr;\
var process = joo_global_object.process;\
var quit = joo_global_object.quit;\
var read = joo_global_object.read;\
var readbuffer = joo_global_object.readbuffer;\
var readline = joo_global_object.readline;\
var scriptArgs = joo_global_object.scriptArgs;\
var setTimeout = joo_global_object.setTimeout;' $output
sed -e :a -e '$d;N;2,7ba' -e 'P;D' -i $output
echo "
//Provides: wasm_ready
//Requires: caml_failwith
function wasm_ready() {
caml_failwith('wasm not yet loaded');
}
//Provides: wasm
//Requires: wasm_loader, wasm_ready
var wasm = wasm_loader().then(function(r) {
wasm = r;
wasm_ready = function() { return true; };
})" >> $output
Loading

0 comments on commit b1b5f22

Please sign in to comment.