Cross-compilation build Linux to Windows Error - Forward slashes in paths converted to Backslashes
Build failing for windows/mingw target. Nimble project structure: src/wasm.nim:
import wasm3
let
env = loadWasmEnv(readFile"wasm_payload.wasm")
read_at_place = env.findFunction("read_wasm_at_index")
echo read_at_place.call(uint32, 0)
wasm.nimble:
# Package
[...]
srcDir = "src"
bin = @["wasm"]
# Dependencies
requires "nim >= 2.0.2"
requires "https://github.com/beef331/wasm3 >= 0.1.1"
Compilation command: nimble build -d:mingw:
Verifying dependencies for [email protected]
Info: Dependency on https://github.com/beef331/wasm3@>= 0.1.1 already satisfied
Verifying dependencies for [email protected]
Info: Dependency on https://github.com/beef331/micros/@any version already satisfied
Verifying dependencies for [email protected]
Building wasm/wasm using c backend
/home/<redacted>/.nimble/pkgs2/wasm3-0.1.9-fe3d1f397a835018bddd8ac01b91351292d334ab/wasm3/wasm3c.nim(14, 10) Error: cannot find: \home\<redacted>\.nimble\pkgs2\wasm3-0.1.9-fe3d1f397a835018bddd8ac01b91351292d334ab\wasm3\wasm3c\source\m3_api_tracer.c
Tip: 6 messages have been suppressed, use --verbose to show them.
nimble.nim(229) buildFromDir
Error: Build failed for the package: wasm
After hammering the correct source paths into wasm3c.nim, eventually got another error of the same kind in a different C source file:
Verifying dependencies for [email protected]
Info: Dependency on https://github.com/beef331/wasm3@>= 0.1.1 already satisfied
Verifying dependencies for [email protected]
Info: Dependency on https://github.com/beef331/micros/@any version already satisfied
Verifying dependencies for [email protected]
Building wasm/wasm using c backend
/home/<redacted>/.nimble/pkgs2/wasm3-0.1.9-fe3d1f397a835018bddd8ac01b91351292d334ab/wasm3.nim(220, 14) Warning: Insert rendered proc here [User]
/home/<redacted>/.cache/nim/wasm_d/@m..@s..@s..@[email protected]@[email protected]@swasm3.nim.c:8:10: fatal error: wasm3.h: No such file or directory
8 | #include "wasm3.h"
| ^~~~~~~~~
compilation terminated.
Error: execution of an external compiler program '/usr/bin/x86_64-w64-mingw32-gcc -c -w -fmax-errors=3 -mno-ms-bitfields -DWIN32_LEAN_AND_MEAN -I\home\<redacted>\.nimble\pkgs2\wasm3-0.1.9-fe3d1f397a835018bddd8ac01b91351292d334ab\wasm3\wasm3c\source\ -I/home/<redacted>/.choosenim/toolchains/nim-2.0.2/lib -I/home/<redacted>/Documents/nim_projects/wasm/src -o /home/<redacted>/.cache/nim/wasm_d/@m..@s..@s..@[email protected]@[email protected]@swasm3.nim.c.o /home/<redacted>/.cache/nim/wasm_d/@m..@s..@s..@[email protected]@[email protected]@swasm3.nim.c' failed with exit code: 1
Fix seems simple, just don't change the source files path to backslashes if compiling on Linux.
Fairly certain this is just an issue with Nim + mingw it auto converts paths when using mingw. Perhaps using {.compile.} was a fools errand and it's best to have a precompilation step that compiles the code into object files.
Finally got around to bodging this in, fixed in 0.1.18. I know I know it's been ages and you've grown to have an entire family and put them through Uni.