Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Switch from makefiles to cmake
  • Loading branch information
ianthomas23 committed Jan 8, 2026
commit ec1eeb4856865c51e2a33ae0a6b11c964aa0202b
16 changes: 14 additions & 2 deletions wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
serve/cockle/
serve/lite/
CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
cockle-config.json
cockle_wasm_env/
node_modules/
package-lock.json
.jupyterlite.doit.db

recipe/em-forge-recipes/
serve/*/
test/assets/*/
test/lib/
16 changes: 16 additions & 0 deletions wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.28)
project(git2cpp-wasm)

add_subdirectory(recipe)
add_subdirectory(cockle-deploy)
add_subdirectory(lite-deploy)
add_subdirectory(test)

# Build everything (package, cockle and lite deployments, tests).
add_custom_target(build ALL DEPENDS build-recipe build-cockle build-lite build-test)

# Rebuild after change in C++ code.
add_custom_target(rebuild DEPENDS rebuild-recipe rebuild-cockle rebuild-lite rebuild-test)

# Serve both cockle and JupyterLite deployments.
add_custom_target(serve COMMAND npx static-handler --cors --coop --coep --corp serve)
28 changes: 0 additions & 28 deletions wasm/Makefile

This file was deleted.

14 changes: 12 additions & 2 deletions wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It works on Linux and macOS but not Windows.

There are 5 sub-directories:

- `build`: build local `git2cpp` source code into an Emscripten-forge package.
- `recipe`: build local `git2cpp` source code into an Emscripten-forge package.
- `cockle-deploy`: create a `cockle` deployment in the `serve` directory.
- `lite-deploy`: create a JupyterLite `terminal` deployment in the `serve` directory.
- `serve`: where the two deployments are served from.
Expand All @@ -29,9 +29,13 @@ micromamba activate git2cpp-wasm
Then to build the WebAssembly package, both deployments and the testing resources use:

```bash
cmake .
make
```

The built emscripten-forge package will be file named something like `git2cpp-0.0.5-h7223423_1.tar.bz2`
in the directory `recipe/em-force-recipes/output/emscripten-wasm32`.

The local deployments in the `serve` directory can be manually checked using:

```bash
Expand All @@ -58,7 +62,13 @@ make test
```

This runs (some of) the tests in the top-level `test` directory with various monkey patching so that
`git2cpp` commands are executed in the browser.
`git2cpp` commands are executed in the browser. If there are problems running the tests then ensure
you have the latest `playwright` browser installed:


```bash
playwright install chromium
```

## Rebuild

Expand Down
1 change: 0 additions & 1 deletion wasm/build/.gitignore

This file was deleted.

31 changes: 0 additions & 31 deletions wasm/build/Makefile

This file was deleted.

3 changes: 0 additions & 3 deletions wasm/cockle-deploy/.gitignore

This file was deleted.

21 changes: 21 additions & 0 deletions wasm/cockle-deploy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.28)
project(git2cpp-wasm-cockle-deploy)

include("../common.cmake")

set(SERVE_DIR "../serve/cockle")

add_custom_target(build-cockle
DEPENDS build-recipe
COMMAND npm install
COMMAND COCKLE_WASM_EXTRA_CHANNEL=${BUILT_PACKAGE_DIR} npm run build
BYPRODUCTS cockle_wasm_env node_modules ${SERVE_DIR}
)

add_custom_target(rebuild-cockle
DEPENDS rebuild-recipe clean-env-cockle build-cockle
)

add_custom_target(clean-env-cockle
COMMAND ${CMAKE_COMMAND} -E remove_directory cockle_wasm_env
)
16 changes: 0 additions & 16 deletions wasm/cockle-deploy/Makefile

This file was deleted.

8 changes: 8 additions & 0 deletions wasm/common.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Emscripten-forge recipes directory relative to 'recipe' directory
set(EM_FORGE_RECIPES_DIR "em-forge-recipes")

# Output directory for built emscripten-forge packages relative to EM_FORGE_RECIPES_DIR
set(BUILT_PACKAGE_SUBDIR "output")

# Output directory for built emscripten-forge packages relative to subdirectories of this directory
set(BUILT_PACKAGE_DIR "../recipe/${EM_FORGE_RECIPES_DIR}/${BUILT_PACKAGE_SUBDIR}")
5 changes: 0 additions & 5 deletions wasm/common.mk

This file was deleted.

4 changes: 0 additions & 4 deletions wasm/lite-deploy/.gitignore

This file was deleted.

21 changes: 21 additions & 0 deletions wasm/lite-deploy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.28)
project(git2cpp-wasm-lite-deploy)

include("../common.cmake")

