futhark icon indicating copy to clipboard operation
futhark copied to clipboard

Futhark needs to run twice

Open heuer opened this issue 4 months ago • 1 comments

I need some functions/structs from the xkbcommon lib.

Here an excerpt from my futhark config (sorry for the un-nimesque snake case code ;)):

when defined(USE_FUTHARK):
  import futhark

  proc rename_callback(
    name: string, kind: SymbolKind, partOf: string, overloading: var bool
  ): string =
    result = name
    if result.starts_with("xkb_layout_index_t_"):
      result = "xkb_layout_index_t"

  importc:
    outputPath current_source_path.parent_dir / "generated.nim"
    # […]
    renameCallback rename_callback
    # […]
    path "/usr/include/xkbcommon/"
    "xkbcommon.h"
    # […]
else:
  include "generated.nim"

I get the following error:

.nimble/pkgs2/futhark-0.15.0-50ab2e44c9d5cc99ba1c85032b63c1086c71371c/futhark.nim(779, 14) template/generic instantiation of `importcImpl` from here
(1, 27) Error: undeclared identifier: 'xkb_layout_index_t_536871429'
candidates (edit distance, scope distance); see '--spellSuggest':
 (9, 0): 'xkb_layout_index_t'
nimble.nim(304)          buildFromDir

But when I restart the build process, it runs without any problems.

Any idea? Let me know if you need further information.

heuer avatar Oct 20 '25 10:10 heuer

I've seen this myself, but been unable to create a small reproduction. The culprit is likely that the macro code generates some slightly invalid code, but which is rendered correct when it goes through the writing out to a file and being parsed back in.

PMunch avatar Oct 20 '25 11:10 PMunch