Giter Club home page Giter Club logo

webview_rust's Introduction

webview

Discord Build Status

A tiny cross-platform webview library for C/C++ to build modern cross-platform GUIs.

The goal of the project is to create a common HTML5 UI abstraction layer for the most widely used platforms.

It supports two-way JavaScript bindings (to call JavaScript from C/C++ and to call C/C++ from JavaScript).

Note

Language binding for Go has moved. Versions <= 0.1.1 are available in this repository.

Platform Support

Platform Technologies
Linux GTK 3, WebKitGTK
macOS Cocoa, WebKit
Windows Windows API, WebView2

Documentation

The most up-to-date documentation is right in the source code. Improving the documentation is a continuous effort and you are more than welcome to contribute.

Prerequisites

Your compiler must support minimum C++11 except for platforms that require a more modern version.

Linux and BSD

The GTK and WebKit2GTK libraries are required for development and distribution. You need to check your package repositories regarding how to install those those.

Debian-based systems:

  • Packages:
    • Development: apt install libgtk-3-dev libwebkit2gtk-4.0-dev
    • Production: apt install libgtk-3-0 libwebkit2gtk-4.0-37

Fedora-based systems:

  • Packages:
    • Development: dnf install gtk3-devel webkit2gtk4.0-devel
    • Production: dnf install gtk3 webkit2gtk4.0

BSD-based systems:

  • FreeBSD packages: pkg install webkit2-gtk3
  • Execution on BSD-based systems may require adding the wxallowed option (see mount(8)) to your fstab to bypass W^X memory protection for your executable. Please see if it works without disabling this security feature first.

Windows

Your compiler must support C++14 and we recommend to pair it with an up-to-date Windows 10 SDK.

For Visual C++ we recommend Visual Studio 2022 or later. We have a separate section for MinGW-w64.

Developers and end-users must have the WebView2 runtime installed on their system for any version of Windows before Windows 11.

Getting Started

If you are a developer of this project then please go to the development section.

Instructions here are written for GCC when compiling C/C++ code using Unix-style command lines, and assumes that multiple commands are executed in the same shell session. Command lines for Windows use syntax specific to the Command shell but you can use any shell such as PowerShell as long as you adapt the commands accordingly. See the MinGW-w64 requirements when building on Windows.

You will have a working app but you are encouraged to explore the available examples and try the ones that go beyond the mere basics.

Start with creating a new directory structure for your project:

mkdir my-project && cd my-project
mkdir build libs "libs/webview"

Windows Preparation

The WebView2 SDK is required when compiling programs:

mkdir libs\webview2
curl -sSL "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2" | tar -xf - -C libs\webview2

If you wish to use the official WebView2 loader (WebView2Loader.dll) then grab a copy of the DLL (replace x64 with your target architecture):

copy /Y libs\webview2\build\native\x64\WebView2Loader.dll build

Note: See the WebView2 loader section for more options.

C/C++ Preparation

Fetch the webview library:

curl -sSLo "libs/webview/webview.h" "https://raw.githubusercontent.com/webview/webview/master/webview.h"
curl -sSLo "libs/webview/webview.cc" "https://raw.githubusercontent.com/webview/webview/master/webview.cc"

Getting Started with C++

Save the basic C++ example into your project directory:

curl -sSLo basic.cc "https://raw.githubusercontent.com/webview/webview/master/examples/basic.cc"

Build and run the example:

# Linux
g++ basic.cc -std=c++11 -Ilibs/webview $(pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0) -o build/basic && ./build/basic
# macOS
g++ basic.cc -std=c++11 -Ilibs/webview -framework WebKit -o build/basic && ./build/basic
# Windows/MinGW
g++ basic.cc -std=c++14 -mwindows -Ilibs/webview -Ilibs/webview2/build/native/include -ladvapi32 -lole32 -lshell32 -lshlwapi -luser32 -lversion -o build/basic.exe && "build/basic.exe"

Bonus for Visual C++

Build a C++ example:

cl basic.cc /std:c++14 /EHsc /Fobuild\ ^
    /I libs\webview ^
    /I libs\webview2\build\native\include ^
    /link /OUT:build\basic.exe

