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 ba93637
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 82 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
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
76 changes: 39 additions & 37 deletions docs/_static/test-c.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,51 @@
<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';
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((wasm) => {
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();
}
});
});
});
}
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
76 changes: 39 additions & 37 deletions docs/_static/test-cp.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,51 @@
<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';
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((wasm) => {
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();
}
});
});
});
}
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 ba93637

Please sign in to comment.