Skip to content

Commit

Permalink
Update to the latest version of the Emscripten toolchain. (#88)
Browse files Browse the repository at this point in the history
This involves some changes to the embind code to deal with emscripten's new
lifetime specifications, and to (re)export the Module internals that we need on
the JS side. We also fix some of the FetchContent calls so that dependencies
are resolved in their correct order.
  • Loading branch information
LTLA authored Oct 1, 2024
1 parent 6d23ede commit bb498e0
Show file tree
Hide file tree
Showing 35 changed files with 248 additions and 255 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ target_link_options(scran_wasm PRIVATE
-pthread
-sPTHREAD_POOL_SIZE=Module.scran_custom_nthreads
-sEXPORTED_FUNCTIONS=_malloc,_free
-sEXPORTED_RUNTIME_METHODS=wasmMemory,PThread
)

set_target_properties(scran_wasm PROPERTIES OUTPUT_NAME scran)
Expand All @@ -96,13 +97,6 @@ if (COMPILE_NODE)
-sENVIRONMENT=node
-sNODERAWFS=1
)

add_custom_command(TARGET scran_wasm POST_BUILD
COMMAND cat ../misc/preamble.js scran.worker.js > tmp.js
COMMAND mv tmp.js scran.worker.js
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Adding ES6 preamble for Node"
)
else ()
target_link_options(scran_wasm PRIVATE
-sENVIRONMENT=web,worker
Expand Down
29 changes: 14 additions & 15 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,99 +21,98 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/tatami-inc/tatami
GIT_TAG d6cb42539e434efce7fd24cd5abcbb1c006f74f3
)
FetchContent_MakeAvailable(tatami)

FetchContent_Declare(
tatami_layered
GIT_REPOSITORY https://github.com/tatami-inc/tatami_layered
GIT_TAG e550a305ab17461970b78bf97579cc8308b03fd5
)
FetchContent_MakeAvailable(tatami_layered)

FetchContent_Declare(
tatami_mtx
GIT_REPOSITORY https://github.com/tatami-inc/tatami_mtx
GIT_TAG bc8f647dae4ada6480ee8c785fc4663d5bbf57ca
)
FetchContent_MakeAvailable(tatami_mtx)

FetchContent_Declare(
tatami_hdf5
GIT_REPOSITORY https://github.com/tatami-inc/tatami_hdf5
GIT_TAG 20ec1fb64e0419907d3094827b5d9134854a0119
)
FetchContent_MakeAvailable(tatami_hdf5)

## Prebuilt static libraries ###
FetchContent_Declare(
igraph
URL https://github.com/kanaverse/igraph-wasm/releases/download/v0.2.1-pthreads_3.1.43/igraph-0.10.6-wasm.tar.gz # need the thread-aware version.
URL_HASH SHA256=a40595001e0b39ef715f4a84bb83f3bb668ee8eed3ac55bd206212d45d7c53f1
)
FetchContent_MakeAvailable(igraph)

FetchContent_Declare(
h5wasm
URL https://github.com/kanaverse/libhdf5-wasm/releases/download/v0.3.0_3.1.43/libhdf5-1_12_2-wasm.tar.gz
URL_HASH SHA256=b2e58b102fe98326c77f1a160025c47a062c1a205818568680d5f5ed78df801c
)
FetchContent_MakeAvailable(h5wasm)

## Other stuff ###
FetchContent_Declare(
irlba
GIT_REPOSITORY https://github.com/LTLA/CppIrlba
GIT_TAG 15d6399fc2c9c2ed4755fa0baef373c086fdedd1
)
FetchContent_MakeAvailable(irlba)

FetchContent_Declare(
umappp
GIT_REPOSITORY https://github.com/LTLA/umappp
GIT_TAG f2928b3018e9dc374fbe4553769f899e575e2f14
)
FetchContent_MakeAvailable(umappp)

FetchContent_Declare(
scran
GIT_REPOSITORY https://github.com/LTLA/libscran
GIT_TAG 8659e9c76bd7656b1d75051f26eb5aa08c935d9c
)
FetchContent_MakeAvailable(scran)

FetchContent_Declare(
kmeans
GIT_REPOSITORY https://github.com/LTLA/CppKmeans
GIT_TAG 4c5aca44bffd8ed7d7243b2451105b572028e9d4
)
FetchContent_MakeAvailable(kmeans)

FetchContent_Declare(
mnncorrect
GIT_REPOSITORY https://github.com/LTLA/CppMnnCorrect
GIT_TAG 5ba5c790f01b3a676420892151791786dfb0a8d6
)
FetchContent_MakeAvailable(mnncorrect)

