Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -50,7 +50,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -64,4 +64,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
2 changes: 1 addition & 1 deletion .github/workflows/ossar-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ jobs:

# Upload results to the Security tab
- name: Upload OSSAR results
uses: github/codeql-action/upload-sarif@v1
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.ossar.outputs.sarifFile }}
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/.nyc_output
.vscode/ipch
/.vscode/c_cpp_properties.json
/.vscode/ipch
/.vscode/settings.json
/bin
/build
/coverage
/dist
/dist-test
/emsdk*
/src-expat
/src-graphviz
/lib-*
/node_modules
/rust
/src-*
/tmp
/types
/vcpkg
*.tsbuildinfo
/.vscode/c_cpp_properties.json
/.vscode/settings.json
33 changes: 31 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
"url": "http://localhost:8000/hw-zstd.html",
"webRoot": "${workspaceRoot}"
},
{
"name": "hw-base91.html",
"type": "msedge",
"request": "launch",
"url": "http://localhost:8000/hw-base91.html",
"webRoot": "${workspaceRoot}"
},
{
"name": "test-browser",
"type": "msedge",
Expand All @@ -50,9 +57,31 @@
],
"type": "node"
},
{
"name": "sfx-wasm",
"program": "${workspaceFolder}/bin/sfx-wasm.mjs",
"request": "launch",
"args": [
"./build/cpp/base91/base91lib.wasm"
],
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"name": "cli rollup wasm",
"program": "${workspaceFolder}/output-node/test-wasm.js",
"request": "launch",
"args": [],
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"name": "CLI",
"program": "${workspaceFolder}/bin/cli.js",
"program": "${workspaceFolder}/bin/dot-wasm.mjs",
"request": "launch",
"args": [
"-K neato",
Expand All @@ -66,7 +95,7 @@
},
{
"name": "CLI Version",
"program": "${workspaceFolder}/bin/cli.js",
"program": "${workspaceFolder}/bin/dot-wasm.mjs",
"request": "launch",
"args": [
"-v"
Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ SET(EM_FLAGS
"-s INVOKE_RUN=0"
"-s ALLOW_MEMORY_GROWTH=1"
"-s WASM=1"
"-s MODULARIZE"
"-s ENVIRONMENT=web"
"-s FILESYSTEM=0"
# "-s MINIMAL_RUNTIME=1"
Expand All @@ -21,7 +20,7 @@ SET(EM_FLAGS
"-s USE_ES6_IMPORT_META=0"
# "-s WASM_BIGINT=1"
"--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/pre.js"
# "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/post.js"
"--post-js ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/post.js"
)

IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
176 changes: 146 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Built with:
- [Zstandard (zstd)](#zstandard)
- [Hello World](#zstandard-hello-world)
- [API](#zstandard-api)
- [Base91](#base91)
- [Hello World](#base91-hello-world)
- [API](#base91-api)
- [Utilities](#utility)
- [Building @hpcc-js/wasm](#building-hpcc-js-wasm)

Expand Down Expand Up @@ -108,7 +111,7 @@ GraphViz WASM library, see [graphviz.org](https://www.graphviz.org/) for c++ det

To call `dot-wasm` without installing:
```
npx @hpcc-js/wasm [options] fileOrDot
npx -p @hpcc-js/wasm dot-wasm [options] fileOrDot
```

To install the global command `dot-wasm` via NPM:
Expand All @@ -121,38 +124,35 @@ Usage:
Usage: dot-wasm [options] fileOrDot

Options:
--version Show version number [boolean]
-K, --layout Set layout engine (circo | dot | fdp | sfdp | neato | osage
| patchwork | twopi). By default, dot is used.
-T, --format Set output language to one of the supported formats (svg,
dot, json, dot_json, xdot_json, plain, plain-ext). By
default, svg is produced.
--version Show version number [boolean]
-K, --layout Set layout engine (circo | dot | fdp | sfdp | neato | osage | patchwo
rk | twopi). By default, dot is used.
-T, --format Set output language to one of the supported formats (svg | dot | json
| dot_json | xdot_json | plain | plain-ext). By default, svg is prod
uced.
-n, --neato-no-op Sets no-op flag in neato.
"-n 1" assumes neato nodes have already been positioned and
all nodes have a pos attribute giving the positions. It
then performs an optional adjustment to remove node-node
overlap, depending on the value of the overlap attribute,
computes the edge layouts, depending on the value of the
splines attribute, and emits the graph in the appropriate
format.
"-n 2" Use node positions as specified, with no adjustment
to remove node-node overlaps, and use any edge layouts
already specified by the pos attribute. neato computes an
edge layout for any edge that does not have a pos
attribute. As usual, edge layout is guided by the splines
attribute.
-y, --invert-y By default, the coordinate system used in generic output
formats, such as attributed dot, extended dot, plain and
plain-ext, is the standard cartesian system with the origin
in the lower left corner, and with increasing y coordinates
as points move from bottom to top. If the -y flag is used,
the coordinate system is inverted, so that increasing
values of y correspond to movement from top to bottom.
-h, --help Show help [boolean]
"-n 1" assumes neato nodes have already bee
n positioned and all nodes have a pos attribute giving the positions.
It then performs an optional adjustment to remove node-node overlap,
depending on the value of the overlap attribute, computes the edge l
ayouts, depending on the value of the splines attribute, and emits th
e graph in the appropriate format.
"-n 2" Use node positions as speci
fied, with no adjustment to remove node-node overlaps, and use any ed
ge layouts already specified by the pos attribute. neato computes an
edge layout for any edge that does not have a pos attribute. As usual
, edge layout is guided by the splines attribute.
-y, --invert-y By default, the coordinate system used in generic output formats, suc
h as attributed dot, extended dot, plain and plain-ext, is the standa
rd cartesian system with the origin in the lower left corner, and wit
h increasing y coordinates as points move from bottom to top. If the
-y flag is used, the coordinate system is inverted, so that increasin
g values of y correspond to movement from top to bottom.
-v Echo GraphViz library version
-h, --help Show help [boolean]

Examples:
dot-wasm -K neato -T xdot ./input.dot Execute NEATO layout and outputs XDOT
format.
dot-wasm -K neato -T xdot ./input.dot Execute NEATO layout and outputs XDOT format.
```

### GraphViz Hello World
Expand Down Expand Up @@ -515,6 +515,122 @@ A note on compressionLevel: The library supports regular compression levels fro

---

## Base91
_Similar to Base 64, but uses more characters resulting in smaller strings._

Base 91 WASM library, similar to Base 64 but uses more characters resulting in smaller strings, see [Base91](https://base91.sourceforge.net/) for more details.

### Base91 Hello World

```html
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Base91 WASM</title>
</head>

<body>
<div id="placeholder"></div>
<script type="module">
import { Base91 } from "./dist/index.es6.js";
//import { Base91 } from "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/index.es6.js";

const base91 = await Base91.load();
const data = new Uint8Array(Array.from({ length: 100 }, (_, i) => Math.random() * 100));
const encoded_data = await base91.encode(data);
const decoded_data = await base91.decode(encoded_data);
document.getElementById("placeholder").innerHTML = `\
<ul>
<li>Data Size (bytes): ${data.byteLength}</li>
<li>Endoded Size (bytes): ${encoded_data.length}</li>
<li>Decoded Size (bytes): ${decoded_data.byteLength}</li>
</ul>
<h4>Data: </h4>
<code>
${data}
</code>
<h4>Base 91: </h4>
<code id="base91">
</code>
<h4>Decoded: </h4>
<code>
${decoded_data}
</code>
`;
document.getElementById("base91").innerText = encoded_data;
</script>

</body>

</html>
```

### Base91 API

#### Interfaces

<a name="Options" href="#Base91Options">#</a> **Options** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")

Options structure for advanced loading.

```typescript
interface Options {
wasmFolder?: string;
wasmBinary?: ArrayBuffer;
}
```

* _wasmFolder_: An optional `string` specifying the location of wasm file.
* _wasmBinary_: An optional "pre-fetched" copy of the wasm binary as returned from `XHR` or `fetch`.

<a name="Base91" href="#Base91">#</a> **Base91** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")

Conceptual interface for TypeScript/JavaScript wrapper API

```typescript
interface Base91 {
static load(options?: Options): Promise<Base91>;
version(): string;

encode(data: Uint8Array): string;
decode(array: string): Uint8Array;
}
```

<a name="base91Load" href="#base91Load">#</a> **Base91.load**(_options_?: **Options**): **Promise\<Base91\>** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")

Loads and initializes the Base91 wasm library, returns a Promise to `Base91`:
```typescript
const base91 = await Base91.load();
...dostuff...
```
or
```typescript
Base91.load().then(base91 => {...dostuff...});
```

<a name="base91Version" href="#base91Version">#</a> **base91.version**(): **string** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")

* **_returns_**: The Base91 library Version.

<a name="base91Encode" href="#base91Encode">#</a> **base91.encode**(_data_: **Uint8Array**): **string** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")

* **_data_**: Raw data to encode.
* **_returns_**: Encoded string.

Encodes the raw data.

<a name="base91Decode" href="#base91Decode">#</a> **base91.decode**(_str_: **string**): **Uint8Array** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")

* **_str_**: String to decode.
* **_returns_**: Decoded data.

Decodes the raw data.

---

## Utility

Utility functions unrelated to any specific wasm APIs
Expand Down
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ADD_SUBDIRECTORY(base91)
ADD_SUBDIRECTORY(expat)
ADD_SUBDIRECTORY(graphviz)
ADD_SUBDIRECTORY(zstd)
43 changes: 43 additions & 0 deletions cpp/base91/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
PROJECT(base91lib)

find_package(unofficial-base91 CONFIG REQUIRED)

# See: https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
SET(EM_FLAGS
${EM_FLAGS}
"-s EXPORT_NAME='${CMAKE_PROJECT_NAME}'"
"-s EXPORTED_FUNCTIONS=\"[]\""
"-s EXPORTED_RUNTIME_METHODS=\"[]\""
"--post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js"
)
STRING(REPLACE ";" " " LINK_FLAGS "${EM_FLAGS}")

# Generate Glue from IDL file ---
ADD_CUSTOM_COMMAND(
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/main.idl
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.cpp
COMMAND python3 ${CMAKE_BINARY_DIR}/../emsdk/upstream/emscripten/tools/webidl_binder.py ${CMAKE_CURRENT_SOURCE_DIR}/main.idl ${CMAKE_CURRENT_BINARY_DIR}/main_glue
)
SET_PROPERTY(SOURCE main.cpp APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/main_glue.cpp)
# --- --- ---

INCLUDE_DIRECTORIES(
${VCPKG_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)

ADD_EXECUTABLE(base91lib
main.cpp
)

SET_TARGET_PROPERTIES(base91lib PROPERTIES LINK_FLAGS "${LINK_FLAGS} -s ENVIRONMENT=webview")

TARGET_LINK_LIBRARIES(base91lib
PRIVATE unofficial::base91::base91
)

INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/base91lib.wasm DESTINATION dist COMPONENT runtime)

IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/base91lib.wasm.map DESTINATION dist COMPONENT runtime)
ENDIF ()
Loading