beef331 / wasm3

Yet another wasm runtime to toy with
MIT License
23 stars 3 forks source link

Cross-compilation build Linux to Windows Error - Forward slashes in paths converted to Backslashes #10

Open BrunoPincho opened 10 months ago

BrunoPincho commented 10 months ago

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 wasm@0.1.0
     Info:  Dependency on https://github.com/beef331/wasm3@>= 0.1.1 already satisfied
  Verifying dependencies for wasm3@0.1.9
     Info:  Dependency on https://github.com/beef331/micros/@any version already satisfied
  Verifying dependencies for micros@0.1.15
   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 wasm@0.1.0
     Info:  Dependency on https://github.com/beef331/wasm3@>= 0.1.1 already satisfied
  Verifying dependencies for wasm3@0.1.9
     Info:  Dependency on https://github.com/beef331/micros/@any version already satisfied
  Verifying dependencies for micros@0.1.15
   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..@s..@s.nimble@spkgs2@swasm3-0.1.9-fe3d1f397a835018bddd8ac01b91351292d334ab@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..@s..@s.nimble@spkgs2@swasm3-0.1.9-fe3d1f397a835018bddd8ac01b91351292d334ab@swasm3.nim.c.o /home/<redacted>/.cache/nim/wasm_d/@m..@s..@s..@s..@s.nimble@spkgs2@swasm3-0.1.9-fe3d1f397a835018bddd8ac01b91351292d334ab@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.

beef331 commented 10 months ago

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.