FetchContent_Declare(
qdtsne
GIT_REPOSITORY https://github.com/LTLA/qdtsne
GIT_TAG 72c81a00eda97cae2011abe06acce4525ecdd82a
)
FetchContent_MakeAvailable(qdtsne)

FetchContent_Declare(
singlepp
GIT_REPOSITORY https://github.com/LTLA/singlepp
GIT_TAG 1d9869c3f050521a12b3151c89bc41906bf093e0
)
FetchContent_MakeAvailable(singlepp)

FetchContent_Declare(
rds2cpp
GIT_REPOSITORY https://github.com/LTLA/rds2cpp
GIT_TAG 58755b4bce01734f33fba12494f68c5aa6604a69
)
FetchContent_MakeAvailable(rds2cpp)


FetchContent_MakeAvailable(tatami)
FetchContent_MakeAvailable(tatami_layered)
FetchContent_MakeAvailable(tatami_mtx)
FetchContent_MakeAvailable(tatami_hdf5)
FetchContent_MakeAvailable(igraph)
FetchContent_MakeAvailable(h5wasm)
FetchContent_MakeAvailable(irlba)
FetchContent_MakeAvailable(umappp)
FetchContent_MakeAvailable(scran)
FetchContent_MakeAvailable(kmeans)
FetchContent_MakeAvailable(mnncorrect)
FetchContent_MakeAvailable(qdtsne)
FetchContent_MakeAvailable(singlepp)
FetchContent_MakeAvailable(rds2cpp)
14 changes: 7 additions & 7 deletions src/NeighborIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ NeighborResults find_nearest_neighbors(const NeighborIndex& index, int k, int nt
}

