Skip to content

Commit d9ecad8

Browse files
authored
Merge pull request #73 from http4s/71-refactor-glue-code-to-avoid-requiring-lcurl
linking does not require explicit -lcurl anymore
2 parents 5843751 + 332ce55 commit d9ecad8

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ThisBuild / nativeConfig ~= { c =>
2121
.withLinkingOptions(c.linkingOptions :+ s"-L${vcpkgBaseDir}/installed/x64-windows/lib/")
2222
} else c
2323

24-
platformOptions.withLinkingOptions(platformOptions.linkingOptions :+ "-lcurl")
24+
platformOptions
2525
}
2626

2727
ThisBuild / envVars ++= {

curl/src/main/resources/scala-native/curl.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ CURLcode org_http4s_curl_CURLMsg_data_result(CURLMsg *curlMsg) {
1414
return curlMsg->data.result;
1515
}
1616

17-
const char * const * org_http4s_curl_get_protocols(){
18-
return curl_version_info(CURLVERSION_NOW) -> protocols;
17+
const char * const * org_http4s_curl_get_protocols(curl_version_info_data *data){
18+
return data -> protocols;
1919
}
2020

21-
unsigned int org_http4s_curl_get_version_num(){
22-
return curl_version_info(CURLVERSION_NOW) -> version_num;
21+
unsigned int org_http4s_curl_get_version_num(curl_version_info_data *data){
22+
return data -> version_num;
23+
}
24+
25+
CURLversion org_http4s_curl_version_now(){
26+
// This is the minimum version we need currently
27+
return CURLVERSION_FIRST;
2328
}
2429

2530
#endif // has_include

curl/src/main/scala/org/http4s/curl/unsafe/CurlRuntime.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ object CurlRuntime {
6161

6262
def curlVersion: String = fromCString(libcurl.curl_version())
6363

64+
private lazy val versionData = libcurl.curl_version_info(libcurl.CURLVERSION_NOW())
65+
6466
/** curl version number encoded as hex 0xXXYYZZ
6567
* see here https://everything.curl.dev/libcurl/api
6668
*/
67-
def curlVersionNumber: Int = libcurl.curl_version_number()
69+
def curlVersionNumber: Int = libcurl.curl_version_number(versionData)
6870

6971
/** curl version number (major, minor, patch) */
7072
def curlVersionTriple: (Int, Int, Int) = (
@@ -76,7 +78,7 @@ object CurlRuntime {
7678
def protocols: List[String] = {
7779

7880
val all: ListBuffer[String] = ListBuffer.empty
79-
var cur: Ptr[CString] = libcurl.curl_protocols_info()
81+
var cur: Ptr[CString] = libcurl.curl_protocols_info(versionData)
8082
while ((!cur).toLong != 0) {
8183
all.addOne(fromCString(!cur).toLowerCase)
8284
cur = cur + 1

curl/src/main/scala/org/http4s/curl/unsafe/libcurl.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ private[curl] object libcurl {
100100

101101
type CURLoption = CUnsignedInt
102102

103+
type CURLversion = CUnsignedInt
104+
103105
type curl_slist
104106

107+
type curl_version_info_data
108+
105109
type header_callback = CFuncPtr4[Ptr[CChar], CSize, CSize, Ptr[Byte], CSize]
106110

107111
type write_callback = CFuncPtr4[Ptr[CChar], CSize, CSize, Ptr[Byte], CSize]
@@ -112,6 +116,8 @@ private[curl] object libcurl {
112116

113117
def curl_version(): Ptr[CChar] = extern
114118

119+
def curl_version_info(age: CURLversion): Ptr[curl_version_info_data] = extern
120+
115121
def curl_global_init(flags: CLongInt): CURLcode = extern
116122

117123
def curl_global_cleanup(): Unit = extern
@@ -143,10 +149,13 @@ private[curl] object libcurl {
143149
def curl_CURLMsg_data_result(curlMsg: Ptr[CURLMsg]): CURLcode = extern
144150

145151
@name("org_http4s_curl_get_protocols")
146-
def curl_protocols_info(): Ptr[CString] = extern
152+
def curl_protocols_info(data: Ptr[curl_version_info_data]): Ptr[CString] = extern
147153

148154
@name("org_http4s_curl_get_version_num")
149-
def curl_version_number(): CInt = extern
155+
def curl_version_number(data: Ptr[curl_version_info_data]): CInt = extern
156+
157+
@name("org_http4s_curl_version_now")
158+
def CURLVERSION_NOW(): CURLversion = extern
150159

151160
def curl_multi_add_handle(multi_handle: Ptr[CURLM], curl_handle: Ptr[CURL]): CURLMcode = extern
152161

0 commit comments

Comments
 (0)