Getting Started with C

Save the basic C example into your project directory:

curl -sSLo basic.c "https://raw.githubusercontent.com/webview/webview/master/examples/basic.c"

Build the library and example, then run it:

# Linux
g++ -c libs/webview/webview.cc -std=c++11 -DWEBVIEW_STATIC $(pkg-config --cflags gtk+-3.0 webkit2gtk-4.0) -o build/webview.o
gcc -c basic.c -std=c99 -Ilibs/webview -o build/basic.o
g++ build/basic.o build/webview.o $(pkg-config --libs gtk+-3.0 webkit2gtk-4.0) -o build/basic && build/basic
# macOS
g++ -c libs/webview/webview.cc -std=c++11 -DWEBVIEW_STATIC -o build/webview.o
gcc -c basic.c -std=c99 -Ilibs/webview -o build/basic.o
g++ build/basic.o build/webview.o -framework WebKit -o build/basic && build/basic
# Windows/MinGW
g++ -c libs/webview/webview.cc -std=c++14 -DWEBVIEW_STATIC -Ilibs/webview2/build/native/include -o build/webview.o
gcc -c basic.c -std=c99 -Ilibs/webview -o build/basic.o
g++ build/basic.o build/webview.o -mwindows -ladvapi32 -lole32 -lshell32 -lshlwapi -luser32 -lversion -o build/basic.exe && "build/basic.exe"

Bonus for Visual C++

Build a shared library:

cl libs\webview\webview.cc /std:c++14 /EHsc /Fobuild\ ^
    /D WEBVIEW_BUILD_SHARED ^
    /I libs\webview ^
    /I libs\webview2\build\native\include ^
    /link /DLL /OUT:build\webview.dll

Build a C example using the shared library:

cl basic.c build\webview.lib /EHsc /Fobuild\ ^
    /D WEBVIEW_SHARED ^
    /I libs\webview ^
    /link /OUT:build\basic.exe

More Examples

The examples shown here are mere pieces of a bigger picture so we encourage you to try other examples and explore on your own—you can follow the same procedure. Please get in touch if you find any issues.

Compile-time Options

C API Linkage

Name Description
WEBVIEW_API Controls C API linkage, symbol visibility and whether it's a shared library. By default this is inline for C++ and extern for C.
WEBVIEW_BUILD_SHARED Modifies WEBVIEW_API for building a shared library.
WEBVIEW_SHARED Modifies WEBVIEW_API for using a shared library.
WEBVIEW_STATIC Modifies WEBVIEW_API for building or using a static library.

App Distribution

Distribution of your app is outside the scope of this library but we can give some pointers for you to explore.

macOS Application Bundle

On macOS you would typically create a bundle for your app with an icon and proper metadata.

A minimalistic bundle typically has the following directory structure:

example.app                 bundle
└── Contents
    ├── Info.plist          information property list
    ├── MacOS
    |   └── example         executable
    └── Resources
        └── example.icns    icon

Read more about the structure of bundles at the Apple Developer site.

Tip: The png2icns tool can create icns files from PNG files. See the icnsutils package for Debian-based systems.

Windows Apps

You would typically create a resource script file (*.rc) with information about the app as well as an icon. Since you should have MinGW-w64 readily available then you can compile the file using windres and link it into your program. If you instead use Visual C++ then look into the Windows Resource Compiler.

The directory structure could look like this:

my-project/
├── icons/
|   ├── application.ico
|   └── window.ico
├── basic.cc
└── resources.rc

resources.rc:

100 ICON "icons\\application.ico"
32512 ICON "icons\\window.ico"

Note: The ID of the icon resource to be used for the window must be 32512 (IDI_APPLICATION).

Compile:

windres -o build/resources.o resources.rc
g++ basic.cc build/resources.o [...]

Remember to bundle the DLLs you have not linked statically, e.g. those from MinGW-w64 and optionally WebView2Loader.dll.

MinGW-w64 Requirements

In order to build this library using MinGW-w64 on Windows then it must support C++14 and have an up-to-date Windows SDK.