EMSCRIPTEN_BINDINGS(build_neighbor_index) {
emscripten::function("find_nearest_neighbors", &find_nearest_neighbors);
emscripten::function("find_nearest_neighbors", &find_nearest_neighbors, emscripten::return_value_policy::take_ownership());

emscripten::function("build_neighbor_index", &build_neighbor_index);
emscripten::function("build_neighbor_index", &build_neighbor_index, emscripten::return_value_policy::take_ownership());

emscripten::class_<NeighborIndex>("NeighborIndex")
.function("num_obs", &NeighborIndex::num_obs)
.function("num_dim", &NeighborIndex::num_dim);
.function("num_obs", &NeighborIndex::num_obs, emscripten::return_value_policy::take_ownership())
.function("num_dim", &NeighborIndex::num_dim, emscripten::return_value_policy::take_ownership());

emscripten::class_<NeighborResults>("NeighborResults")
.constructor<size_t, uintptr_t, uintptr_t, uintptr_t>()
.function("num_obs", &NeighborResults::num_obs)
.function("size", &NeighborResults::size)
.function("serialize", &NeighborResults::serialize);
.function("num_obs", &NeighborResults::num_obs, emscripten::return_value_policy::take_ownership())
.function("size", &NeighborResults::size, emscripten::return_value_policy::take_ownership())
.function("serialize", &NeighborResults::serialize, emscripten::return_value_policy::take_ownership());
}
14 changes: 7 additions & 7 deletions src/NumericMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ NumericMatrix NumericMatrix::clone() const {

EMSCRIPTEN_BINDINGS(NumericMatrix) {
emscripten::class_<NumericMatrix>("NumericMatrix")
.constructor<int, int, uintptr_t, bool, bool>()
.function("nrow", &NumericMatrix::nrow)
.function("ncol", &NumericMatrix::ncol)
.function("row", &NumericMatrix::row)
.function("column", &NumericMatrix::column)
.function("sparse", &NumericMatrix::sparse)
.function("clone", &NumericMatrix::clone)
.constructor<int, int, uintptr_t, bool, bool>(emscripten::return_value_policy::take_ownership())
.function("nrow", &NumericMatrix::nrow, emscripten::return_value_policy::take_ownership())
.function("ncol", &NumericMatrix::ncol, emscripten::return_value_policy::take_ownership())
.function("row", &NumericMatrix::row, emscripten::return_value_policy::take_ownership())
.function("column", &NumericMatrix::column, emscripten::return_value_policy::take_ownership())
.function("sparse", &NumericMatrix::sparse, emscripten::return_value_policy::take_ownership())
.function("clone", &NumericMatrix::clone, emscripten::return_value_policy::take_ownership())
;
}
14 changes: 7 additions & 7 deletions src/aggregate_across_cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ AggregateAcrossCells_Results aggregate_across_cells(const NumericMatrix& mat, ui
}

EMSCRIPTEN_BINDINGS(aggregate_across_cells) {
emscripten::function("aggregate_across_cells", &aggregate_across_cells);
emscripten::function("aggregate_across_cells", &aggregate_across_cells, emscripten::return_value_policy::take_ownership());

emscripten::class_<AggregateAcrossCells_Results>("AggregateAcrossCells_Results")
.function("group_sums", &AggregateAcrossCells_Results::group_sums)
.function("all_sums", &AggregateAcrossCells_Results::all_sums)
.function("group_detected", &AggregateAcrossCells_Results::group_detected)
.function("all_detected", &AggregateAcrossCells_Results::all_detected)
.function("num_genes", &AggregateAcrossCells_Results::num_genes)
.function("num_groups", &AggregateAcrossCells_Results::num_groups)
.function("group_sums", &AggregateAcrossCells_Results::group_sums, emscripten::return_value_policy::take_ownership())
.function("all_sums", &AggregateAcrossCells_Results::all_sums, emscripten::return_value_policy::take_ownership())
.function("group_detected", &AggregateAcrossCells_Results::group_detected, emscripten::return_value_policy::take_ownership())
.function("all_detected", &AggregateAcrossCells_Results::all_detected, emscripten::return_value_policy::take_ownership())
.function("num_genes", &AggregateAcrossCells_Results::num_genes, emscripten::return_value_policy::take_ownership())
.function("num_groups", &AggregateAcrossCells_Results::num_groups, emscripten::return_value_policy::take_ownership())
;
}

4 changes: 2 additions & 2 deletions src/cbind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ NumericMatrix rbind(int n, uintptr_t mats) {
}

EMSCRIPTEN_BINDINGS(cbind) {
emscripten::function("cbind", &cbind);
emscripten::function("cbind", &cbind, emscripten::return_value_policy::take_ownership());

emscripten::function("rbind", &rbind);
emscripten::function("rbind", &rbind, emscripten::return_value_policy::take_ownership());
}
18 changes: 9 additions & 9 deletions src/cluster_kmeans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ ClusterKmeans_Result cluster_kmeans(uintptr_t mat, int nr, int nc, int k, std::s
}

EMSCRIPTEN_BINDINGS(cluster_kmeans) {
emscripten::function("cluster_kmeans", &cluster_kmeans);
emscripten::function("cluster_kmeans", &cluster_kmeans, emscripten::return_value_policy::take_ownership());

emscripten::class_<ClusterKmeans_Result>("ClusterKmeans_Result")
.function("num_obs", &ClusterKmeans_Result::num_obs)
.function("num_clusters", &ClusterKmeans_Result::num_clusters)
.function("cluster_sizes", &ClusterKmeans_Result::cluster_sizes)
.function("wcss", &ClusterKmeans_Result::wcss)
.function("clusters", &ClusterKmeans_Result::clusters)
.function("centers", &ClusterKmeans_Result::centers)
.function("iterations", &ClusterKmeans_Result::iterations)
.function("status", &ClusterKmeans_Result::status)
.function("num_obs", &ClusterKmeans_Result::num_obs, emscripten::return_value_policy::take_ownership())
.function("num_clusters", &ClusterKmeans_Result::num_clusters, emscripten::return_value_policy::take_ownership())
.function("cluster_sizes", &ClusterKmeans_Result::cluster_sizes, emscripten::return_value_policy::take_ownership())
.function("wcss", &ClusterKmeans_Result::wcss, emscripten::return_value_policy::take_ownership())
.function("clusters", &ClusterKmeans_Result::clusters, emscripten::return_value_policy::take_ownership())
.function("centers", &ClusterKmeans_Result::centers, emscripten::return_value_policy::take_ownership())
.function("iterations", &ClusterKmeans_Result::iterations, emscripten::return_value_policy::take_ownership())
.function("status", &ClusterKmeans_Result::status, emscripten::return_value_policy::take_ownership())
;
}
26 changes: 13 additions & 13 deletions src/cluster_snn_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,31 @@ ClusterSnnGraphLeiden_Result cluster_snn_graph_leiden(const BuildSnnGraph_Result
/**********************************/

EMSCRIPTEN_BINDINGS(cluster_snn_graph) {
emscripten::function("build_snn_graph", &build_snn_graph);
emscripten::function("build_snn_graph", &build_snn_graph, emscripten::return_value_policy::take_ownership());

emscripten::class_<BuildSnnGraph_Result>("BuildSnnGraph_Result");

emscripten::function("cluster_snn_graph_multilevel", &cluster_snn_graph_multilevel);
emscripten::function("cluster_snn_graph_multilevel", &cluster_snn_graph_multilevel, emscripten::return_value_policy::take_ownership());

emscripten::class_<ClusterSnnGraphMultiLevel_Result>("ClusterSnnGraphMultiLevel_Result")
.function("number", &ClusterSnnGraphMultiLevel_Result::number)
.function("best", &ClusterSnnGraphMultiLevel_Result::best)
.function("modularity", &ClusterSnnGraphMultiLevel_Result::modularity)
.function("membership", &ClusterSnnGraphMultiLevel_Result::membership)
.function("number", &ClusterSnnGraphMultiLevel_Result::number, emscripten::return_value_policy::take_ownership())
.function("best", &ClusterSnnGraphMultiLevel_Result::best, emscripten::return_value_policy::take_ownership())
.function("modularity", &ClusterSnnGraphMultiLevel_Result::modularity, emscripten::return_value_policy::take_ownership())
.function("membership", &ClusterSnnGraphMultiLevel_Result::membership, emscripten::return_value_policy::take_ownership())
;

emscripten::function("cluster_snn_graph_walktrap", &cluster_snn_graph_walktrap);
emscripten::function("cluster_snn_graph_walktrap", &cluster_snn_graph_walktrap, emscripten::return_value_policy::take_ownership());

emscripten::class_<ClusterSnnGraphWalktrap_Result>("ClusterSnnGraphWalktrap_Result")
.function("modularity", &ClusterSnnGraphWalktrap_Result::modularity)
.function("membership", &ClusterSnnGraphWalktrap_Result::membership)
.function("num_merge_steps", &ClusterSnnGraphWalktrap_Result::num_merge_steps)
.function("modularity", &ClusterSnnGraphWalktrap_Result::modularity, emscripten::return_value_policy::take_ownership())
.function("membership", &ClusterSnnGraphWalktrap_Result::membership, emscripten::return_value_policy::take_ownership())
.function("num_merge_steps", &ClusterSnnGraphWalktrap_Result::num_merge_steps, emscripten::return_value_policy::take_ownership())
;

emscripten::function("cluster_snn_graph_leiden", &cluster_snn_graph_leiden);
emscripten::function("cluster_snn_graph_leiden", &cluster_snn_graph_leiden, emscripten::return_value_policy::take_ownership());

emscripten::class_<ClusterSnnGraphLeiden_Result>("ClusterSnnGraphLeiden_Result")
.function("modularity", &ClusterSnnGraphLeiden_Result::modularity)
.function("membership", &ClusterSnnGraphLeiden_Result::membership)
.function("modularity", &ClusterSnnGraphLeiden_Result::modularity, emscripten::return_value_policy::take_ownership())
.function("membership", &ClusterSnnGraphLeiden_Result::membership, emscripten::return_value_policy::take_ownership())
;
}
8 changes: 4 additions & 4 deletions src/delayed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void transpose(NumericMatrix& x) {
}

EMSCRIPTEN_BINDINGS(delayed_operations) {
emscripten::function("delayed_arithmetic_scalar", &delayed_arithmetic_scalar);
emscripten::function("delayed_arithmetic_vector", &delayed_arithmetic_vector);
emscripten::function("delayed_math", &delayed_math);
emscripten::function("transpose", &transpose);
emscripten::function("delayed_arithmetic_scalar", &delayed_arithmetic_scalar, emscripten::return_value_policy::take_ownership());
emscripten::function("delayed_arithmetic_vector", &delayed_arithmetic_vector, emscripten::return_value_policy::take_ownership());
emscripten::function("delayed_math", &delayed_math, emscripten::return_value_policy::take_ownership());
emscripten::function("transpose", &transpose, emscripten::return_value_policy::take_ownership());
}
2 changes: 1 addition & 1 deletion src/filter_cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ NumericMatrix filter_cells(const NumericMatrix& mat, uintptr_t filter, bool keep
}

EMSCRIPTEN_BINDINGS(filter_cells) {
emscripten::function("filter_cells", &filter_cells);
emscripten::function("filter_cells", &filter_cells, emscripten::return_value_policy::take_ownership());
}
2 changes: 1 addition & 1 deletion src/get_error_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ std::string get_error_message(intptr_t ptr) {
}

EMSCRIPTEN_BINDINGS(Bindings) {
emscripten::function("get_error_message", &get_error_message);
emscripten::function("get_error_message", &get_error_message, emscripten::return_value_policy::take_ownership());
};
2 changes: 1 addition & 1 deletion src/grouped_size_factors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ void grouped_size_factors(const NumericMatrix& mat,
}

EMSCRIPTEN_BINDINGS(grouped_size_factors) {
emscripten::function("grouped_size_factors", &grouped_size_factors);
emscripten::function("grouped_size_factors", &grouped_size_factors, emscripten::return_value_policy::take_ownership());
}
Loading

0 comments on commit bb498e0

Please sign in to comment.