Skip to content

Commit

Permalink
feat: Bump versions to latest
Browse files Browse the repository at this point in the history
Add version function to Graphviz and Expat
Clean up module loading and promises

Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Jul 12, 2021
1 parent b4a4cc2 commit b412b82
Show file tree
Hide file tree
Showing 32 changed files with 1,052 additions and 657 deletions.
12 changes: 5 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@
"configurations": [
{
"name": "index.html",
"type": "chrome",
"type": "pwa-msedge",
"request": "launch",
"url": "http://localhost:8000/index.html",
"runtimeArgs": [
"--disable-web-security"
],
"runtimeArgs": [],
"webRoot": "${workspaceRoot}"
},
{
"name": "helloworld.html",
"type": "chrome",
"type": "pwa-msedge",
"request": "launch",
"url": "file://${workspaceRoot}/helloworld.html",
"webRoot": "${workspaceRoot}"
},
{
"name": "test-chrome",
"type": "chrome",
"name": "test-browser",
"type": "pwa-msedge",
"request": "launch",
"url": "http://localhost:8000/test.html",
"webRoot": "${workspaceRoot}",
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This repository contains a collection of useful c++ libraries compiled to WASM f
* [expat](https://libexpat.github.io/) - v2.4.1

Built with:
* [emsdk](https://github.com/emscripten-core/emsdk) - v2.0.24
* [emsdk](https://github.com/emscripten-core/emsdk) - v2.0.25

## Quick GraphViz Demos
* https://raw.githack.com/hpcc-systems/hpcc-js-wasm/trunk/index.html
Expand Down Expand Up @@ -130,6 +130,10 @@ The _GraphViz_ library comes in **two** flavours

#### GraphViz API

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

Returns the Graphviz Version.

<a name="layout" href="#layout">#</a> **layout**(_dotSource_[, _outputFormat_][, _layoutEngine_][, _ext_]) · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/graphviz.ts "Source")

Performs layout for the supplied _dotSource_, see [The DOT Language](https://graphviz.gitlab.io/_pages/doc/info/lang.html) for specification.
Expand Down Expand Up @@ -268,6 +272,10 @@ Expat WASM library, provides a simplified wrapper around the Expat XML Parser li

#### Expat API

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

Returns the Expat Version.

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

* **_xml_**: XML String.
Expand Down
5 changes: 3 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ PROJECT(cpp)

SET(CMAKE_INSTALL_PREFIX "..")

SET(EXPATSRC_DIRS "${CMAKE_SOURCE_DIR}/../src-expat")
SET(GRAPHVIZSRC_DIRS "${CMAKE_SOURCE_DIR}/../src-graphviz")
SET(EMSDK_DIR "${CMAKE_SOURCE_DIR}/../emsdk")
SET(EXPAT_DIR "${CMAKE_SOURCE_DIR}/../src-expat/expat")
SET(GRAPHVIZ_DIR "${CMAKE_SOURCE_DIR}/../src-graphviz")

ADD_SUBDIRECTORY(expat)
ADD_SUBDIRECTORY(graphviz)
2 changes: 1 addition & 1 deletion cpp/expat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(CMAKE_CXX_STANDARD 17)

SET(EXPAT_LIB_DIR "${EXPATSRC_DIRS}/expat/lib")
SET(EXPAT_LIB_DIR "${EXPAT_DIR}/lib")

ADD_DEFINITIONS(-DXML_POOR_ENTROPY)

Expand Down
1 change: 1 addition & 0 deletions cpp/expat/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../src-expat/expat/expat_config.h"
2 changes: 1 addition & 1 deletion cpp/expat/expatlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROJECT(expatlib)

SET(EM_FLAGS "-s WASM=1 -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s EXPORT_NAME='${CMAKE_PROJECT_NAME}' -s EXPORTED_FUNCTIONS=\"['_malloc']\" --post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js")
SET(EM_FLAGS "-s WASM=1 -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=2 -s EXPORT_NAME='${CMAKE_PROJECT_NAME}' -s EXPORTED_FUNCTIONS=\"['_malloc']\" --post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js")

# Generate Glue from IDL file ---
ADD_CUSTOM_COMMAND(
Expand Down
6 changes: 6 additions & 0 deletions cpp/expat/expatlib/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "../config.h"
#include "stack_parser.h"

#include <string>
Expand All @@ -13,6 +14,11 @@ class CExpat : public CExpatImpl<CExpat>
std::string m_content;

public:
static const char *version()
{
return PACKAGE_VERSION;
}

CExpat()
{
}
Expand Down
5 changes: 3 additions & 2 deletions cpp/expat/expatlib/main.idl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface CExpat
{
void CExpat();
[Const] static DOMString version();
boolean create();
void destroy();
boolean parse([Const] DOMString xml);
Expand All @@ -12,8 +13,8 @@ interface CExpat
void characterData();
};

[JSImplementation = "CExpat"]
interface CExpatJS {
[JSImplementation = "CExpat"] interface CExpatJS
{
void CExpatJS();
void startElement();
void endElement();
Expand Down
6 changes: 3 additions & 3 deletions cpp/graphviz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PROJECT(graphlayout)

set(TOP_SOURCE_DIR "${GRAPHVIZSRC_DIRS}")
SET(GRAPHVIZ_LIB_DIR "${GRAPHVIZSRC_DIRS}/lib")
SET(GRAPHVIZ_BIN_DIR "${GRAPHVIZSRC_DIRS}/build/lib")
SET(GRAPHVIZ_LIB_DIR "${GRAPHVIZ_DIR}/lib")
SET(GRAPHVIZ_PLUGIN_DIR "${GRAPHVIZ_DIR}/plugin")
SET(GRAPHVIZ_BUILD_DIR "${GRAPHVIZ_DIR}/build")

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
2 changes: 1 addition & 1 deletion cpp/graphviz/config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <../../src-graphviz/config.h>
#include "../../src-graphviz/config.h"
#undef ENABLE_LTDL
#undef HAVE_LIBZ
#undef HAVE_GTS
3 changes: 1 addition & 2 deletions cpp/graphviz/graphvizlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROJECT(graphvizlib)

SET(EM_FLAGS "-s WASM=1 -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s EXPORT_NAME='${CMAKE_PROJECT_NAME}' --post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js")
SET(EM_FLAGS "-s WASM=1 -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=2 -s EXPORT_NAME='${CMAKE_PROJECT_NAME}' --post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js")

# Generate Glue from IDL file ---
ADD_CUSTOM_COMMAND(
Expand All @@ -13,7 +13,6 @@ SET_PROPERTY(SOURCE main.cpp APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINA

SET(SRCS
main.cpp
fs.cpp
)

INCLUDE_DIRECTORIES(
Expand Down
15 changes: 0 additions & 15 deletions cpp/graphviz/graphvizlib/fs.cpp

This file was deleted.

83 changes: 43 additions & 40 deletions cpp/graphviz/graphvizlib/main.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
#include "main.hpp"

#include "../config.h"
#include <gvc.h>
#include <globals.h>
#include <string>

#include <emscripten.h>

extern gvplugin_library_t gvplugin_core_LTX_library;
extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
extern gvplugin_library_t gvplugin_neato_layout_LTX_library;

std::string errorMessage = "";
char lastErrorStr[1024];

int vizErrorf(char *buf)
{
errorMessage = buf;
strncpy(lastErrorStr, buf, sizeof(lastErrorStr) - 1);
return 0;
}

const char *Main::layout(const char *src, const char *format, const char *engine)
const char *Graphviz::version()
{
errorMessage = "";
char *result = NULL;
GVC_t *context;
Agraph_t *graph;
unsigned int length;
return PACKAGE_VERSION;
}

const char *Graphviz::lastError()
{
return lastErrorStr;
}

int origYInvert = Y_invert;
int origNop = Nop;

Graphviz::Graphviz(bool yInvert, int nop)
{
Y_invert = yInvert == true ? 1 : origYInvert;
Nop = nop > 0 ? nop : origNop;
}

Graphviz::~Graphviz()
{
}

const char *Graphviz::layout(const char *src, const char *format, const char *engine)
{
lastErrorStr[0] = '\0';

context = gvContext();
GVC_t *context = gvContext();
gvAddLibrary(context, &gvplugin_core_LTX_library);
gvAddLibrary(context, &gvplugin_dot_layout_LTX_library);
gvAddLibrary(context, &gvplugin_neato_layout_LTX_library);
Expand All @@ -34,6 +55,9 @@ const char *Main::layout(const char *src, const char *format, const char *engine

agreadline(1);

Agraph_t *graph;
char *result = NULL;
unsigned int length;
while ((graph = agmemread(src)))
{
if (result == NULL)
Expand All @@ -51,38 +75,17 @@ const char *Main::layout(const char *src, const char *format, const char *engine
return result;
}

const char *Main::lastError()
{
return errorMessage.c_str();
}

void Main::setYInvert(int yInvert)
{
Y_invert = yInvert;
}

void Main::setNop(int nop)
void Graphviz::createFile(const char *path, const char *data)
{
if (nop != 0)
Nop = nop;
}

// Patch for invalid osage function ---
// https://gitlab.com/graphviz/graphviz/issues/1544
#include "types.h"
#include "SparseMatrix.h"
extern "C"
{
void remove_overlap(int dim, SparseMatrix A, double *x, double *label_sizes, int ntry, double initial_scaling, int edge_labeling_scheme, int n_constr_nodes, int *constr_nodes, SparseMatrix A_constr, int do_shrinking, int *flag)
{
static int once;

if (once == 0)
EM_ASM(
{
once = 1;
agerr(AGERR, "remove_overlap: Graphviz not built with triangulation library\n");
}
}
var path = UTF8ToString($0);
var data = UTF8ToString($1);

FS.createPath("/", PATH.dirname(path));
FS.writeFile(PATH.join("/", path), data);
},
path, data);
}

// Include JS Glue ---
Expand Down
13 changes: 8 additions & 5 deletions cpp/graphviz/graphvizlib/main.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
class Main
class Graphviz
{
protected:
public:
static const char *layout(const char *dot, const char *format, const char *engine);
static const char *version();
static const char *lastError();
static void createFile(const char *path, const char *data);
static void setYInvert(int yInvert);
static void setNop(int nop);

Graphviz(bool yInvert = false, int nop = 0);
~Graphviz();
const char *layout(const char *dot, const char *format, const char *engine);
void createFile(const char *path, const char *data);
};
10 changes: 5 additions & 5 deletions cpp/graphviz/graphvizlib/main.idl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
interface Main {
[Const] static DOMString layout([Const] DOMString dot, [Const] DOMString format, [Const] DOMString engine);
interface Graphviz
{
void Graphviz(long yInvert, long nop);
[Const] static DOMString version();
[Const] static DOMString lastError();
[Const] DOMString layout([Const] DOMString dot, [Const] DOMString format, [Const] DOMString engine);
void createFile([Const] DOMString file, [Const] DOMString data);
void setYInvert(long yInvert);
void setNop(long nop);
};

6 changes: 3 additions & 3 deletions cpp/graphviz/lib/cgraph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ add_library(cgraph STATIC
${GRAPHVIZ_LIB_DIR}/cgraph/write.c

# Generated files
${GRAPHVIZSRC_DIRS}/build/lib/cgraph/grammar.c
${GRAPHVIZSRC_DIRS}/build/lib/cgraph/scan.c
${GRAPHVIZ_BUILD_DIR}/lib/cgraph/grammar.c
${GRAPHVIZ_BUILD_DIR}/lib/cgraph/scan.c
)

target_include_directories(cgraph PRIVATE
${GRAPHVIZ_LIB_DIR}
${GRAPHVIZ_LIB_DIR}/cdt
${GRAPHVIZ_LIB_DIR}/cgraph
${GRAPHVIZSRC_DIRS}/build/lib/cgraph
${GRAPHVIZ_BUILD_DIR}/lib/cgraph
)

target_link_libraries(cgraph cdt)
Expand Down
8 changes: 4 additions & 4 deletions cpp/graphviz/lib/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_library(common STATIC
${GRAPHVIZ_LIB_DIR}/common/arith.h
${GRAPHVIZ_LIB_DIR}/common/color.h
${GRAPHVIZ_LIB_DIR}/common/colorprocs.h
${GRAPHVIZSRC_DIRS}/build/lib/common/common/colortbl.h
${GRAPHVIZ_BUILD_DIR}/lib/common/common/colortbl.h
${GRAPHVIZ_LIB_DIR}/common/const.h
${GRAPHVIZ_LIB_DIR}/common/entities.h
${GRAPHVIZ_LIB_DIR}/common/geom.h
Expand Down Expand Up @@ -53,19 +53,19 @@ add_library(common STATIC
${GRAPHVIZ_LIB_DIR}/common/utils.c

# Generated files
${GRAPHVIZSRC_DIRS}/build/lib/common/htmlparse.c
${GRAPHVIZ_BUILD_DIR}/lib/common/htmlparse.c
)

target_include_directories(common PRIVATE
${GRAPHVIZ_LIB_DIR}
${GRAPHVIZ_LIB_DIR}/common
${GRAPHVIZ_BIN_DIR}/common
${GRAPHVIZ_BUILD_DIR}/lib/common
${GRAPHVIZ_LIB_DIR}/cdt
${GRAPHVIZ_LIB_DIR}/cgraph
${GRAPHVIZ_LIB_DIR}/gvc
${GRAPHVIZ_LIB_DIR}/pack
${GRAPHVIZ_LIB_DIR}/pathplan
${GRAPHVIZ_LIB_DIR}/xdot
${EXPATSRC_DIRS}/expat/lib
${EXPAT_DIR}/lib
)

3 changes: 2 additions & 1 deletion cpp/graphviz/lib/gvc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ add_library(gvc STATIC
target_include_directories(gvc PRIVATE
${GRAPHVIZ_LIB_DIR}
${GRAPHVIZ_LIB_DIR}/gvc
${TOP_SOURCE_DIR}
${GRAPHVIZ_DIR}
${GRAPHVIZ_LIB_DIR}/ast
${GRAPHVIZ_LIB_DIR}/cdt
${GRAPHVIZ_LIB_DIR}/cgraph
Expand All @@ -46,6 +46,7 @@ target_link_libraries(gvc
cdt
cgraph
label
pack
pathplan
xdot
expat
Expand Down
Loading

0 comments on commit b412b82

Please sign in to comment.