From aa232cc61653f509d791fa41b7f15e0ffc3f6693 Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Mon, 30 Oct 2023 16:30:58 -0400
Subject: [PATCH] Fix breakage due to JuliaLang/julia#51319

`cconvert` does not return an array anymore and cannot be used with `reinterpret`.
Fix to use the underlying `transcode` function directly,
which is also consistent with the `Cstring` version.
---
 deps/depsutils.jl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/deps/depsutils.jl b/deps/depsutils.jl
index 35ed1e12..73ae2946 100644
--- a/deps/depsutils.jl
+++ b/deps/depsutils.jl
@@ -64,8 +64,10 @@ function _preserveas!(dest::Vector{UInt8}, ::Type{Cstring}, x::AbstractString)
 end
 
 function _preserveas!(dest::Vector{UInt8}, ::Type{Cwstring}, x::AbstractString)
-    s = reinterpret(UInt8, Base.cconvert(Cwstring, x))
-    copyto!(resize!(dest, length(s)), s)
+    s = reinterpret(UInt8, transcode(Cwchar_t, String(x)))
+    len = length(s)
+    copyto!(resize!(dest, len + sizeof(Cwchar_t)), s)
+    dest[len + 1:len + sizeof(Cwchar_t)] .= 0
     return pointer(dest)
 end