From 5d70c7d079b71753329f0ac0b97b38e6e94493eb Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:05:03 +0100 Subject: [PATCH 1/9] feat: add windows support --- curl/build.vsh | 44 +++++++++++++++++++++++++++++++++++++++++++- curl/lib.v | 7 +++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/curl/build.vsh b/curl/build.vsh index 1cd83e5..ba18913 100755 --- a/curl/build.vsh +++ b/curl/build.vsh @@ -72,6 +72,38 @@ fn setup(silent bool) ! { } } +fn setup_windows(silent bool) ! { + dl_url := 'https://curl.se/windows/dl-8.11.0_1/curl-8.11.0_1-win64-mingw.zip' + dl_archive := dl_url.all_after_last('/') + extracted_dir := '${curl_mod_dir}/curl-8.11.0_1-win64-mingw' + + { + println('(1/2) Downloading...') + s := chan bool{cap: 1} + if !silent { + spawn spinner(s) + } + http.download_file(dl_url, '${curl_mod_dir}/${dl_archive}')! + s <- true + } + time.sleep(100 * time.millisecond) + + { + println('(2/2) Extracting...') + s := chan bool{cap: 1} + if !silent { + spawn spinner(s) + } + mkdir(dst_dir)! + execute_opt('powershell -command Expand-Archive -LiteralPath ${curl_mod_dir}/${dl_archive} -DestinationPath ${curl_mod_dir}')! + mv('${extracted_dir}/include', '${dst_dir}/include')! + mv('${extracted_dir}/bin/', '${dst_dir}/bin/')! + rmdir_all(extracted_dir) or {} + s <- true + } + time.sleep(100 * time.millisecond) +} + fn spinner(ch chan bool) { runes := [`-`, `\\`, `|`, `/`] mut pos := 0 @@ -115,7 +147,17 @@ mut cmd := cli.Command{ // TODO: build in temp then remove old and move new from temp. rmdir_all(dst_dir) or {} // Remove old library files. silent := cmd.flags.get_bool('silent')! - setup(silent)! + $if windows { + setup_windows(silent)! + defer { + // For now, don't automatically update the PATH, as it's easily corrupted and might cause annoyances on a user's machine. + println('\nOn Windows, libcurl requires access to a compatible curl.exe.') + println('A reliable way is to use the curl.exe that is shipped with every libcurl version.') + println("Add '${curl_mod_dir.replace('/', os.path_separator)}\\libcurl\\bin' to your PATH to make it accessible.") + } + } $else { + setup(silent)! + } println('\rFinished!') } } diff --git a/curl/lib.v b/curl/lib.v index 8626eb2..85cc75b 100644 --- a/curl/lib.v +++ b/curl/lib.v @@ -9,8 +9,11 @@ import instructions import state #flag -I@VMODROOT/curl/libcurl/include -#flag -L@VMODROOT/curl/libcurl -#flag -lcurl +#flag windows @VMODROOT/curl/libcurl/bin/libcurl-x64.dll +$if !windows { + #flag -L@VMODROOT/curl/libcurl + #flag -lcurl +} #include "curl/curl.h" pub type Handle = C.CURL From 351e0dd454ef7012967b11a97b5ac6698d4fcd5a Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:06:05 +0100 Subject: [PATCH 2/9] ci: add windows workflow --- .github/workflows/ci.yml | 3 ++ .github/workflows/windows.yml | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72205de..7e24220 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,3 +16,6 @@ jobs: macos: uses: ./.github/workflows/macos.yml + + windows: + uses: ./.github/workflows/windows.yml diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..b052bc5 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,55 @@ +name: CI + +on: + workflow_call: + +jobs: + setup: + runs-on: windows-latest + defaults: + run: + shell: bash + steps: + - name: Setup V + run: | + curl -LO https://github.com/vlang/v/releases/latest/download/v_windows.zip + 7z x v_windows.zip + mv v ~/v + ~/v/v symlink + - run: v -showcc self && v doctor + - uses: actions/checkout@v4 + with: + path: vibe + - name: Setup V module + run: | + mv vibe ~/.vmodules/vibe + v ~/.vmodules/vibe/curl/build.vsh --silent + - name: Save cache + uses: actions/cache/save@v4 + with: + path: | + ~/v + ~/.vmodules + key: ${{ runner.os }}-${{ github.sha }} + + test: + needs: setup + runs-on: windows-latest + env: + VFLAGS: -cg -cc gcc + steps: + - name: Restore cache + uses: actions/cache/restore@v4 + with: + path: | + ~/v + ~/.vmodules + key: ${{ runner.os }}-${{ github.sha }} + fail-on-cache-miss: true + - name: Setup V + run: ~/v/v symlink + - name: Run tests + shell: cmd + run: | + set PATH=%PATH%;%USERPROFILE%\.vmodules\vibe\curl\libcurl\bin + v test %USERPROFILE%\.vmodules\vibe From b8736e0815e0ae149e9b47e95344f4856c21a425 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:14:34 +0100 Subject: [PATCH 3/9] fix: add comptime workarounds for windows specific issues --- curl/instructions/easy.v | 6 +++++- src/_instructions_common.v | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/curl/instructions/easy.v b/curl/instructions/easy.v index 07c7b69..27151c4 100644 --- a/curl/instructions/easy.v +++ b/curl/instructions/easy.v @@ -27,7 +27,11 @@ pub fn easy_strerror(err_code state.Ecode) string { } pub fn easy_setopt[T](handle &C.CURL, option state.Opt, parameter T) state.Ecode { - return ecode(C.curl_easy_setopt(handle, int(option), parameter)) + $if T is string { + return ecode(C.curl_easy_setopt(handle, int(option), parameter.str)) + } $else { + return ecode(C.curl_easy_setopt(handle, int(option), parameter)) + } } pub fn easy_perform(handle &C.CURL) state.Ecode { diff --git a/src/_instructions_common.v b/src/_instructions_common.v index 7c2e733..8b00cf4 100644 --- a/src/_instructions_common.v +++ b/src/_instructions_common.v @@ -17,6 +17,10 @@ fn cleanup_() { } fn (req Request) set_common_opts(h &curl.Handle, url string, resp &VibeResponse) { + $if windows { + curl.easy_setopt(h, .ssl_verifypeer, 0) + curl.easy_setopt(h, .ssl_verifyhost, 0) + } if req.cookie_jar != '' { curl.easy_setopt(h, .cookiejar, req.cookie_jar) } From 55b1591191ba8e4b81b028fc909b59295fda2060 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:16:57 +0100 Subject: [PATCH 4/9] docs: prefix setup script with `v` for windows compatibility --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a67560..b7f2d09 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ higher-level API. - Setup development dependency ```sh - ~/.vmodules/vibe/curl/build.vsh + v ~/.vmodules/vibe/curl/build.vsh ``` ## Usage examples From 47bb2a414e5f03cef49c09de34e1374a6ea3beb2 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:19:03 +0100 Subject: [PATCH 5/9] chore!: rename build.vsh to setup.vsh as it's semantically more accurate since we do not "build" on windows. --- .github/workflows/linux.yml | 2 +- .github/workflows/macos.yml | 2 +- .github/workflows/windows.yml | 2 +- README.md | 2 +- curl/{build.vsh => setup.vsh} | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename curl/{build.vsh => setup.vsh} (99%) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 57f1212..d8a5b73 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -23,7 +23,7 @@ jobs: - name: Setup V module run: | mv vibe ~/.vmodules/vibe - ~/.vmodules/vibe/curl/build.vsh --silent + ~/.vmodules/vibe/curl/setup.vsh --silent - name: Save cache uses: actions/cache/save@v4 with: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 42f2c28..261f64d 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -24,7 +24,7 @@ jobs: - name: Setup V module run: | mv vibe ~/.vmodules/vibe - ~/.vmodules/vibe/curl/build.vsh --silent + ~/.vmodules/vibe/curl/setup.vsh --silent - name: Save cache uses: actions/cache/save@v4 with: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index b052bc5..9880d2a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -23,7 +23,7 @@ jobs: - name: Setup V module run: | mv vibe ~/.vmodules/vibe - v ~/.vmodules/vibe/curl/build.vsh --silent + v ~/.vmodules/vibe/curl/setup.vsh --silent - name: Save cache uses: actions/cache/save@v4 with: diff --git a/README.md b/README.md index b7f2d09..0f7d57e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ higher-level API. - Setup development dependency ```sh - v ~/.vmodules/vibe/curl/build.vsh + v ~/.vmodules/vibe/curl/setup.vsh ``` ## Usage examples diff --git a/curl/build.vsh b/curl/setup.vsh similarity index 99% rename from curl/build.vsh rename to curl/setup.vsh index ba18913..3530629 100755 --- a/curl/build.vsh +++ b/curl/setup.vsh @@ -127,7 +127,7 @@ fn spinner(ch chan bool) { } mut cmd := cli.Command{ - name: 'build.vsh' + name: 'setup.vsh' posix_mode: true required_args: 0 pre_execute: fn (cmd cli.Command) ! { From 33bf5e620b5306946347b638ba56c408897728b5 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:22:30 +0100 Subject: [PATCH 6/9] ci: test windows with optimizations --- .github/workflows/windows.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 9880d2a..9d0fa30 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -35,8 +35,10 @@ jobs: test: needs: setup runs-on: windows-latest - env: - VFLAGS: -cg -cc gcc + strategy: + matrix: + optimization: ['', '-W -cstrict'] + fail-fast: false steps: - name: Restore cache uses: actions/cache/restore@v4 @@ -52,4 +54,4 @@ jobs: shell: cmd run: | set PATH=%PATH%;%USERPROFILE%\.vmodules\vibe\curl\libcurl\bin - v test %USERPROFILE%\.vmodules\vibe + v -cg -cc gcc ${{ matrix.optimization }} -stats test %USERPROFILE%\.vmodules\vibe From 2fda6584f53a1ba48ff6b1ee91e21a2f8c5a246e Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:27:13 +0100 Subject: [PATCH 7/9] tmp: partial revert comptime generic change in setop to check compilation errors with cstrict --- curl/instructions/easy.v | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/curl/instructions/easy.v b/curl/instructions/easy.v index 27151c4..07c7b69 100644 --- a/curl/instructions/easy.v +++ b/curl/instructions/easy.v @@ -27,11 +27,7 @@ pub fn easy_strerror(err_code state.Ecode) string { } pub fn easy_setopt[T](handle &C.CURL, option state.Opt, parameter T) state.Ecode { - $if T is string { - return ecode(C.curl_easy_setopt(handle, int(option), parameter.str)) - } $else { - return ecode(C.curl_easy_setopt(handle, int(option), parameter)) - } + return ecode(C.curl_easy_setopt(handle, int(option), parameter)) } pub fn easy_perform(handle &C.CURL) state.Ecode { From 0c679fd7b375d61d54bd54302e563ca4160cca2d Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:29:35 +0100 Subject: [PATCH 8/9] revert: "tmp: partial revert comptime generic change in setop to check compilation errors with cstrict" - cast to &char This reverts commit 2fda6584f53a1ba48ff6b1ee91e21a2f8c5a246e. --- curl/instructions/easy.v | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/curl/instructions/easy.v b/curl/instructions/easy.v index 07c7b69..ba830a0 100644 --- a/curl/instructions/easy.v +++ b/curl/instructions/easy.v @@ -27,7 +27,11 @@ pub fn easy_strerror(err_code state.Ecode) string { } pub fn easy_setopt[T](handle &C.CURL, option state.Opt, parameter T) state.Ecode { - return ecode(C.curl_easy_setopt(handle, int(option), parameter)) + $if T is string { + return ecode(C.curl_easy_setopt(handle, int(option), &char(parameter.str))) + } $else { + return ecode(C.curl_easy_setopt(handle, int(option), parameter)) + } } pub fn easy_perform(handle &C.CURL) state.Ecode { From 37dc339aa42484bfb6b5a81bdc52b651982a6732 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:42:09 +0100 Subject: [PATCH 9/9] ci: disable cstrict optimization on gcc due to unrecognized re-exported enum --- .github/workflows/linux.yml | 7 ++++--- .github/workflows/windows.yml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index d8a5b73..a947684 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -42,10 +42,11 @@ jobs: matrix: os: [ubuntu-20.04, ubuntu-latest] cc: [tcc, gcc, clang] - optimization: ['', '-W -cstrict'] - exclude: - - cc: tcc + include: + - cc: clang optimization: '-W -cstrict' + - cc: gcc + optimization: '-W' fail-fast: false runs-on: ${{ matrix.os }} env: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 9d0fa30..2ee988c 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -37,7 +37,7 @@ jobs: runs-on: windows-latest strategy: matrix: - optimization: ['', '-W -cstrict'] + optimization: ['', '-W'] fail-fast: false steps: - name: Restore cache