set(SERVE_DIR "../serve/lite")

add_custom_target(build-lite
DEPENDS build-recipe
COMMAND jupyter lite --version
COMMAND COCKLE_WASM_EXTRA_CHANNEL=${BUILT_PACKAGE_DIR} jupyter lite build --output-dir ${SERVE_DIR}
BYPRODUCTS cockle-config.json .cockle_temp/ .jupyterlite.doit.db cockle_wasm_env/ ${SERVE_DIR}
)

add_custom_target(rebuild-lite
DEPENDS rebuild-recipe clean-env-lite build-lite
)

add_custom_target(clean-env-lite
COMMAND ${CMAKE_COMMAND} -E remove_directory cockle_wasm_env
)
15 changes: 0 additions & 15 deletions wasm/lite-deploy/Makefile

This file was deleted.

43 changes: 43 additions & 0 deletions wasm/recipe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.28)
project(git2cpp-wasm-recipe)

include("../common.cmake")

set(EM_FORGE_RECIPES_REPO "https://github.com/emscripten-forge/recipes")
set(GIT2CPP_RECIPE_DIR "recipes/recipes_emscripten/git2cpp")
set(RATTLER_ARGS "--package-format tar-bz2 --target-platform emscripten-wasm32 -c https://repo.prefix.dev/emscripten-forge-dev -c microsoft -c conda-forge")

# Only want the git2cpp recipe from emscripten-forge/recipes repo, not the whole repo.
# Note removing the .git directory otherwise `git clean -fxd` will not remove the directory.
add_custom_command(
OUTPUT ${EM_FORGE_RECIPES_DIR}
COMMAND git clone --no-checkout ${EM_FORGE_RECIPES_REPO} --depth 1 ${EM_FORGE_RECIPES_DIR}
COMMAND cd ${EM_FORGE_RECIPES_DIR} && git sparse-checkout init
COMMAND cd ${EM_FORGE_RECIPES_DIR} && git sparse-checkout set ${GIT2CPP_RECIPE_DIR}
COMMAND cd ${EM_FORGE_RECIPES_DIR} && git checkout main
COMMAND ${CMAKE_COMMAND} -E remove_directory ${EM_FORGE_RECIPES_DIR}/.git
)

add_custom_target(modify-recipe
DEPENDS ${EM_FORGE_RECIPES_DIR}
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/modify-recipe.py ${GIT2CPP_RECIPE_DIR}
WORKING_DIRECTORY ${EM_FORGE_RECIPES_DIR}
)

add_custom_command(
OUTPUT ${EM_FORGE_RECIPES_DIR}/${BUILT_PACKAGE_SUBDIR}
DEPENDS modify-recipe
COMMAND bash -c "rattler-build build ${RATTLER_ARGS} --recipe ${GIT2CPP_RECIPE_DIR}"
WORKING_DIRECTORY ${EM_FORGE_RECIPES_DIR}
)

add_custom_target(build-recipe
DEPENDS ${EM_FORGE_RECIPES_DIR}/${BUILT_PACKAGE_SUBDIR}
WORKING_DIRECTORY ${EM_FORGE_RECIPES_DIR}
)

add_custom_target(rebuild-recipe DEPENDS clean-output-dir build-recipe)

add_custom_target(clean-output-dir
COMMAND ${CMAKE_COMMAND} -E remove_directory ${EM_FORGE_RECIPES_DIR}/${BUILT_PACKAGE_SUBDIR}
)
File renamed without changes.
5 changes: 0 additions & 5 deletions wasm/test/.gitignore

This file was deleted.

25 changes: 25 additions & 0 deletions wasm/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.28)
project(git2cpp-wasm-test)

include("../common.cmake")

add_custom_target(build-test
DEPENDS build-recipe
COMMAND npm install
COMMAND COCKLE_WASM_EXTRA_CHANNEL=${BUILT_PACKAGE_DIR} npm run build
BYPRODUCTS cockle_wasm_env lib node_modules
)

add_custom_target(rebuild-test
DEPENDS rebuild-recipe clean-env-test build-test
)

add_custom_target(test
# A pytest fixture ensures that `npm run serve` runs for the duration of the tests.
COMMAND GIT2CPP_TEST_WASM=1 pytest -v -rP test_git.py
WORKING_DIRECTORY ../../test
)

add_custom_target(clean-env-test
COMMAND ${CMAKE_COMMAND} -E remove_directory cockle_wasm_env
)
20 changes: 0 additions & 20 deletions wasm/test/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions wasm/wasm-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
- python
- pyyaml
# To build emscripten-forge recipe
- cmake
- micromamba
- rattler-build
# For JupyterLite deployment
Expand Down