Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Nov 16, 2024
2 parents 01e75c6 + 9c95f7f commit d2fcd44
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 59 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Publish to Registry with version-tag
- uses: actions/checkout@v3
- id: pre-step
shell: bash
run: echo "release-version=$(echo ${GITHUB_REF:10})" >> $GITHUB_OUTPUT
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: webarkit/nft-marker-creator-app
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tag_names: true

- name: Publish to Registry with latest-tag
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: webarkit/nft-marker-creator-app
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: "latest"
tags: "latest,${{ steps.pre-step.outputs.release-version }}"
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
with:
files: |
build/NftMarkerCreator.min.js
build/NftMarkerCreator_ES6_wasm.js
build/NftMarkerCreator_wasm.js
build/NftMarkerCreator_wasm.thread.js
src/NFTMarkerCreator.js
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ e.g `node NFTMarkerCreator.js -i image.png -level=4 -min_thresh=8`

e.g node NFTMarkerCreator.js -i image.png -Demo

## ES6 version of the build library

The library is built with Emscripten and is located in the `build` folder. It is an ES6 module and can be imported in your project.

<!-- prettier-ignore -->
```js
<script type="module">

import nftMC from '../build/NFTMarkerCreator_ES6_wasm.js';
const mc = await nftMC();

</script>
```

## Create your NTS markers with our docker image

First, you need docker installed in your system, if you haven't, follow the Docker engine installation [instruction](https://docs.docker.com/engine/install/) .
Expand Down
16 changes: 16 additions & 0 deletions build/NftMarkerCreator_ES6_wasm.js

Large diffs are not rendered by default.

116 changes: 69 additions & 47 deletions tools/makem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* @author zz85 github.com/zz85
*/

var exec = require("child_process").exec,
let exec = require("child_process").exec,
path = require("path"),
fs = require("fs"),
child;

var HAVE_NFT = 1;
const HAVE_NFT = 1;

var EMSCRIPTEN_ROOT = process.env.EMSCRIPTEN;
var WEBARKITLIB_ROOT = process.env.WEBARKITLIB_ROOT || "../emscripten/WebARKitLib";
const EMSCRIPTEN_ROOT = process.env.EMSCRIPTEN;
const WEBARKITLIB_ROOT = process.env.WEBARKITLIB_ROOT || "../emscripten/WebARKitLib";

if (!EMSCRIPTEN_ROOT) {
console.log("\nWarning: EMSCRIPTEN environment variable not found.");
Expand All @@ -20,22 +20,23 @@ if (!EMSCRIPTEN_ROOT) {
);
}

var EMCC = EMSCRIPTEN_ROOT ? path.resolve(EMSCRIPTEN_ROOT, "emcc") : "emcc";
var EMPP = EMSCRIPTEN_ROOT ? path.resolve(EMSCRIPTEN_ROOT, "em++") : "em++";
var OPTIMIZE_FLAGS = " -Oz "; // -Oz for smallest size
var MEM = 256 * 1024 * 1024; // 64MB
const EMCC = EMSCRIPTEN_ROOT ? path.resolve(EMSCRIPTEN_ROOT, "emcc") : "emcc";
const EMPP = EMSCRIPTEN_ROOT ? path.resolve(EMSCRIPTEN_ROOT, "em++") : "em++";
const OPTIMIZE_FLAGS = " -Oz "; // -Oz for smallest size
const MEM = 256 * 1024 * 1024; // 64MB

var SOURCE_PATH = path.resolve(__dirname, "../emscripten/") + "/";
var OUTPUT_PATH = path.resolve(__dirname, "../build/") + "/";
const SOURCE_PATH = path.resolve(__dirname, "../emscripten/") + "/";
const OUTPUT_PATH = path.resolve(__dirname, "../build/") + "/";

var BUILD_WASM_FILE = "NftMarkerCreator_wasm.js";
var BUILD_WASM_TD_FILE = "NftMarkerCreator_wasm.thread.js";
var BUILD_MIN_FILE = "NftMarkerCreator.min.js";
const BUILD_WASM_FILE = "NftMarkerCreator_wasm.js";
const BUILD_WASM_TD_FILE = "NftMarkerCreator_wasm.thread.js";
const BUILD_WASM_ES6_FILE = "NftMarkerCreator_ES6_wasm.js";
const BUILD_MIN_FILE = "NftMarkerCreator.min.js";

