jhass / crystal-gobject

gobject-introspection for Crystal
BSD 3-Clause "New" or "Revised" License
127 stars 13 forks source link

Unable to build gi-doc #48

Closed ghost closed 4 years ago

ghost commented 4 years ago

I'm trying to build gi-doc so I can generate some documentation for myself. Unfortunately, running shards build produces this error:

λ shards build
Dependencies are satisfied
Building: gi-generator
Building: gi-dump
Building: gi-doc
Error target gi-doc failed to compile:
/usr/bin/ld: /var/lib/snapd/snap/crystal/331/share/crystal/src/llvm/ext/llvm_ext.o: in function `llvm::MetadataTracking::track(llvm::Metadata*&)':
llvm_ext.cc:(.text._ZN4llvm16MetadataTracking5trackERPNS_8MetadataE[_ZN4llvm16MetadataTracking5trackERPNS_8MetadataE]+0x42): undefined reference to `llvm::MetadataTracking::track(void*, llvm::Metadata&, llvm::PointerUnion<llvm::MetadataAsValue*, llvm::Metadata*>)'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o '/home/sim/Downloads/crystal-gobject/bin/gi-doc'  -rdynamic  -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` /var/lib/snapd/snap/crystal/331/share/crystal/src/llvm/ext/llvm_ext.o `/usr/bin/llvm-config --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lgirepository-1.0 -lxml2 -lpcre -lm /var/lib/snapd/snap/crystal/331/bin/../lib/crystal/lib/libgc.a -lpthread /var/lib/snapd/snap/crystal/331/share/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/var/lib/snapd/snap/crystal/331/bin/../lib/crystal/lib -L/var/lib/snapd/snap/crystal/331/bin/../lib/crystal/lib`

I've got all the dependencies and LLVM installed. Is this a problem on my end, or is this an issue with the build?

jhass commented 4 years ago

gi-doc reuses large parts of the documentation generator, and thus parser, included into the compiler, so it is building the compiler as part of it. Are you able to build the compiler from soure?

ghost commented 4 years ago

I just built the compiler and ran the spec tests. Everything works fine, but I'm still unable to build the doc generator.

jhass commented 4 years ago

Mmh, maybe the LLVM version used to build the snap differs from the one installed into the system? I don't really know.

It'll probably work with your just built compiler, try export PATH="/path/to/your/crystal/repo/clone/bin:$PATH.

ghost commented 4 years ago

That makes sense. IIRC the official LLVM version for Crystal is 8, while Fedora's default is 8.

That command sort of worked, but now I get a crystal error:

Error target gi-doc failed to compile:
Using compiled compiler at /home/sim/Programming/git/not_mine/crystal/.build/crystal
Showing last frame. Use --error-trace for full trace.

In src/generator/doc.cr:228:23

 228 | generator = Generator.new(result.program, included_dirs, output_directory, "html", nil, "", "")
                             ^--
Error: wrong number of arguments for 'Generator.new' (given 7, expected 2, 8)

Overloads are:
 - Crystal::Doc::Generator.new(program : Program, included_dirs : Array(String), output_dir : String, output_format : String, sitemap_base_url : String | ::Nil, sitemap_priority : String, sitemap_changefreq : String, project_info : ProjectInfo)
 - Crystal::Doc::Generator.new(program : Program, included_dirs : Array(String))
jhass commented 4 years ago

Ah, right, master is landing many changes to the doc generator currently, missed thinking about that :/

I'm hesitant to just update gi-doc to that without those changes having all landed in a release yet, so I would ask you to into one more round of trial and error by doing make clean; git checkout 0.34.0; make in your crystal-lang/crystal clone please :)

ghost commented 4 years ago

I managed to fix it by appending Crystal::Doc::ProjectInfo.new to the function call arguments, and that fixed it.

Thanks for the help, I appreciate it :)

ghost commented 4 years ago

Whoops, runtime error. I'll try checking out that branch like you said

ghost commented 4 years ago

That didn't fix it. New error!

λ ./bin/gi-doc Gtk
Unhandled exception: while requiring "gobject" (Crystal::TypeException)
  from /home/sim/Programming/git/not_mine/crystal/src/compiler/crystal/semantic/ast.cr:13:9 in 'raise'
  from /home/sim/Programming/git/not_mine/crystal/src/compiler/crystal/semantic/ast.cr:12:5 in 'raise'
  from /home/sim/Programming/git/not_mine/crystal/src/compiler/crystal/semantic/semantic_visitor.cr:72:5 in 'visit'
  from /home/sim/Programming/git/not_mine/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/sim/Programming/git/not_mine/crystal/src/compiler/crystal/semantic/top_level_visitor.cr:724:9 in 'visit'
  from /home/sim/Programming/git/not_mine/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/sim/Programming/git/not_mine/crystal/src/compiler/crystal/semantic.cr:62:7 in 'top_level_semantic'
  from /home/sim/Programming/git/not_mine/crystal/src/compiler/crystal/compiler.cr:193:25 in 'top_level_semantic'
  from src/generator/doc.cr:226:10 in '__crystal_main'
  from /home/sim/Programming/git/not_mine/crystal/src/crystal/main.cr:105:5 in 'main_user_code'
  from /home/sim/Programming/git/not_mine/crystal/src/crystal/main.cr:91:7 in 'main'
  from /home/sim/Programming/git/not_mine/crystal/src/crystal/main.cr:114:3 in 'main'
  from __libc_start_main
  from _start
  from ???
jhass commented 4 years ago

Mmh, it works if you run it from within samples/ 😆 (In other words from within something that has crystal-gobject within a lib folder).

Guess I'll have to figure out a way to always push it into the lookup path for gi-doc 🤔

jhass commented 4 years ago

Well, this is a terrible hack, but so is the entire gi-doc thing. Let's see if that works for you :D

ghost commented 4 years ago

Terrible hacks are the best kind! T his one's even better because it works perfectly, thank you :)