Skip to content

Commit

Permalink
generate mintops.ts to artifacts/bin/native/generated
Browse files Browse the repository at this point in the history
- Drive the generation from wasm.proj (driving it from cmake is wrong,
because the cmake build runs after rollup)
- Use the tsconfig rootDirs option to specify where to find the
files (runtime dir and also artifacts/bin/native/generated)
- Also due to rollup issues, specify rootDirs and include in
rollup.config.js - otherwise the rollup typescript plugin doesn't seem
to kick in, and barebones rollup gets confused when parsing .ts files
- The outDir option in tsconfig.json had to be deleted to make rollup
work.  But it was also unused since rollup controls where the ts
plugin is supposed to emit its output
- VS Code understands the tsconfig.json changes and can follow
references to the artifacts/.../generated folder

Note that Release and Debug builds both dump the generates mintops.ts
in the same folder.  This seems ok for now since there's no special
debug-only opcodes.  (Also VS Code has no idea about configurations,
so it has to be done this way or else it won't be able to find the .ts file)
  • Loading branch information
lambdageek committed Nov 21, 2022
1 parent 589ac14 commit 91d2bc9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1,658 deletions.
7 changes: 0 additions & 7 deletions src/mono/wasm/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ set_target_properties(dotnet PROPERTIES

set(ignoreMeWasmOptFlags "${CONFIGURATION_WASM_OPT_FLAGS}")

add_custom_target(GENERATE_MINTOPS_TYPESCRIPT ALL
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/genmintops.py "${CMAKE_CURRENT_SOURCE_DIR}/../../mono/mini/interp/mintops.def" "${CMAKE_CURRENT_SOURCE_DIR}/mintops.ts"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/genmintops.py ${CMAKE_CURRENT_SOURCE_DIR}/../../mono/mini/interp/mintops.def
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/mintops.ts
VERBATIM
)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(TARGET dotnet
POST_BUILD COMMAND ${EMSDK_PATH}/upstream/bin/wasm-opt --enable-exception-handling ${CONFIGURATION_WASM_OPT_FLAGS} --strip-dwarf ${NATIVE_BIN_DIR}/dotnet.wasm -o ${NATIVE_BIN_DIR}/dotnet.wasm
Expand Down
19 changes: 10 additions & 9 deletions src/mono/wasm/runtime/genmintops.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@
}};
"""

dest = open(output_ts_path, 'r')
if (dest.read() == generated):
print("mintops.ts up to date, exiting")
exit(0)

dest.close()
dest = open(output_ts_path, 'w')
dest.write(generated)
os.makedirs(os.path.dirname(output_ts_path), exist_ok=True)
try:
with open(output_ts_path, 'r') as dest:
if (dest.read() == generated):
print("mintops.ts up to date, exiting")
exit(0)
except FileNotFoundError:
pass
with open(output_ts_path, 'w') as dest:
dest.write(generated)
print("mintops.ts generated")
dest.close()
exit(0)
Loading

0 comments on commit 91d2bc9

Please sign in to comment.