Skip to content

Commit

Permalink
Merge pull request #73 from http4s/71-refactor-glue-code-to-avoid-req…
Browse files Browse the repository at this point in the history
…uiring-lcurl

linking does not require explicit -lcurl anymore
  • Loading branch information
hnaderi authored Feb 9, 2023
2 parents 5843751 + 332ce55 commit d9ecad8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ThisBuild / nativeConfig ~= { c =>
.withLinkingOptions(c.linkingOptions :+ s"-L${vcpkgBaseDir}/installed/x64-windows/lib/")
} else c

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

ThisBuild / envVars ++= {
Expand Down
13 changes: 9 additions & 4 deletions curl/src/main/resources/scala-native/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ CURLcode org_http4s_curl_CURLMsg_data_result(CURLMsg *curlMsg) {
return curlMsg->data.result;
}

const char * const * org_http4s_curl_get_protocols(){
return curl_version_info(CURLVERSION_NOW) -> protocols;
const char * const * org_http4s_curl_get_protocols(curl_version_info_data *data){
return data -> protocols;
}

unsigned int org_http4s_curl_get_version_num(){
return curl_version_info(CURLVERSION_NOW) -> version_num;
unsigned int org_http4s_curl_get_version_num(curl_version_info_data *data){
return data -> version_num;
}

CURLversion org_http4s_curl_version_now(){
// This is the minimum version we need currently
return CURLVERSION_FIRST;
}

#endif // has_include
6 changes: 4 additions & 2 deletions curl/src/main/scala/org/http4s/curl/unsafe/CurlRuntime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ object CurlRuntime {

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

private lazy val versionData = libcurl.curl_version_info(libcurl.CURLVERSION_NOW())

/** curl version number encoded as hex 0xXXYYZZ
* see here https://everything.curl.dev/libcurl/api
*/
def curlVersionNumber: Int = libcurl.curl_version_number()
def curlVersionNumber: Int = libcurl.curl_version_number(versionData)

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

val all: ListBuffer[String] = ListBuffer.empty
var cur: Ptr[CString] = libcurl.curl_protocols_info()
var cur: Ptr[CString] = libcurl.curl_protocols_info(versionData)
while ((!cur).toLong != 0) {
all.addOne(fromCString(!cur).toLowerCase)
cur = cur + 1
Expand Down
13 changes: 11 additions & 2 deletions curl/src/main/scala/org/http4s/curl/unsafe/libcurl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ private[curl] object libcurl {

type CURLoption = CUnsignedInt

type CURLversion = CUnsignedInt

type curl_slist

type curl_version_info_data

type header_callback = CFuncPtr4[Ptr[CChar], CSize, CSize, Ptr[Byte], CSize]

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

def curl_version(): Ptr[CChar] = extern

def curl_version_info(age: CURLversion): Ptr[curl_version_info_data] = extern

def curl_global_init(flags: CLongInt): CURLcode = extern

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

@name("org_http4s_curl_get_protocols")
def curl_protocols_info(): Ptr[CString] = extern
def curl_protocols_info(data: Ptr[curl_version_info_data]): Ptr[CString] = extern

@name("org_http4s_curl_get_version_num")
def curl_version_number(): CInt = extern
def curl_version_number(data: Ptr[curl_version_info_data]): CInt = extern

@name("org_http4s_curl_version_now")
def CURLVERSION_NOW(): CURLversion = extern

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

Expand Down

0 comments on commit d9ecad8

Please sign in to comment.