Distributions that are known to be compatible:

MS WebView2 Loader

Linking the WebView2 loader part of the Microsoft WebView2 SDK is not a hard requirement when using our webview library, and neither is distributing WebView2Loader.dll with your app.

If, however, WebView2Loader.dll is loadable at runtime, e.g. from the executable's directory, then it will be used; otherwise our minimalistic implementation will be used instead.

Should you wish to use the official loader then remember to distribute it along with your app unless you link it statically. Linking it statically is possible with Visual C++ but not MinGW-w64.

Here are some of the noteworthy ways our implementation of the loader differs from the official implementation:

  • Does not support configuring WebView2 using environment variables such as WEBVIEW2_BROWSER_EXECUTABLE_FOLDER.
  • Microsoft Edge Insider (preview) channels are not supported.

The following compile-time options can be used to change how the library integrates the WebView2 loader:

  • WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL=<1|0> - Enables or disables the built-in implementation of the WebView2 loader. Enabling this avoids the need for WebView2Loader.dll but if the DLL is present then the DLL takes priority. This option is enabled by default.
  • WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK=<1|0> - Enables or disables explicit linking of WebView2Loader.dll. Enabling this avoids the need for import libraries (*.lib). This option is enabled by default if WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL is enabled.

Development

To build the library, examples and run tests, use one of the builds scripts in the script directory:

  • build.sh:

    • On Unix-based systems.
    • On Windows in a Unix-like environment such as MSYS2.
  • build.bat:

    • On Windows when building with Visual C++.

You can specify individual tasks on the command line for these scripts:

Task Description
info Displays information.
clean Cleans the build directory.
format Reformats code.
deps Fetches dependencies.
check Runs checks.
build Builds the library, examples and tests.
test Runs tests.

Additionally, the scripts accept the following environment variables.

Both scripts:

Variable Description
CI Changes behavior in CI environments (more strict).
TARGET_ARCH Target architecture for cross-compilation (x64, x86).
BUILD_DIR Overrides the path of the build directory.

Only build.sh:

Variable Description
HOST_OS Host operating system (linux, macos, windows).
TARGET_OS Target operating system for cross-compilation (see HOST_OS).
CC C compiler executable.
CXX C++ compiler executable.
LIB_PREFIX Library name prefix.
PKGCONFIG Alternative pkgconfig executable.

Cross-compilation

See the CI configuration for examples.

Limitations

Browser Features

Since a browser engine is not a full web browser it may not support every feature you may expect from a browser. If you find that a feature does not work as expected then please consult with the browser engine's documentation and open an issue if you think that the library should support it.

For example, the library does not attempt to support user interaction features like alert(), confirm() and prompt() and other non-essential features like console.log().

Bindings

Language Project
Bun tr1ckydev/webview-bun
C# webview/webview_csharp
C3 thechampagne/webview-c3
Crystal naqvis/webview
D thechampagne/webview-d
Deno webview/webview_deno
Go webview/webview_go
Harbour EricLendvai/Harbour_WebView
Haskell lettier/webviewhs
Janet janet-lang/webview
Java webview/webview_java
Kotlin Winterreisender/webviewko
Nim oskca/webview, neroist/webview
Node.js Winterreisender/webview-nodejs
Odin thechampagne/webview-odin
Pascal PierceNg/fpwebview
Python zserge/webview-python
PHP 0hr/php-webview
Ruby Maaarcocr/webview_ruby
Rust Boscop/web-view
Swift jakenvac/SwiftWebview
V malisipi/mui, ttytm/webview
Zig thechampagne/webview-zig

If you wish to add bindings to the list, feel free to submit a pull request or open an issue.

Generating Bindings

You can generate bindings for the library by yourself using the included SWIG interface (webview.i).

Here are some examples to get you started. Unix-style command lines are used for conciseness.

