Skip to content

Commit

Permalink
Try doing a module version
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 21, 2024
1 parent 8d3a4cb commit 9f46a0a
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 86 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
target: wasm32-unknown-unknown

- run: |
rustup default stable
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
- run: cargo install wasm-pack

- uses: mymindstorm/setup-emsdk@v14
with:
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ Olivia's Project Euler Solutions
<a href="https://euler.oliviaappleton.com/_static/test-rs.html" target="_blank">click here!</a>

.. [1] This is the earliest standard the MSVC explicitly supports.
.. .. [2] (This target is not yet complete.) While these solutions do run in most browsers, they need to be bundled with Emscripten first,
.. and these tests not yet automated as in |clang| and |gcc|. To run these tests yourself, |test-c-link|
.. .. [3] (This target is not yet complete.) While these solutions do run in most browsers, they need to be bundled with Emscripten first,
.. and these tests not yet automated as in |clang| and |gcc|. To run these tests yourself, |test-cp-link|
.. [2] While these solutions do run in most browsers, they need to be bundled with Emscripten first,
and these tests not yet automated as in |clang| and |gcc|. To run these tests yourself, |test-c-link|
.. [3] While these solutions do run in most browsers, they need to be bundled with Emscripten first,
and these tests not yet automated as in |clang| and |gcc|. To run these tests yourself, |test-cp-link|
.. .. [#] (This target is not yet complete.) While these solutions do run in most browsers, they need to be bundled with DotNetAnywhere first,
.. and these tests not yet automated as in mainline .NET. To run these tests yourself, |test-cs-link|
.. .. [#] (This target is not yet complete.) While these solutions do run in most browsers, they need to be bundled with CheerpJ first,
Expand Down
4 changes: 2 additions & 2 deletions c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ native_test: native
clean:
@rm -rf build dist {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo

dist/lib.wasm: build/c-lib.c
dist/c-lib.wasm: build/lib.c
@mkdir -p dist
@emcc build/lib.c -Wl,--whole-archive -DUNITY_END -O$(O) -o dist/c-lib.js
@emcc build/lib.c -Wl,--whole-archive -DUNITY_END -O$(O) -o dist/c-lib.mjs

build/lib.c: ../LICENSE
@mkdir -p build
Expand Down
2 changes: 1 addition & 1 deletion cplusplus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ clean:

dist/cp-lib.wasm: build/lib.cpp
@mkdir -p dist
@emcc build/lib.cpp -Wl,--whole-archive -DUNITY_END -O$(O) -o dist/cp-lib.js
@emcc build/lib.cpp -Wl,--whole-archive -DUNITY_END -O$(O) -o dist/cp-lib.mjs

build/lib.cpp: ../LICENSE
@mkdir -p build
Expand Down
5 changes: 4 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ _static/dist/bundle.js:

_static/dist/c-lib.js:
@$(MAKE) -C ../c dist/c-lib.wasm $(MFLAGS)
@mkdir -p _static/dist
@cp ../c/dist/c-lib.* _static/dist/

_static/dist/cp-lib.js:
@$(MAKE) -C ../cplusplus dist/cp-lib.wasm $(MFLAGS)
@cp ../c/dist/cp-lib.* _static/dist/
@mkdir -p _static/dist
@cp ../cplusplus/dist/cp-lib.* _static/dist/

_static/dist/rust.js:
@mkdir -p _static/dist
@cd ../rust && wasm-pack build --target web --out-dir ../docs/_static/dist/

_static/dist/python.tar.gz:
Expand Down
78 changes: 41 additions & 37 deletions docs/_static/test-c.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,53 @@
<div id="mocha"></div>
<!-- Mocha setup and initiation code -->
<script type="module">
import * as wasm from './dist/c/lib.js';
import Module from './dist/c-lib.mjs';
import init, { get_js_answer } from './dist/rust.js';
mocha.setup('bdd');
window.onload = function() {
for (let p = 1; p < 10000; p++) {
const formattedQuestion = `${p}`.padStart(4, '0');
const func = wasm[`_p${formattedQuestion}`];
if (func === undefined) continue;
const expected = wasm._get_answer(p);
describe(`run test ${p}`, function() {
this.timeout(Infinity);
it(`should return ${expected}`, async () => {
const answer = func();
console.log(p, answer, expected);
if (answer !== expected) {
throw new Error();
}
Module().then(async (wasm) => {
await init();
for (let p = 1; p < 10000; p++) {
const formattedQuestion = `${p}`.padStart(4, '0');
const func = wasm[`_p${formattedQuestion}`];
if (func === undefined) continue;
const expected = get_js_answer(p);
describe(`run test ${p}`, function() {
this.timeout(Infinity);
it(`should return ${expected}`, async () => {
const answer = func();
console.log(p, answer, expected);
if (answer !== expected) {
throw new Error();
}
});
});
});
}
const runner = mocha.run();
let failedTests = [];
}
const runner = mocha.run();
let failedTests = [];

runner.on('end', function() {
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});
runner.on('end', function() {
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});

runner.on('fail', function(test, err){
const flattenTitles = function(test){
let titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};
runner.on('fail', function(test, err){
const flattenTitles = function(test){
let titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};

failedTests.push({
name: test.title,
result: false,
message: err.message,
stack: err.stack,
titles: flattenTitles(test)
failedTests.push({
name: test.title,
result: false,
message: err.message,
stack: err.stack,
titles: flattenTitles(test)
});
});
});
};
Expand Down
78 changes: 41 additions & 37 deletions docs/_static/test-cp.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,53 @@
<div id="mocha"></div>
<!-- Mocha setup and initiation code -->
<script type="module">
import * as wasm from './dist/cp/lib.js';
import Module from './dist/c-lib.mjs';
import init, { get_js_answer } from './dist/rust.js';
mocha.setup('bdd');
window.onload = function() {
for (let p = 1; p < 10000; p++) {
const formattedQuestion = `${p}`.padStart(4, '0');
const func = wasm[`_p${formattedQuestion}`];
if (func === undefined) continue;
const expected = wasm._get_answer(p);
describe(`run test ${p}`, function() {
this.timeout(Infinity);
it(`should return ${expected}`, async () => {
const answer = func();
console.log(p, answer, expected);
if (answer !== expected) {
throw new Error();
}
Module().then(async (wasm) => {
await init();
for (let p = 1; p < 10000; p++) {
const formattedQuestion = `${p}`.padStart(4, '0');
const func = wasm[`_p${formattedQuestion}`];
if (func === undefined) continue;
const expected = get_js_answer(p);
describe(`run test ${p}`, function() {
this.timeout(Infinity);
it(`should return ${expected}`, async () => {
const answer = func();
console.log(p, answer, expected);
if (answer !== expected) {
throw new Error();
}
});
});
});
}
const runner = mocha.run();
let failedTests = [];
}
const runner = mocha.run();
let failedTests = [];

runner.on('end', function() {
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});
runner.on('end', function() {
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});

runner.on('fail', function(test, err){
const flattenTitles = function(test){
let titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};
runner.on('fail', function(test, err){
const flattenTitles = function(test){
let titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};

failedTests.push({
name: test.title,
result: false,
message: err.message,
stack: err.stack,
titles: flattenTitles(test)
failedTests.push({
name: test.title,
result: false,
message: err.message,
stack: err.stack,
titles: flattenTitles(test)
});
});
});
};
Expand Down

0 comments on commit 9f46a0a

Please sign in to comment.