Skip to content

Commit 4fdaa86

Browse files
authored
Merge pull request #5652 from odin-lang/vendor/curl
`vendor:curl`
2 parents e72aad9 + 99d8d72 commit 4fdaa86

26 files changed

+9611
-0
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ jobs:
278278
sudo ./llvm.sh 18
279279
echo "/usr/lib/llvm-18/bin" >> $GITHUB_PATH
280280
281+
- name: Install libcurl
282+
run: |
283+
sudo apt-get install libcurl4-openssl-dev
284+
281285
- name: Build Odin
282286
run: ./build_odin.sh release
283287

tests/vendor/all.odin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ package tests_vendor
22

33
@(require) import "glfw"
44
@(require) import _ "lua/5.4"
5+
@(require) import _ "curl"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#+build windows, linux, darwin
2+
package test_vendor_curl
3+
4+
import "base:runtime"
5+
import "core:testing"
6+
import "vendor:curl"
7+
8+
@(test)
9+
test_curl :: proc(t: ^testing.T) {
10+
data_callback :: proc "c" (contents: [^]byte, size: int, nmemb: int, userp: rawptr) -> int {
11+
context = runtime.default_context()
12+
13+
real_size := size * nmemb
14+
memory := (^[dynamic]byte)(userp)
15+
16+
n := len(memory^)
17+
resize(memory, n + real_size)
18+
copy(memory[n:], contents[:real_size])
19+
20+
return real_size
21+
}
22+
23+
24+
curl.global_init(curl.GLOBAL_ALL)
25+
26+
c := curl.easy_init()
27+
testing.expect(t, c == nil, "curl.easy_init failed")
28+
29+
defer curl.easy_cleanup(c)
30+
31+
memory, memory_err := make([dynamic]byte)
32+
testing.expectf(t, memory_err == nil, "make failed: %v", memory_err)
33+
defer delete(memory)
34+
35+
curl.easy_setopt(c, .URL, cstring("https://odin-lang.org"))
36+
curl.easy_setopt(c, .WRITEFUNCTION, data_callback)
37+
curl.easy_setopt(c, .WRITEDATA, &memory)
38+
curl.easy_setopt(c, .USERAGENT, cstring("libcurl-agent/1.0"))
39+
40+
res := curl.easy_perform(c)
41+
testing.expectf(t, res == nil, "curl.easy_perform failed: %v", res)
42+
}

0 commit comments

Comments
 (0)