Skip to content

Commit

Permalink
update mymindstorm/setup-emsdk, CPM.cmake and yarn dependencies (#13)
Browse files Browse the repository at this point in the history
* update CPM.cmake and dependencies

* also cache yarn dependencies

* update cache in all workflows

* update mymindstorm/setup-emsdk

* update note in readme

* update publish workflow
  • Loading branch information
TheLartians committed Jan 20, 2021
1 parent 205733a commit a9f327b
Show file tree
Hide file tree
Showing 10 changed files with 818 additions and 768 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- uses: mymindstorm/setup-emsdk@v6
- uses: actions/cache@v2
with:
path: |
**/cpm_modules
**/node_modules
key: cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake', '**/yarn.lock') }}

- uses: mymindstorm/setup-emsdk@v7
with:
version: 1.39.20

- name: install
env:
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules
run: yarn install

- name: test
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- uses: mymindstorm/setup-emsdk@v6
- uses: actions/cache@v2
with:
path: |
**/cpm_modules
**/node_modules
key: cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake', '**/yarn.lock') }}

- uses: mymindstorm/setup-emsdk@v7
with:
version: 1.39.20

- name: install
env:
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules
run: yarn install

- name: test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/build
/node_modules
/cpm_modules
/dist
/.vscode
/source/WasmModule.d.ts
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ This will create the files `source/WasmModule.js` and `source/WasmModule.d.ts` f
To build your code as wasm, add it as a CPM.cmake dependency in the [CMakeLists.txt](wasm/CMakeLists.txt) file and define the bindings in the [wasmGlue.cpp](wasm/source/wasmGlue.cpp) source file.
To update the wasm and TypeScript declarations, you can run `npm run build:wasm`.

Note: due to what seems to be a [compiler bug](https://github.com/emscripten-core/emscripten/issues/12238), some emsdk versions seem to crash the compiler.
The most recently tested working version is `1.39.20`.


### Run tests

The following command will build and run the test suite.
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"description": "A starter project for wasm node modules",
"main": "dist/index.js",
"author": "Lars Melchior",
"license": "Unlicence",
"license": "Unlicense",
"repository": {
"type": "git",
"url": "https://github.com/TheLartians/modern-wasm-starter.git"
},
"devDependencies": {
"@types/jest": "^25.2.1",
"jest": "^26.0.1",
"prettier": "^2.0.5",
"ts-jest": "^25.5.1",
"typescript": "^3.8.3"
"@types/jest": "^26.0.20",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
},
"files": [
"dist"
Expand Down
21 changes: 5 additions & 16 deletions wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,10 @@ project(TypeScriptXX

set(CMAKE_CXX_FLAGS_RELEASE "-Oz -g0")

# ---- Fetch CPM ----

set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM.cmake")
set(CPM_DOWNLOAD_VERSION 0.25.1)

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION} AND CPM_VERSION STREQUAL CPM_DOWNLOAD_VERSION))
message(STATUS "Downloading CPM.cmake")
file(DOWNLOAD https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
endif()

# ---- Dependencies ----
# Add C++ dependencies through CPM.cmake.
# See https://github.com/TheLartians/CPM.cmake for more info.

include(${CPM_DOWNLOAD_LOCATION})
include(cmake/CPM.cmake)

# exact package versions are defined in package-lock.cmake
# this helps us specify exact versions of transitive dependencies
Expand All @@ -33,7 +22,7 @@ CPMUsePackageLock(package-lock.cmake)
CPMAddPackage(
NAME Greeter
GITHUB_REPOSITORY TheLartians/ModernCppStarter
VERSION 0.10
VERSION 0.16.1
)

# EmGlue is used to create the TypeScript declarations and the JavaScript bindings
Expand All @@ -47,16 +36,16 @@ CPMAddPackage(
CPMAddPackage(
NAME Format.cmake
GITHUB_REPOSITORY TheLartians/Format.cmake
VERSION 1.4
VERSION 1.6
)

# ---- Create wams glue library ----

add_library(wasmGlue source/wasmGlue.cpp)
set_target_properties(wasmGlue PROPERTIES CXX_STANDARD 17)

# link dependencies, replace `Greeter` with your library
target_link_libraries(wasmGlue PUBLIC Glue Greeter)
# link dependencies, replace `Greeter::Greeter` with your library
target_link_libraries(wasmGlue PUBLIC Glue Greeter::Greeter)

# ---- Create main library ----

Expand Down
19 changes: 19 additions & 0 deletions wasm/cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(CPM_DOWNLOAD_VERSION 0.28.0)

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()

include(${CPM_DOWNLOAD_LOCATION})
20 changes: 10 additions & 10 deletions wasm/package-lock.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# CPM Package Lock
# This file should be committed to version control

# Greeter
CPMDeclarePackage(Greeter "NAME;Greeter;GITHUB_REPOSITORY;TheLartians/ModernCppStarter;VERSION;0.10")
# PackageProject.cmake
CPMDeclarePackage(PackageProject.cmake "NAME;PackageProject.cmake;GITHUB_REPOSITORY;TheLartians/PackageProject.cmake;VERSION;1.2")
# EmGlue
CPMDeclarePackage(EmGlue "NAME;EmGlue;VERSION;0.6.1;GITHUB_REPOSITORY;TheLartians/EmGlue")
# Glue
CPMDeclarePackage(Glue "NAME;Glue;GITHUB_REPOSITORY;TheLartians/Glue;VERSION;1.5")
CPMDeclarePackage(PackageProject.cmake "NAME;PackageProject.cmake;GITHUB_REPOSITORY;TheLartians/PackageProject.cmake;VERSION;1.4")
# Greeter
CPMDeclarePackage(Greeter "NAME;Greeter;GITHUB_REPOSITORY;TheLartians/ModernCppStarter;VERSION;0.16.1")
# EasyIterator
CPMDeclarePackage(EasyIterator "NAME;EasyIterator;VERSION;1.4;GIT_REPOSITORY;https://github.com/TheLartians/EasyIterator.git")
# Revisited
CPMDeclarePackage(Revisited "NAME;Revisited;VERSION;2.3.1;GITHUB_REPOSITORY;TheLartians/Revisited")
# StaticTypeInfo
CPMDeclarePackage(StaticTypeInfo "NAME;StaticTypeInfo;VERSION;1.3.1;GIT_REPOSITORY;https://github.com/TheLartians/StaticTypeInfo")
# Revisited
CPMDeclarePackage(Revisited "NAME;Revisited;VERSION;2.3.1;GITHUB_REPOSITORY;TheLartians/Revisited")
# Glue
CPMDeclarePackage(Glue "NAME;Glue;GITHUB_REPOSITORY;TheLartians/Glue;VERSION;1.5")
# EmGlue
CPMDeclarePackage(EmGlue "NAME;EmGlue;VERSION;0.6.1;GITHUB_REPOSITORY;TheLartians/EmGlue")
# Format.cmake
CPMDeclarePackage(Format.cmake "NAME;Format.cmake;GITHUB_REPOSITORY;TheLartians/Format.cmake;VERSION;1.4")
CPMDeclarePackage(Format.cmake "NAME;Format.cmake;GITHUB_REPOSITORY;TheLartians/Format.cmake;VERSION;1.6")
2 changes: 1 addition & 1 deletion wasm/source/wasmGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <glue/class.h>
#include <glue/enum.h>
#include <greeter.h>
#include <greeter/greeter.h>

glue::MapValue wasmGlue() {
using namespace greeter;
Expand Down
Loading

0 comments on commit a9f327b

Please sign in to comment.