Skip to content

build: Add support building with msvc#59

Open
lygstate wants to merge 6 commits into
lvgl:masterfrom
lygstate:msvc
Open

build: Add support building with msvc#59
lygstate wants to merge 6 commits into
lvgl:masterfrom
lygstate:msvc

Conversation

@lygstate
Copy link
Copy Markdown

@lygstate lygstate commented May 10, 2026

        "-DCMAKE_PREFIX_PATH=C:/work/vcpkg/packages/zlib_x64-windows;C:/work/vcpkg/packages/curl_x64-windows;C:/work/vcpkg/packages/libffi_x64-windows;C:/work/vcpkg/packages/sdl2_x64-windows",
        "-DBUILD_LVGL_SIMULATOR=ON",
        "-DUSE_EXTERNAL_FFI=ON",
        "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>"

vcpkg install:

.\vcpkg.exe install curl zlib libffi sdl2 libffi:x64-windows-static

Summary by cubic

Add MSVC build support for Windows (simulator + vcpkg), update txiki to v26.4.0, and fix a style init bug. Also improves QuickJS and Windows compatibility for smoother cross-platform builds.

  • New Features

    • MSVC support: C++23 on MSVC (C++14 elsewhere), adds "/utf-8" and WIN32_LEAN_AND_MEAN; new BUILD_LVGL_SIMULATOR=ON flag with Makefile update; non‑MSVC simulator builds relax -Werror for unused-but-set variables.
    • Compatibility: centralized LVGL/QuickJS includes in src/render/native/lv_bindings_js.h; align QuickJS API usage (e.g., JS_IsArray without ctx, boolean literals, event handlers return JS_UNDEFINED); rename Arc to avoid a Windows name clash; remove zero-length ComponentClassFuncs arrays.
    • Dependencies: bump txiki to v26.4.0 and apply compile fixes.
  • Migration

    • Install with vcpkg: .\vcpkg.exe install curl zlib libffi sdl2 libffi:x64-windows-static
    • Example CMake: -DBUILD_LVGL_SIMULATOR=ON -DUSE_EXTERNAL_FFI=ON -DCMAKE_PREFIX_PATH=C:/work/vcpkg/packages/zlib_x64-windows;C:/work/vcpkg/packages/curl_x64-windows;C:/work/vcpkg/packages/libffi_x64-windows;C:/work/vcpkg/packages/sdl2_x64-windows -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>

Written for commit 632869f. Summary will update on new commits. Review in cubic

Closes: #57

lygstate added 5 commits May 10, 2026 16:32
…riable]

[build] /mnt/c/work/lvgl/lv_binding_js/deps/txiki/deps/libwebsockets/lib/system/async-dns/async-dns.c:801:27: error: variable ‘c’ set but not used [-Werror=unused-but-set-variable]
[build]   801 |         lws_adns_cache_t *c;
[build]       |                           ^
[build] cc1: all warnings being treated as errors
MSVC do not support for zero length array:

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 45 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/render/native/components/roller/roller_wrap.cpp">

<violation number="1" location="src/render/native/components/roller/roller_wrap.cpp:16">
P1: `argc >= 1` is too weak: `argv[1]` and `argv[2]` are accessed in the same condition, causing out-of-bounds reads when fewer than 3 arguments are passed.</violation>
</file>

<file name="src/render/native/components/line/line_wrap.cpp">

<violation number="1" location="src/render/native/components/line/line_wrap.cpp:17">
P2: Out-of-bounds argv access: checks `argc >= 1` but reads `argv[1]`, should be `argc >= 2`</violation>
</file>

<file name="src/render/native/components/calendar/calendar_wrap.cpp">

<violation number="1" location="src/render/native/components/calendar/calendar_wrap.cpp:16">
P2: Out-of-bounds read: `argc >= 1` insufficiently guards `argv[1]` access (should be `argc >= 2`)</violation>
</file>

<file name="src/render/native/components/dropdownlist/dropdownlist_wrap.cpp">

<violation number="1" location="src/render/native/components/dropdownlist/dropdownlist_wrap.cpp:16">
P1: Out-of-bounds argv access: condition checks `argc >= 1` but then reads `argv[1]` which requires at least 2 arguments. If `setItems` is called with only one argument, `JS_IsNumber(argv[1])` causes an out-of-bounds read and `JS_ToInt32(ctx, &item_len, argv[1])` reads garbage. The guard should be `argc >= 2`.</violation>
</file>

<file name="src/engine/hal/simulator/simulator.cpp">

<violation number="1" location="src/engine/hal/simulator/simulator.cpp:3">
P1: Wrapping `LV_IMG_DECLARE(mouse_cursor_icon)` in `extern "C"` creates a C-linkage reference, but `mouse_cursor_icon.c` is compiled with the C++ compiler in this build, so the definition will not match and linking can fail.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


