Skip to content

Commit

Permalink
feat: add windows support (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Nov 11, 2024
1 parent a3e6d76 commit d5c8c51
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ jobs:

macos:
uses: ./.github/workflows/macos.yml

windows:
uses: ./.github/workflows/windows.yml
9 changes: 5 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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/setup.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
strategy:
matrix:
optimization: ['', '-W']
fail-fast: false
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 -cg -cc gcc ${{ matrix.optimization }} -stats test %USERPROFILE%\.vmodules\vibe
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ higher-level API.
- Setup development dependency

```sh
~/.vmodules/vibe/curl/build.vsh
v ~/.vmodules/vibe/curl/setup.vsh
```

## Usage examples
Expand Down
6 changes: 5 additions & 1 deletion curl/instructions/easy.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions curl/lib.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 44 additions & 2 deletions curl/build.vsh → curl/setup.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -95,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) ! {
Expand All @@ -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!')
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/_instructions_common.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d5c8c51

Please sign in to comment.