mkdir -p build/bindings/{python,csharp,java,ruby}
swig -c++ -python -outdir build/bindings/python -o build/bindings/python/python_wrap.cpp webview.i
swig -c++ -csharp -outdir build/bindings/csharp -o build/bindings/csharp/csharp_wrap.cpp webview.i
swig -c++ -java -outdir build/bindings/java -o build/bindings/java/java_wrap.cpp webview.i
swig -c++ -ruby -outdir build/bindings/ruby -o build/bindings/ruby/ruby_wrap.cpp webview.i

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.

webview_rust's People

Contributors

brettfo avatar carbotaniuman avatar eliassjogreen avatar github-actions[bot] avatar jbolda avatar lucasfernog avatar nothingismagick avatar rajivshah3 avatar tensor-programming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webview_rust's Issues

Fractional / HIDPI support (Windows)

Follow-up of webview/webview#54

In short, on Windows 10 (maybe 8 and 7, can't check), there is an option to use fractional resolutions for the interface (and all application), meaning that you can pick 100%, 125%, 150% 175%, 200% and so on.

The thing is, fractional pixels doesn't exists, where 100% and 200% are simple to implement since you just have to double the pixel's size (2x2 instead of 1x1), in-between values are more tricky.

Windows seems to rely on two different tricks to support those :

  1. Displaying properly "fractional" pixels using (unknown to me) wizardry .
  2. A fallback that render the software at a "normal" scaling (100%) and then upscale the output to the desired scaling (125%) resulting in blurry renders.

Tauri, per default, is using the 2nd trick, resulting in blurry applications :
Screenshot of the issue, with a top Windows which is Firefox displaying the application properly, and Tauri being blurred
Screenshot of the issue, with a top window which is Firefox displaying the application properly, and the bottom window a Tauri app being blurred

Steps to reproduce this behaviour:

  1. In the Windows 10's system settings, set the scaling to a fractional one.
  2. Start a Tauri project
  3. Build / Run dev
  4. See the blurriness

Thankfully, thanks to @Ciantic works, it seems to be pretty trivial to fix this issue, here is the solution provided by them : webview/webview#54 (comment)

Expose webview-official-sys crate

Is your feature request related to a problem? Please describe.
We are encountering some issues handling Webview rust wrapper types in a multithreaded environment while creating webview bindings for webview/webview_deno. We would like to have more control over the actual c_void pointers that currently are not exposed by the crate.

Describe the solution you'd like
sys bindings should be exported from the crate, or be made available in a separate crate.

Describe alternatives you've considered
Taking the code that we need directly for this repository, removing the dependency from webview_official (this crate). This approach is feasible but we think that the correct approach is to expose the bindings directly.

CC @eliassjogreen

WebView Abstraction Layer and Winit

To implement RFC#0001, there's two necessary changes, and one change that would shift more power to our side of the interop.

Bindings abstraction

This would take the form of a single Rust trait. Said trait will have the following properties:

  • Functions for all possible operations, including target-specific.
  • Associated constants Option<&'static str> for target_os and target_family, for build assertion purposes.
  • An initialization function that would take a Window Handle (and more?), and return Self.

This trait should be exposed via another crate, so bindings can be specified as a crate name or git repo. The bundler should then load the implementations appropriately. Tauri should provide a generic function. The bundler should worry about which implementation to pick for the target, the generated binary code should be target-specific.

Switch to zserge's Web View for Defaults

As per the RFC, we are moving away from Boscop. Boscop doesn't allow us to control the window, so this is a necessary step in this set of changes.

Winit

Currently, there are functionalities of Electron that we can't copy without controlling the window itself. Therefore, it's imperative that we have control, and I would have us use Winit to this end. Winit can provide a pointer to the raw Window Handle, and can handle most, if not all, of our window management needs. This would have the lovely side effect of providing more power to our Rust users, rather than letting responsibilities get moved into the web view's space.

Get events from window

Is your feature request related to a problem? Please describe.
I need to

  • get real file path when "drop file"

I want to

  • use custom drop area (e.g.: <div data-tauri-drag />)

Describe the solution you'd like
I want to create window using "winit" attach webview on it.
This might solve "drop file" issue https://github.com/tauri-apps/tauri/issues/993.

Describe alternatives you've considered
What I wanna do is,

  1. get real file path when "drop file"
  2. use custom drop area (e.g.: <div data-tauri-drag />)

Support for Apple Silicon/ARM on MacOS Big Sur

Describe the bug
When trying to build webview rust on MacOS with Apple Silicon/ARM the build script fails.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '.' (the project root)
  2. Run cargo build or cargo test
  3. See the error below
error: failed to run custom build command for `webview-official-sys v0.1.0 (/Users/byron/dev/webview_rust/webview-official-sys)`

Caused by:
  process didn't exit successfully: `/Users/byron/dev/webview_rust/target/debug/build/webview-official-sys-c458bcfd287ba625/build-script-build` (exit code: 1)
  --- stdout
  cargo:rustc-link-lib=framework=Cocoa
  cargo:rustc-link-lib=framework=WebKit
  cargo:rerun-if-changed=webview-official/webview.h
  cargo:rerun-if-changed=webview-official/webview.cc
  TARGET = Some("aarch64-apple-darwin")
  OPT_LEVEL = Some("0")
  HOST = Some("aarch64-apple-darwin")
  CXX_aarch64-apple-darwin = None
  CXX_aarch64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_aarch64-apple-darwin = None
  CXXFLAGS_aarch64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = None
  CXX_aarch64-apple-darwin = None
  CXX_aarch64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_aarch64-apple-darwin = None
  CXXFLAGS_aarch64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = None
  CXX_aarch64-apple-darwin = None
  CXX_aarch64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_aarch64-apple-darwin = None
  CXXFLAGS_aarch64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = None
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-I" "webview-official/webview.h" "-Wall" "-Wextra" "-std=c++11" "-w" "-o" "/Users/byron/dev/webview_rust/target/debug/build/webview-official-sys-2a67ef4fc041c24f/out/webview-official/webview.o" "-c" "webview-official/webview.cc"
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:576:10: error: no matching function for call to 'objc_msgSend'
  cargo:warning=  return objc_msgSend("NSString"_cls, "stringWithUTF8String:"_sel, s);
  cargo:warning=         ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:583:14: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    id app = objc_msgSend("NSApplication"_cls, "sharedApplication"_sel);
  cargo:warning=             ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:584:5: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    objc_msgSend(app, "setActivationPolicy:"_sel,
  cargo:warning=    ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:599:27: error: no matching function for call to 'objc_msgSend'
  cargo:warning=                          objc_msgSend(msg, "body"_sel), "UTF8String"_sel));
  cargo:warning=                          ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:604:21: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    auto delegate = objc_msgSend((id)cls, "new"_sel);
  cargo:warning=                    ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:611:18: error: no matching function for call to 'objc_msgSend'
  cargo:warning=      m_window = objc_msgSend("NSWindow"_cls, "alloc"_sel);
  cargo:warning=                 ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:612:18: error: no matching function for call to 'objc_msgSend'
  cargo:warning=      m_window = objc_msgSend(
  cargo:warning=                 ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 6 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:620:19: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    auto config = objc_msgSend("WKWebViewConfiguration"_cls, "new"_sel);
  cargo:warning=                  ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:622:17: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    m_webview = objc_msgSend("WKWebView"_cls, "alloc"_sel);
  cargo:warning=                ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:626:20: error: no matching function for call to 'objc_msgSend'
  cargo:warning=                   objc_msgSend("NSNumber"_cls, "numberWithBool:"_sel, 1),
  cargo:warning=                   ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:640:5: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    objc_msgSend(m_window, "setContentView:"_sel, m_webview);
  cargo:warning=    ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:641:5: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    objc_msgSend(m_window, "makeKeyAndOrderFront:"_sel, nullptr);
  cargo:warning=    ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:647:5: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    objc_msgSend("NSApp"_cls, "terminate:"_sel, nullptr);
  cargo:warning=    ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:650:14: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    id app = objc_msgSend("NSApplication"_cls, "sharedApplication"_sel);
  cargo:warning=             ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:651:22: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    dispatch([&]() { objc_msgSend(app, "activateIgnoringOtherApps:"_sel, 1); });
  cargo:warning=                     ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:652:5: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    objc_msgSend(app, "run"_sel);
  cargo:warning=    ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:664:18: error: no matching function for call to 'objc_msgSend'
  cargo:warning=                 objc_msgSend("NSString"_cls, "stringWithUTF8String:"_sel,
  cargo:warning=                 ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:673:5: error: no matching function for call to 'objc_msgSend'
  cargo:warning=    objc_msgSend(m_window, "setStyleMask:"_sel, style);
  cargo:warning=    ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=In file included from webview-official/webview.cc:3:
  cargo:warning=webview-official/webview.h:676:7: error: no matching function for call to 'objc_msgSend'
  cargo:warning=      objc_msgSend(m_window, "setContentMinSize:"_sel,
  cargo:warning=      ^~~~~~~~~~~~
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided
  cargo:warning=objc_msgSend(void /* id self, SEL op, ... */ )
  cargo:warning=^
  cargo:warning=fatal error: too many errors emitted, stopping now [-ferror-limit=]
  cargo:warning=20 errors generated.
  exit code: 1

  --- stderr

Expected behavior
The build should succeed.

If applicable, add screenshots to help explain your problem.

Platform and Versions (please complete the following information):

OS: MacOS 11.1 on Apple Silicon (M1)
Rustc: rustc 1.49.0-beta.4 (877c7cbe1 2020-12-10)

Additional context
In the file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/objc-api.h line 99 there is the following:

/* The arm64 ABI requires proper casting to ensure arguments are passed
 *  * correctly.  */
#if defined(__arm64__) && !__swift__
#   undef OBJC_OLD_DISPATCH_PROTOTYPES
#   define OBJC_OLD_DISPATCH_PROTOTYPES 0
#endif

It explains why explicitly setting the directive isn't effective there.

Maybe it's possible to use the actual signature, even though I can't tell what these are supposed to be by looking at the header :/.

Builder Pattern

Introduce builder pattern to instantiate the Webview instance which is the common and idiomatic approach in Rust.

Documentation

Add lint attributes #![warn(missing_doc)] to enforce all public interfaces have documentations.

CI

We need to revise this CI to avoid using the stuff from the old Tauri CI.

Seperate ffi module to a file or even become another `*-sys`

When creating FFI bindings, we usually will create another *-sys crate for the raw binding (which is what ffi module does right now). But I tend to know that it might be tedious to maintain two crates even it's not really necessary. Maybe it's also idiomatic to move it to a standalone file as sys module?

[Feature/Docs] Ability to Cross Compile From Linux to Windows & Mac

Is your feature request related to a problem? Please describe.
I prefer to build applications in Linux Docker containers for maximum automation, reproducibility, and build portability. That said, I still need to be able to build applications for Windows and Mac and I have since done that by cross compiling the application using MingW for windows and OSX Cross for Mac. Without being able to cross compile from Linux, you have to use a CI service that provides all three operating systems. While these exist, and they are free for Open Source projects, I prefer to be able to host these builds myself when necessary and the most cost effective and simple way to do that is by cross compiling from Linux.

Describe the solution you'd like
I would like to work out the required build steps and tools necessary to cross-compile for Windows and Mac from Linux.

Describe alternatives you've considered
Going with GitHub Actions for automated builds is definitely a decent option, but again, I prefer to be able to produce these same builds on my local machine and using Linux Docker containers is the most productive way to do that.

Additional context
If we get this working I am going to be building my Tauri application with Drone and could easily derive a template build that could be used for other's Tauri applications, allowing people to build for all three platforms using only Linux servers on either the public Drone cloud, or their own build farm.

bug: window titles are not showing up in macOS

Describe the bug
Titles in the webview window are not showing up in macOS when running examples in this repo.

To Reproduce
Run the examples in a macOS machine.

Expected behavior
The title "TEST" should appear in the top of this window.

Screenshots
Screenshot of window opened with the sample example:

Screenshot 2020-07-31 at 22 38 48

Platform and Versions (please complete the following information):

OS: 64bit Mac OS X 10.15.6 19G73
Rustc: rustc 1.45.0 (5c1f21c3b 2020-07-13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.