Fix Swift runtime not being initialized on Linux

This commit is contained in:
Shadowfacts 2023-01-02 18:49:59 -05:00
parent 13076ab5b8
commit 149e009152
2 changed files with 9 additions and 9 deletions

View File

@ -11,8 +11,15 @@ fn main() {
target.paths.runtime_library_paths.iter().for_each(|path| { target.paths.runtime_library_paths.iter().for_each(|path| {
println!("cargo:rustc-link-arg=-Wl,-rpath={}", path); println!("cargo:rustc-link-arg=-Wl,-rpath={}", path);
}); });
// need to link against libswiftCore and libFoundation
// link in swiftrt.o, which initializes the swift runtime
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
println!(
"cargo:rustc-link-arg={}/linux/{}/swiftrt.o",
&target.paths.runtime_resource_path, arch
);
// link against the swift stdlib and all th supporting pieces
println!("cargo:rustc-link-lib=dylib=BlocksRuntime"); println!("cargo:rustc-link-lib=dylib=BlocksRuntime");
println!("cargo:rustc-link-lib=dylib=dispatch"); println!("cargo:rustc-link-lib=dylib=dispatch");
println!("cargo:rustc-link-lib=dylib=FoundationNetworking"); println!("cargo:rustc-link-lib=dylib=FoundationNetworking");
@ -59,6 +66,7 @@ pub struct SwiftTargetInfo {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SwiftPaths { pub struct SwiftPaths {
pub runtime_library_paths: Vec<String>, pub runtime_library_paths: Vec<String>,
pub runtime_resource_path: String,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]

View File

@ -7,15 +7,7 @@ public func highlight(codePtr: UnsafePointer<UInt8>, codeLen: UInt64, htmlLenPtr
let data = Data(buffer: buf) let data = Data(buffer: buf)
let code = String(data: data, encoding: .utf8)! let code = String(data: data, encoding: .utf8)!
print("a")
debugPrint(MyOutputFormat())
let highligher = SyntaxHighlighter(format: MyOutputFormat()) let highligher = SyntaxHighlighter(format: MyOutputFormat())
withUnsafePointer(to: highligher) { ptr in
debugPrint(UnsafeRawPointer(ptr))
}
print("b")
debugPrint(highligher)
debugPrint(code)
var html = highligher.highlight(code) var html = highligher.highlight(code)
let outPtr = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: html.utf8.count) let outPtr = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: html.utf8.count)
_ = html.withUTF8 { buf in _ = html.withUTF8 { buf in