Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make nimble build succeed on Linux (#128)
Before this commit, running `nimble build` on Linux would error at link time with: /usr/bin/ld: /home/runner/.cache/nim/test_r/@Merr@soutput.nim.c.o: in function `customValidationError__errZoutput_u909': @Merr@soutput.nim.c:(.text+0x28c1): undefined reference to `find_string_at' /usr/bin/ld: /home/runner/.cache/nim/test_r/@[email protected]: in function `foreign_z_call': @[email protected]:(.text+0x52d): undefined reference to `run_0c00l_vm' collect2: error: ld returned 1 exit status This happened only when building `test`, and occurred because: - `find_string_at` is defined in codegen.nim - `run_0c00l_vm` is defined in vm.nim and on Linux neither file was compiled when building `test`, which was an item in `bin` in the nimutils nimble file. From the docs [1]: `bin` - A list of files which should be built separated by commas with no file extension required. This option turns your package into a binary package. Nimble will build the files specified and install them appropriately. `nimble build` did work on macOS, but I believe that's only because applyCommonLinkOptions() in nimutils enabled link time optimization (LTO) for macOS only [2]: when defined(macosx): switch("cpu", targetArch) switch("passc", "-flto -target " & targetStr) switch("passl", "-flto -w -target " & targetStr & "-Wl,-object_path_lto,lto.o") elif defined(linux): if staticLink: switch("passc", "-static") switch("passl", "-static") else: discard else: echo "Platform not supported." quit(1) which caused files to be compiled that otherwise wouldn't be. Restructure slightly to allow `nimble build` to succeed without LTO. This is much better than just enabling LTO on Linux, which dramatically increases compilation time with a typical setup. It also wouldn't be ideal for LTO to be _required_, especially for debug builds. Builds would probably be significantly faster with clang, but I tried to get clang builds working on Linux, and was unsuccessful with e.g. CC=clang nimble build \ -f \ --cc:env \ --clang.exe:musl-clang \ --clang.linkerexe:musl-clang \ --passC:-flto \ --passC:-Wno-implicit-function-declaration \ --passC:-Wno-int-conversion \ --passC:-Wno-incompatible-function-pointer-types -d:zippyNoSimd This commit adds a `vm` import in test.nim, and extracts the find_string_at proc to a separate module. It seemed like it wasn't possible to simply add some lines like: import codegen or from codegen import find_string_at due to Nim not supporting mutual imports yet, which is the reason for these importc and exportc in the first place. Closes: #122 [1] https://nim-lang.github.io/nimble/nimble-reference.html#optional [2] https://github.com/crashappsec/nimutils/blob/74130e392d9b/nimutils/nimscript.nim#L76-L89
- Loading branch information