Closed f-fr closed 4 years ago
Oh hi, this is caused by bindgens shard.yml, its postinstall hook needs to be updated to reflect that change. Can you PR that over there?
It seems as if shard.yml of qt5.cr also contains the lines
scripts:
postinstall: crystal deps build
so should it be updated, too? Whats the “correct” fix, replace that line by “shards build”? (I'm pretty new to crystal/shards so I have no idea how this should work, sorry)
Yeah that should work. You can verify by running shards build
in the bindgen/ directory.
It took me some time to even find the "bindgen/" directory, because shards seems to remove the directory immediately if the installation fails.
Anyway, I just cloned bindgen
and ran shards build
in that directory. It seems to do something but then stops with the following error message:
Fetching https://github.com/Papierkorb/toka.git
Installing toka (0.1.2)
Building: bindgen
Error target bindgen failed to compile:
Error in src/bindgen.cr:57: instantiating 'Bindgen::Tool:Class#new(String, Bindgen::Configuration, Bool)'
tool = Bindgen::Tool.new(File.dirname(config_path), config, opts.stats)
^~~
in src/bindgen/tool.cr:34: instantiating 'Bindgen::Processor::Runner:Class#new(Bindgen::Configuration, Bindgen::TypeDatabase)'
@processors = Processor::Runner.new(@config, @database)
^~~
in src/bindgen/processor/runner.cr:10: instance variable '@processors' of Bindgen::Processor::Runner must be Array(Bindgen::Processor::Base), not Array(Bindgen::Processor::AutoContainerInstantiation | Bindgen::Processor::CopyStructs | Bindgen::Processor::CppWrapper | Bindgen::Processor::CrystalBinding | Bindgen::Processor::CrystalWrapper | Bindgen::Processor::DefaultConstructor | Bindgen::Processor::DumpGraph | Bindgen::Processor::Enums | Bindgen::Processor::ExternC | Bindgen::Processor::FilterMethods | Bindgen::Processor::FunctionClass | Bindgen::Processor::Functions | Bindgen::Processor::Inheritance | Bindgen::Processor::InstantiateContainers | Bindgen::Processor::Macros | Bindgen::Processor::Qt | Bindgen::Processor::SanityCheck | Bindgen::Processor::VirtualOverride)
@processors = config.processors.map do |name|
^~~~~~~~~~~
So now a little bit lost how to proceed. This is probably a different issue and I should file it in bindgens repo (right?), but should the "crystal deps" thing be fixed first?
Both issues are bindgen issues in any case. That issue there is new, looks like the type inference algorithm of Crystal got stupider. The #map
block starting in src/bindgen/processor/runner.cr:10
needs an .as(Processor::Base)
appended to the last line of its body, so the expression that comes before its end (<- Edit). That should fix it.
I myself am not using Crystal currently, so recent changes in the language are beyond me.
It's not related to type inference, see https://github.com/crystal-lang/crystal/pull/6024.
@RX14 thanks, but should the following example work:
class Base
def self.create : Base
A.new
end
end
class A < Base
end
class AnyOf < Base
@children : Array(Base)
def initialize
@children = [Base.create]
end
end
AnyOf.new
The declaration of Base.create
states that the return type is Base
not A
, so why crystal assumes that the call to Base.create
returns an A
?
Return type restrictions are not casts, they're constraints. self.create
returns type A
, but the return type restriction of Base
doesn't error because A
is a Base
. You need to use A.new.as(Base)
.
I see, interesting. That makes sense but might lead to surprising errors (in particular if using external shards or so). Anyway, thanks for the explanation.
I just tried installing it myself (8-year Rubyist new to Crystal) using the steps described here, and it seems to me that this project needs URGENT re-compiliing and testing with the newest Crystal compiler, particularly the Bindgen stuff! I got an avalanche of cascading Type-related errors when I compiled it using crystal 0.25.1.
Thank you!
@PerrinHH You're welcome to do so, I'm not interested in Crystal much anymore.
@Papierkorb that's sad to hear, just lack of time?
As for me, I tried.And I came to a point where the backtrace responded this:
in src/bindgen/crystal/format.cr:120: undefined method 'key?' for Hash(String, Int64)
Which means that this Hash does not respond to the key? method (which it should, according to documentation). Any ideas what I am supposed to do now? Thank you.
You're correct. The documentation I read referred do Crystal 0.24.2.
(Classical case for "Polish your glasses and read the small print.")
Took me a little to fix the bindgen compilation errors caused by the Crystal update to 0.25.1. But finally I got it. Bindgen compiles. Yeeeah!
Now: How can I link my private Bindgen update to qt5
? Building qt5
still results in downloading the "old" bindgen sources that still produce this error:
Please use 'shards': 'crystal deps' has been removed
What can I do now? Since shards
deletes all downloaded files on error, I'm really stuck. Please help. Thank you.
@PerrinHH, should be fixed in https://github.com/Papierkorb/qt5.cr/pull/14. Please check.
Closing this issue as both bindgen's and qt5.cr's commits for the reported problem have been merged. Bindgen now works with Crystal 0.34.0 and is at release v0.7.0. Qt5.cr is being updated/worked on - see https://github.com/Papierkorb/qt5.cr/issues/29.
When trying to install the shard using
shards install
I get