static JSValue NativeCompSetOptions(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1]) && JS_IsBool(argv[2])) {
if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1]) && JS_IsBool(argv[2])) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: argc >= 1 is too weak: argv[1] and argv[2] are accessed in the same condition, causing out-of-bounds reads when fewer than 3 arguments are passed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/render/native/components/roller/roller_wrap.cpp, line 16:

<comment>`argc >= 1` is too weak: `argv[1]` and `argv[2]` are accessed in the same condition, causing out-of-bounds reads when fewer than 3 arguments are passed.</comment>

<file context>
@@ -13,7 +13,7 @@ WRAPPED_SCROLL_INTO_VIEW(Roller, "Roller")
 
 static JSValue NativeCompSetOptions(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
-    if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1]) && JS_IsBool(argv[2])) {
+    if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1]) && JS_IsBool(argv[2])) {
         COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, RollerClassID);
         std::vector<std::string> items;
</file context>
Suggested change
if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1]) && JS_IsBool(argv[2])) {
if (argc >= 3 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1]) && JS_IsBool(argv[2])) {


static JSValue NativeCompSetItems(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Out-of-bounds argv access: condition checks argc >= 1 but then reads argv[1] which requires at least 2 arguments. If setItems is called with only one argument, JS_IsNumber(argv[1]) causes an out-of-bounds read and JS_ToInt32(ctx, &item_len, argv[1]) reads garbage. The guard should be argc >= 2.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/render/native/components/dropdownlist/dropdownlist_wrap.cpp, line 16:

<comment>Out-of-bounds argv access: condition checks `argc >= 1` but then reads `argv[1]` which requires at least 2 arguments. If `setItems` is called with only one argument, `JS_IsNumber(argv[1])` causes an out-of-bounds read and `JS_ToInt32(ctx, &item_len, argv[1])` reads garbage. The guard should be `argc >= 2`.</comment>

<file context>
@@ -13,7 +13,7 @@ WRAPPED_SCROLL_INTO_VIEW(Dropdownlist, "Dropdownlist")
 
 static JSValue NativeCompSetItems(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
-    if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
+    if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
         COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, DropdownlistClassID);
         std::vector<std::string> items;
</file context>
Suggested change
if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
if (argc >= 2 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {

Comment on lines +3 to +7
extern "C" {

LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Wrapping LV_IMG_DECLARE(mouse_cursor_icon) in extern "C" creates a C-linkage reference, but mouse_cursor_icon.c is compiled with the C++ compiler in this build, so the definition will not match and linking can fail.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/engine/hal/simulator/simulator.cpp, line 3:

<comment>Wrapping `LV_IMG_DECLARE(mouse_cursor_icon)` in `extern "C"` creates a C-linkage reference, but `mouse_cursor_icon.c` is compiled with the C++ compiler in this build, so the definition will not match and linking can fail.</comment>

<file context>
@@ -1,5 +1,11 @@
 #include "./simulator.hpp"
 
+extern "C" {
+
+LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
</file context>
Suggested change
extern "C" {
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
}
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were wrong about mouse_cursor_icon.c, the compiler for mouse_cursor_icon.c is default to c, that's why I use
extern "C"


static JSValue NativeCompSetPoints(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Out-of-bounds argv access: checks argc >= 1 but reads argv[1], should be argc >= 2

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/render/native/components/line/line_wrap.cpp, line 17:

<comment>Out-of-bounds argv access: checks `argc >= 1` but reads `argv[1]`, should be `argc >= 2`</comment>

<file context>
@@ -14,7 +14,7 @@ WRAPPED_SCROLL_INTO_VIEW(Line, "Line")
 
 static JSValue NativeCompSetPoints(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
-    if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
+    if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
         COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, LineClassID);
 
</file context>
Suggested change
if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
if (argc >= 2 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {


static JSValue NativeCompSetHightLights(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Out-of-bounds read: argc >= 1 insufficiently guards argv[1] access (should be argc >= 2)

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/render/native/components/calendar/calendar_wrap.cpp, line 16:

<comment>Out-of-bounds read: `argc >= 1` insufficiently guards `argv[1]` access (should be `argc >= 2`)</comment>

<file context>
@@ -13,7 +13,7 @@ WRAPPED_SCROLL_INTO_VIEW(Calendar, "Calendar")
 
 static JSValue NativeCompSetHightLights(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
-    if (argc >= 1 && JS_IsArray(ctx, argv[0]) && JS_IsNumber(argv[1])) {
+    if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
         COMP_REF* ref = (COMP_REF*)JS_GetOpaque(this_val, CalendarClassID);
 
</file context>
Suggested change
if (argc >= 1 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {
if (argc >= 2 && JS_IsArray(argv[0]) && JS_IsNumber(argv[1])) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cubic-dev-ai Please check the agrc check in whole code-base, I am not touching about argc changes, that's should belongs to separate MR, can you automatically create that MR for me?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lygstate Fix with cubic is available during trial and on the Pro plan. Upgrade your plan to use this feature. https://www.cubic.dev/settings?tab=subscription

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add msvc support by upgrading txiki and other deps

1 participant