Open serge-hulne opened 1 year ago
You need to have WebView2 SDK installed for compilation to work on windows.
This shard is just a wrapper against webview library, so if you encounter webview compilation related issues, please refer to webview
library link.
Thank you.
I think with #21 this can be closed. @serge-hulne, can you confirm that it works?
I don't know. I couldn't make the WebView shard work under Windows (but maybe it's just me or maybe Crystal for Windows is still too experimental at this stage). I initially wanted to port my rudimentary prototype from Mac OS to Windows (https://github.com/serge-hulne/CrystApp) but none of the required shards seem to work "out of the box" at this stage, so maybe I will just drop the idea to port it to Windows at this early stage of development of Crystal for Windows.
Feel free to close the issue. Thanks for your kind help!
What would really help for my project is if a simple shards install
(from the powershell or from a MSYS2 terminal) was sufficient to use WebView from Crystal under Windows 10/11 (the way it works on Mac OS, basically).
Here is how a V-Lang developper has done it. He uses scripts to build the libraries. There is no special tool needed (no requirement to use Microsoft Visual Code or so)
https://github.com/malisipi/mui/tree/main/webview
@serge-hulne have you checked updated section https://github.com/naqvis/webview#pre-requisite ? No special tools is needed, just few commands.
Of course, one of the ways could be duplicate build.bat functionality from webview library in shard.yml postinstall. Both approaches has positive and negative sides.
Another problem (and maybe another issue) though is support of fibers. Basically, without periodical call of Fiber.yield
or sleep(0.01)
all fibers in current thread will stop working after calling Webview.run
. The fact that it seems to work on Mac OS is coincidence - without Fiber.yield
you will meet a frozen fibers in sufficiently big application (unless you completely avoid spawn
).
I've patched original webview to have a callback in application loop, but it is simple only for Windows. Carbon and GTK implementations need another approach.
Hi, I haven't checked the updated section yet, but I will keep you posted as soon as I have.
Thank you!
I tried the installation procedure from your new documentation.
The first step worked:
[x] You should have Visual C++ Build tools already as it's a pre-requisite for crystal compiler
[x] git clone https://github.com/webview/webview to get WebView sources
[x] webview\script\build.bat to compile them (it will download required nuget package)
[x] copy webview\dll\x64\webview.lib to <your crystal installation>\lib
[x] copy webview\dll\x64\webview.dll to directory with your program
The second step did't work:
[x] Add the dependency to your shard.yml:
dependencies:
webview:
github: naqvis/webview
[] Run shards install <=== PROBLEM (See herunder)
The problem is that Visual C++ Build tools
doesn't seem to install gcc or g++ on the command line, therefore when shards install
tries to compile :
Resolving dependencies
Fetching https://github.com/naqvis/webview.git
Installing webview (0.2.2)
Postinstall of webview: make
Failed postinstall of webview on make:
g++ -c -o ext/webview.o -std=c++11 ext/webview.cc
process_begin: CreateProcess(NULL, uname, ...) failed.
Makefile:1: pipe: No error
process_begin: CreateProcess(NULL, g++ -c -o ext/webview.o -std=c++11 ext/webview.cc, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [Makefile:23: ext/webview.o] Error 2
PS C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\webview6\app>
actually yes, shard.yml has to be fixed. but if directory lib/webview
is present, you can try examples even though the step was failed.
Apparently not, since:
require "webview"
I wish I could do more to help, but I have no experience with the gcc toolchain under Windows (I use MingW to fake a Unix development environment)
compilation was complete at previous steps. Mingw isn't needed as webview.dll is all need besides crystal code.
in my experiments the step fails bit the directory lib/webview
was created, so require
works. If the directory isn't present though, sone more actions needed.
If shards install
fails, I'm stuck...
Problem you are encountering is due to postinstall
hook of shard.yml
. And you can easily ignore that step by passing --skip-postinstall
flag to shards install
.
shards install --skip-postinstall
OK. That worked.
However, I got the following error when trying to build the app:
crystal build src/app.cr .\lib\webview.lib
In lib\webview.lib:1:2
1 | !<arch>
^
Error: unexpected token: "<"
You have to do crystal build src/app.cr
, lib files cannot be passed to crystal compiler directly.
I am sorry, it doesn't seem to work:
PS C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\webview6\app> shards install --skip-postinstall
Resolving dependencies
Fetching https://github.com/naqvis/webview.git
Using webview (0.2.2)
PS C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\webview6\app> crystal build .\src\app.cr
LINK : fatal error LNK1181: cannot open input file 'webview.lib'
have you copied webview.lib on a previous step (copy webview\dll\x64\webview.lib to <your crystal installation>\lib
)?
Yes. It didn't work.
I have in the meantime started to build my own version of bindings between Webview (on one hand) and Crystal and V on the other hand.
I'll tell you if it works.
My guess is that that sort of bindings is subtitle and discussion about it can be confusing.
Still; I thank you for your time, your efforts and your help.
On Mon, Feb 13, 2023 at 10:12 PM kipar @.***> wrote:
have you copied webview.lib on a previous step (copy webview\dll\x64\webview.lib to
\lib)? — Reply to this email directly, view it on GitHub https://github.com/naqvis/webview/issues/20#issuecomment-1428690407, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKDDRQKPV76NUDXFHUSWLWXKPUDANCNFSM6AAAAAAUVECWCE . You are receiving this because you were mentioned.Message ID: @.***>
It works now, but the correct linking instruction (under Windows) for lib.cr seems to be:
@[Link(ldflags: "#{__DIR__}/webview.lib")]
With this instruction, webview.lib
is expected to reside along the code of the app (in ./src in our example)
instead of:
@[Link("webview")]
I guess, in order to use @[Link("webview")]
( rather than @[Link(ldflags: "#{__DIR__}/webview.lib")]
), webview.lib is supposed to be installed in some standard locations for libraries under Windows 10 or 11 (the equivalent of /usr/local/lib under Linux).
However, in my case, running the install.bat script from https://github.com/webview/webview/tree/master/script did build said library webview.lib locally, but did apparently not copy it to a (standard)location which would be accessible by default to Crystal via a simple @[Link("webview")] , this is basically why the shards install
fails and why I had to resort to the alternative : @[Link(ldflags: "#{__DIR__}/webview.lib")]
for Crystal to be able to access Webview.