// prettier-ignore
var MAIN_SOURCES = [
'markerCreator.cpp',
'markerCompress.cpp'
let MAIN_SOURCES = [
'markerCreator.cpp',
'markerCompress.cpp'
];

MAIN_SOURCES = MAIN_SOURCES.map(function (src) {
Expand All @@ -45,14 +46,14 @@ MAIN_SOURCES = MAIN_SOURCES.map(function (src) {
let srcTest = path.resolve(__dirname, WEBARKITLIB_ROOT + "/lib/SRC/");

// prettier-ignore
var ar_sources = [
let ar_sources = [
'ARUtil/log.c',
'ARUtil/file_utils.c',
].map(function(src) {
return path.resolve(__dirname, WEBARKITLIB_ROOT + '/lib/SRC/', src);
].map(function (src) {
return path.resolve(__dirname, WEBARKITLIB_ROOT + '/lib/SRC/', src);
});

var ar2_sources = [
const ar2_sources = [
"handle.c",
"imageSet.c",
"jpeg.c",
Expand All @@ -73,7 +74,7 @@ var ar2_sources = [
return path.resolve(__dirname, WEBARKITLIB_ROOT + "/lib/SRC/AR2/", src);
});

var kpm_sources = [
const kpm_sources = [
"KPM/kpmHandle.cpp",
"KPM/kpmRefDataSet.cpp",
"KPM/kpmMatching.cpp",
Expand All @@ -99,17 +100,17 @@ var kpm_sources = [

// prettier-ignore
if (HAVE_NFT) {
ar_sources = ar_sources
.concat(ar2_sources)
.concat(kpm_sources);
ar_sources = ar_sources
.concat(ar2_sources)
.concat(kpm_sources);
}

var DEFINES = " ";
let DEFINES = " ";
if (HAVE_NFT) DEFINES += " -D HAVE_NFT ";

var TD = " -D HAVE_THREADING ";
const TD = " -D HAVE_THREADING ";

var FLAGS = "" + OPTIMIZE_FLAGS;
let FLAGS = "" + OPTIMIZE_FLAGS;
// var FLAGS = '';
FLAGS += " -Wno-warn-absolute-paths ";
FLAGS += " -s TOTAL_MEMORY=" + MEM + " ";
Expand All @@ -118,20 +119,19 @@ FLAGS += " -s USE_ZLIB=1";
FLAGS += " -s USE_LIBJPEG=1";
FLAGS += " -s FORCE_FILESYSTEM=1";

//ONLY ENABLE FOR THE NFT-MARKER-CREATOR WEB VERSION !IMPORTANT FLAGS
// FLAGS += ' -s MODULARIZE';
// FLAGS += ' -s EXPORT_ES6=1';
// FLAGS += ' -s USE_ES6_IMPORT_META=0';
let ES6_FLAGS = "";
ES6_FLAGS +=
" -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=0 -s MODULARIZE=1 -sENVIRONMENT=web -s EXPORT_NAME='NftMC' ";

var WASM_FLAGS = " -s WASM=1 ";
const WASM_FLAGS = " -s WASM=1 ";

var SINGLE_FILE_FLAG = " -s SINGLE_FILE=1 ";
const SINGLE_FILE_FLAG = " -s SINGLE_FILE=1 ";

var EXPORTED_FUNCTIONS =
const EXPORTED_FUNCTIONS =
' -s EXPORTED_FUNCTIONS=["_createNftDataSet,_compressZip,_malloc,_free"] -s EXPORTED_RUNTIME_METHODS=["FS,stringToUTF8"] ';

/* DEBUG FLAGS */
var DEBUG_FLAGS = " -g ";
let DEBUG_FLAGS = " -g ";
// DEBUG_FLAGS += ' -s ASSERTIONS=2 '
DEBUG_FLAGS += " -s ASSERTIONS=1 ";
DEBUG_FLAGS += " --profiling ";
Expand All @@ -151,37 +151,37 @@ var INCLUDES = [
.join(" ");

function format(str) {
for (var f = 1; f < arguments.length; f++) {
for (let f = 1; f < arguments.length; f++) {
str = str.replace(/{\w*}/, arguments[f]);
}
return str;
}

function clean_builds() {
try {
var stats = fs.statSync(OUTPUT_PATH);
const stats = fs.statSync(OUTPUT_PATH);
} catch (e) {
fs.mkdirSync(OUTPUT_PATH);
}

try {
var files = fs.readdirSync(OUTPUT_PATH);
const files = fs.readdirSync(OUTPUT_PATH);
if (files.length > 0)
for (var i = 0; i < files.length; i++) {
var filePath = OUTPUT_PATH + "/" + files[i];
for (let i = 0; i < files.length; i++) {
const filePath = OUTPUT_PATH + "/" + files[i];
if (fs.statSync(filePath).isFile()) fs.unlinkSync(filePath);
}
} catch (e) {
return console.log(e);
}
}

var compile_arlib = format(
const compile_arlib = format(
EMCC + " " + INCLUDES + " " + ar_sources.join(" ") + FLAGS + " " + DEFINES + " -r -o {OUTPUT_PATH}libar.o ",
OUTPUT_PATH,
);

var compile_combine_min = format(
const compile_combine_min = format(
EMCC +
" " +
INCLUDES +
Expand All @@ -199,7 +199,7 @@ var compile_combine_min = format(
BUILD_MIN_FILE,
);

var compile_wasm = format(
const compile_wasm = format(
EMCC +
" " +
INCLUDES +
Expand All @@ -218,7 +218,27 @@ var compile_wasm = format(
BUILD_WASM_FILE,
);

var compile_wasm_td = format(
const compile_wasm_es6 = format(
EMCC +
" " +
INCLUDES +
" " +
" {OUTPUT_PATH}libar.o " +
MAIN_SOURCES +
EXPORTED_FUNCTIONS +
FLAGS +
WASM_FLAGS +
ES6_FLAGS +
SINGLE_FILE_FLAG +
DEFINES +
" -std=c++11 " +
" -o {OUTPUT_PATH}{BUILD_FILE} ",
OUTPUT_PATH,
OUTPUT_PATH,
BUILD_WASM_ES6_FILE,
);

const compile_wasm_td = format(
EMCC +
" " +
INCLUDES +
Expand Down Expand Up @@ -253,12 +273,15 @@ function onExec(error, stdout, stderr) {
}
}

const jobs = [];

function runJob() {
if (!jobs.length) {
console.log("Jobs completed");
return;
}
var cmd = jobs.shift();

const cmd = jobs.shift();

if (typeof cmd === "function") {
cmd();
Expand All @@ -270,15 +293,14 @@ function runJob() {
exec(cmd, onExec);
}

var jobs = [];

function addJob(job) {
jobs.push(job);
}

addJob(clean_builds);
addJob(compile_arlib);
addJob(compile_wasm);
addJob(compile_wasm_es6);
addJob(compile_wasm_td);
addJob(compile_combine_min);

Expand Down

0 comments on commit d2fcd44

Please sign in to comment.