Skip to content

Commit

Permalink
19511: Adds LoadEntityLegacy to C API for interop with legacy callers (
Browse files Browse the repository at this point in the history
…#88)

Adding LoadEntityLegacy to C API so wrappers that don't support
LoadEntityStatus yet can still use new Amalgam. This method is
deprecated on creation and will be removed in future releases when
wrappers have been updated to use LoadEntityStatus struct.
  • Loading branch information
calebwherry authored Mar 4, 2024
1 parent 94e9b64 commit 392eba7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/cmake/global_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" S
# TODO 1599: WASM support is experimental, these flags will be cleaned up and auto-generated where possible
if(IS_WASM)
string(APPEND CMAKE_CXX_FLAGS " -sMEMORY64=2 -Wno-experimental -DSIMDJSON_NO_PORTABILITY_WARNING")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -sINVOKE_RUN=0 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=65536000 -sMEMORY_GROWTH_GEOMETRIC_STEP=0.50 -sMODULARIZE=1 -sEXPORT_NAME=AmalgamRuntime -sENVIRONMENT=worker -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,FS,setValue,getValue,UTF8ToString -sEXPORTED_FUNCTIONS=_malloc,_free,_LoadEntity,_StoreEntity,_ExecuteEntity,_ExecuteEntityJsonPtr,_DestroyEntity,_GetEntities,_SetRandomSeed,_SetJSONToLabel,_GetJSONPtrFromLabel,_SetSBFDataStoreEnabled,_IsSBFDataStoreEnabled,_GetVersionString,_SetMaxNumThreads,_GetMaxNumThreads,_GetConcurrencyTypeString,_DeleteString --preload-file /wasm/tzdata@/tzdata --preload-file /wasm/etc@/etc")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -sINVOKE_RUN=0 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=65536000 -sMEMORY_GROWTH_GEOMETRIC_STEP=0.50 -sMODULARIZE=1 -sEXPORT_NAME=AmalgamRuntime -sENVIRONMENT=worker -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,FS,setValue,getValue,UTF8ToString -sEXPORTED_FUNCTIONS=_malloc,_free,_LoadEntity,_LoadEntityLegacy,_VerifyEntity,_StoreEntity,_ExecuteEntity,_ExecuteEntityJsonPtr,_DestroyEntity,_GetEntities,_SetRandomSeed,_SetJSONToLabel,_GetJSONPtrFromLabel,_SetSBFDataStoreEnabled,_IsSBFDataStoreEnabled,_GetVersionString,_SetMaxNumThreads,_GetMaxNumThreads,_GetConcurrencyTypeString,_DeleteString --preload-file /wasm/tzdata@/tzdata --preload-file /wasm/etc@/etc")
endif()

elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
Expand Down
4 changes: 4 additions & 0 deletions src/Amalgam/Amalgam.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ extern "C"
//loads the entity specified into handle
AMALGAM_EXPORT LoadEntityStatus LoadEntity(char *handle, char *path, bool persistent, bool load_contained_entities, char *write_log_filename, char *print_log_filename);

//loads the entity specified into handle
//TODO 19512: deprecated - legacy method to support wrappers that can't call LoadEntity returning a LoadEntityStatus yet
AMALGAM_EXPORT bool LoadEntityLegacy(char *handle, char *path, bool persistent, bool load_contained_entities, char *write_log_filename, char *print_log_filename);

//verifies the entity specified by path. Uses LoadEntityStatus to return any errors and version
AMALGAM_EXPORT LoadEntityStatus VerifyEntity(char *path);

Expand Down
10 changes: 10 additions & 0 deletions src/Amalgam/AmalgamAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ extern "C"
return ConvertLoadStatusToCStatus(status);
}

bool LoadEntityLegacy(char *handle, char *path, bool persistent, bool load_contained_entities, char *write_log_filename, char *print_log_filename)
{
auto status = LoadEntity(handle, path, persistent, load_contained_entities, write_log_filename, print_log_filename);

delete[] status.message;
delete[] status.version;

return status.loaded;
}

LoadEntityStatus VerifyEntity(char *path)
{
std::string p(path);
Expand Down

0 comments on commit 392eba7

Please sign in to comment.