initial emjs build & test chain impl - excluding it from global jest tests pending imminent wasm parent path fix PR merge

pull/41/head
Paul Shapiro 6 years ago
parent f69da791fc
commit 7a7148537c

5
.gitignore vendored

@ -1,4 +1,7 @@
.DS_Store
node_modules/
coverage
.vscode
.vscode
build
tests/emjs/MyMoneroCoreCpp.wasm
tests/emjs/MyMoneroCoreCpp.js

@ -0,0 +1,78 @@
cmake_minimum_required(VERSION 3.4.1)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
project(MyMoneroCoreCpp)
# enable_testing()
#Find openSSL
# find_package(OpenSSL COMPONENTS
# crypto REQUIRED
# ssl REQUIRED
# )
# #Prep ourselves for compiling boost
# find_package(Boost COMPONENTS
# unit_test_framework REQUIRED
# atomic REQUIRED
# chrono REQUIRED
# context REQUIRED
# date_time REQUIRED
# exception REQUIRED
# filesystem REQUIRED
# graph REQUIRED
# iostreams REQUIRED
# math_c99 REQUIRED
# math_c99f REQUIRED
# math_c99l REQUIRED
# math_tr1 REQUIRED
# math_tr1f REQUIRED
# math_tr1l REQUIRED
# prg_exec_monitor REQUIRED
# program_options REQUIRED
# random REQUIRED
# regex REQUIRED
# serialization REQUIRED
# signals REQUIRED
# system REQUIRED
# test_exec_monitor REQUIRED
# thread REQUIRED
# timer REQUIRED
# wave REQUIRED
# wserialization REQUIRED
# )
# include_directories(${Boost_INCLUDE_DIRS})
include_directories("src")
include_directories("src/mymonero-core-cpp/src")
# include_directories("test")
# keeping test files in a separate source directory
# file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/test_*.cpp)
set(
SRC_FILES
#
src/index.cpp
#
# TODO: hopefully pick up source from src/mymonero-core-cpp/src
)
set(
EMCC_LINKER_FLAGS
"--bind -Wall -s MODULARIZE=1 -s 'EXPORT_NAME=\"MyMoneroCoreCpp\"'"#"-s SAFE_HEAP=1 --bind -s WASM=1 -O3 -o ./cryptonote_crypto.emcpp.js -s LEGACY_GL_EMULATION=0 -s GL_UNSAFE_OPTS=0 --pre-js pre-module.js --post-js post-module.js -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -s INVOKE_RUN=0 -std=c++11 -s USE_WEBGL2=1 -s FULL_ES3=1 -s USE_GLFW=3 -s OFFSCREENCANVAS_SUPPORT=1 --preload-file shaders --preload-file extern --use-preload-plugins"
)
# extract the filename without an extension (NAME_WE)
add_executable(
MyMoneroCoreCpp
${SRC_FILES}
)
set_target_properties(MyMoneroCoreCpp PROPERTIES LINK_FLAGS "${EMCC_LINKER_FLAGS}")
# set_target_properties(MyMoneroCoreCpp PROPERTIES SUFFIX ".bc")
# target_link_libraries(
# MyMoneroCoreCpp
# #
# OpenSSL::SSL
# ${Boost_LIBRARIES}
# )

@ -9,6 +9,9 @@
},
"scripts": {
"format": "find . -name '*.js*' | xargs prettier --write --config ./.prettierrc --config-precedence file-override",
"build-emcpp": "mkdir -p build && cd build && emconfigure cmake .. && emmake cmake --build . && emmake make .",
"_build-test-emjs": "npm run-script build-emcpp && cp build/MyMoneroCoreCpp.js tests/emjs/ && cp build/MyMoneroCoreCpp.wasm tests/emjs/",
"run-test-emjs": "npm run-script _build-test-emjs && cd tests/emjs && ../../node_modules/jest/bin/jest.js MyMoneroCoreCpp.spec.js",
"test": "jest",
"test:coverage": "jest --coverage"
},
@ -44,6 +47,8 @@
"cryptonote_utils/biginteger.js",
"cryptonote_utils/nacl-fast-cn.js",
"cryptonote_utils/sha3.js",
"cryptonote_utils/cryptonote_crypto_EMSCRIPTEN.js"]
"cryptonote_utils/cryptonote_crypto_EMSCRIPTEN.js",
"tests/emjs/*"
]
}
}

@ -0,0 +1,18 @@
#include <stdio.h>
#include <emscripten/bind.h>
using namespace emscripten;
float foo(float a, float b, float t)
{
return (1 - t) * a + t * b;
}
EMSCRIPTEN_BINDINGS(my_module)
{
function("foo", &foo);
}
int main() {
printf("hello, world!\n");
return 0;
}

@ -0,0 +1,72 @@
// Copyright (c) 2014-2018, MyMonero.com
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"use strict";
//
if (!process.env.LISTENING_TO_UNHANDLEDS) {
process.on('unhandledRejection', reason => {
throw reason
})
process.on('uncaughtException', e => {
throw e
})
// Avoid memory leak by adding too many listeners
process.env.LISTENING_TO_UNHANDLEDS = true
}
//
const dummy_test_utils = require("./dummy-test-utils.js");
var public_key =
"904e49462268d771cc1649084c35aa1296bfb214880fe2e7f373620a3e2ba597";
var private_key =
"52aa4c69b93b780885c9d7f51e6fd5795904962c61a2e07437e130784846f70d";
//
// var nettype = mymonero.nettype_utils.network_type.MAINNET;
//
it("Module is ready", () => {
dummy_test_utils.OnceModuleReady(
function(Module)
{
expect(Module).toBeTruthy()
}
)
})
it("has a foo which works", () => {
dummy_test_utils.OnceModuleReady(
function(Module)
{
expect(Module).toBeTruthy()
const out = Module.foo(1, 2, 0.5)
expect(out).toEqual(1.5);
}
)
})

@ -0,0 +1,62 @@
// Copyright (c) 2014-2018, MyMonero.com
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"use strict";
const MyMoneroCoreCpp = require("./MyMoneroCoreCpp.js");
var public_key =
"904e49462268d771cc1649084c35aa1296bfb214880fe2e7f373620a3e2ba597";
var private_key =
"52aa4c69b93b780885c9d7f51e6fd5795904962c61a2e07437e130784846f70d";
// var nettype = mymonero.nettype_utils.network_type.MAINNET;
var Module = null
var moduleReadyFns = [] // initial (gets set to undefined once Module ready)
exports.OnceModuleReady = function(fn)
{
if (Module == null) {
if (typeof moduleReadyFns == 'undefined' || !moduleReadyFns) {
throw "Expected moduleReadyFns"
}
moduleReadyFns.push(fn)
} else {
fn(Module)
}
}
MyMoneroCoreCpp().then(function(thisModule)
{
Module = thisModule
{
for (let fn of moduleReadyFns) {
fn(Module)
}
}
moduleReadyFns = [] // flash / free (good idea?)
});
Loading…
Cancel
Save