diff --git a/build.rs b/build.rs index 5366b21..28ce27f 100644 --- a/build.rs +++ b/build.rs @@ -9,11 +9,33 @@ fn main() { if target.target.unversioned_triple.contains("linux") { // include the swift runtime library path in the rpath 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 - println!("cargo:rustc-link-lib=dylib=swiftCore"); + + println!("cargo:rustc-link-lib=dylib=BlocksRuntime"); + println!("cargo:rustc-link-lib=dylib=dispatch"); + println!("cargo:rustc-link-lib=dylib=FoundationNetworking"); println!("cargo:rustc-link-lib=dylib=Foundation"); + println!("cargo:rustc-link-lib=dylib=FoundationXML"); + println!("cargo:rustc-link-lib=dylib=icudataswift"); + println!("cargo:rustc-link-lib=dylib=icui18nswift"); + println!("cargo:rustc-link-lib=dylib=icuucswift"); + println!("cargo:rustc-link-lib=dylib=_InternalSwiftScan"); + println!("cargo:rustc-link-lib=dylib=_InternalSwiftStaticMirror"); + println!("cargo:rustc-link-lib=dylib=_InternalSwiftSyntaxParser"); + println!("cargo:rustc-link-lib=dylib=swift_Concurrency"); + println!("cargo:rustc-link-lib=dylib=swiftCore"); + println!("cargo:rustc-link-lib=dylib=swift_Differentiation"); + println!("cargo:rustc-link-lib=dylib=swiftDispatch"); + println!("cargo:rustc-link-lib=dylib=swiftDistributed"); + println!("cargo:rustc-link-lib=dylib=swiftGlibc"); + println!("cargo:rustc-link-lib=dylib=swiftRegexBuilder"); + println!("cargo:rustc-link-lib=dylib=swift_RegexParser"); + println!("cargo:rustc-link-lib=dylib=swiftRemoteMirror"); + println!("cargo:rustc-link-lib=dylib=swift_StringProcessing"); + println!("cargo:rustc-link-lib=dylib=swiftSwiftOnoneSupport"); + println!("cargo:rustc-link-lib=dylib=XCTest"); } } @@ -72,6 +94,7 @@ pub fn link_swift() { pub fn link_swift_package(package_name: &str, package_root: &str) { let profile = env::var("PROFILE").unwrap(); + dbg!(&profile); if !Command::new("swift") .args(&["build", "-c", &profile]) diff --git a/highlight-swift/Sources/highlight-swift/highlight_swift.swift b/highlight-swift/Sources/highlight-swift/highlight_swift.swift index f15ef8d..f72a27d 100644 --- a/highlight-swift/Sources/highlight-swift/highlight_swift.swift +++ b/highlight-swift/Sources/highlight-swift/highlight_swift.swift @@ -2,19 +2,27 @@ import Foundation import Splash @_cdecl("highlight_swift") -public func highlight(codePtr: UnsafePointer, codeLen: UInt64, htmlLenPtr: UnsafeMutablePointer) -> UnsafeMutableRawPointer { +public func highlight(codePtr: UnsafePointer, codeLen: UInt64, htmlLenPtr: UnsafeMutablePointer) -> UnsafeMutablePointer { let buf = UnsafeBufferPointer(start: codePtr, count: Int(codeLen)) let data = Data(buffer: buf) let code = String(data: data, encoding: .utf8)! + print("a") + debugPrint(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) let outPtr = UnsafeMutableBufferPointer.allocate(capacity: html.utf8.count) _ = html.withUTF8 { buf in buf.copyBytes(to: outPtr, count: buf.count) } - htmlLenPtr.pointee = UInt64(html.utf8.count) - return UnsafeMutableRawPointer(outPtr.baseAddress!) + htmlLenPtr.pointee = UInt64(outPtr.count) + return outPtr.baseAddress! } struct MyOutputFormat: OutputFormat { @@ -119,4 +127,3 @@ extension StringProtocol { }) } } - diff --git a/highlight-swift/Tests/LinuxMain.swift b/highlight-swift/Tests/LinuxMain.swift index 4f390b0..eccd4c7 100644 --- a/highlight-swift/Tests/LinuxMain.swift +++ b/highlight-swift/Tests/LinuxMain.swift @@ -1,4 +1,5 @@ import XCTest +@testable import highlight_swift_tests XCTMain([ testCase(HighlightTests.allTests), diff --git a/highlight-swift/Tests/highlight-swift-tests/HighlightTests.swift b/highlight-swift/Tests/highlight-swift-tests/HighlightTests.swift index c5518cb..578e926 100644 --- a/highlight-swift/Tests/highlight-swift-tests/HighlightTests.swift +++ b/highlight-swift/Tests/highlight-swift-tests/HighlightTests.swift @@ -21,8 +21,7 @@ class HighlightTests: XCTestCase { highlight(codePtr: codePtr.baseAddress!, codeLen: UInt64(codePtr.count), htmlLenPtr: lenPtr) } } - let start = UnsafePointer(result.assumingMemoryBound(to: UInt8.self)) - let htmlPtr = UnsafeBufferPointer(start: start, count: Int(len)) + let htmlPtr = UnsafeBufferPointer(start: result, count: Int(len)) let data = Data(buffer: htmlPtr) let expected = "1+1" XCTAssertEqual(String(data: data, encoding: .utf8), expected)