Skip to content

Commit

Permalink
fix: distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Aug 8, 2024
1 parent 8024e00 commit 35787e7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ jobs:
- name: Create deployment package
run: |
ls -R target/
tar -czf screenpipe-${{ env.VERSION }}-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release screenpipe
mkdir -p screenpipe-${{ env.VERSION }}-${{ matrix.target }}/bin
mkdir -p screenpipe-${{ env.VERSION }}-${{ matrix.target }}/lib
cp target/${{ matrix.target }}/release/screenpipe screenpipe-${{ env.VERSION }}-${{ matrix.target }}/bin/
cp target/${{ matrix.target }}/release/libscreenpipe.dylib screenpipe-${{ env.VERSION }}-${{ matrix.target }}/lib/
tar -czf screenpipe-${{ env.VERSION }}-${{ matrix.target }}.tar.gz -C screenpipe-${{ env.VERSION }}-${{ matrix.target }} .
- name: Calculate SHA256
run: |
Expand Down
3 changes: 2 additions & 1 deletion Formula/screenpipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Screenpipe < Formula
depends_on "tesseract"

def install
bin.install "screenpipe"
bin.install "screenpipe"
lib.install "libscreenpipe.dylib"
end

test do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"ffmpeg/lib/libavutil.59.dylib",
"ffmpeg/lib/libffmpeg.7.dylib",
"ffmpeg/lib/libswresample.5.dylib",
"ffmpeg/lib/libswscale.8.dylib"
"ffmpeg/lib/libswscale.8.dylib",
"../../../../screenpipe-vision/lib/libscreenpipe.dylib"
],
"entitlements": "entitlements.plist",
"signingIdentity": "-",
Expand Down
15 changes: 13 additions & 2 deletions screenpipe-vision/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
use std::env;

#[cfg(target_os = "macos")]
fn main() {
println!("cargo:rustc-link-search=native=screenpipe-vision/lib");
println!("cargo:rustc-link-lib=dylib=ocr");
let destination = env::var("DESTINATION").unwrap_or_default();

if destination == "brew" {
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/../lib");
} else if destination == "tauri" {
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/../Frameworks");
} else {
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/../../screenpipe-vision/lib");
}

println!("cargo:rustc-link-lib=dylib=screenpipe");
}

#[cfg(not(target_os = "macos"))]
Expand Down
2 changes: 1 addition & 1 deletion screenpipe-vision/src/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use image::DynamicImage;
use std::ffi::CStr;
use std::os::raw::{c_char, c_uchar};

#[link(name = "ocr")]
#[link(name = "screenpipe")]
extern "C" {
fn perform_ocr(
image_data: *const c_uchar,
Expand Down
29 changes: 15 additions & 14 deletions screenpipe-vision/src/ocr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import Vision
public func performOCR(imageData: UnsafePointer<UInt8>, length: Int, width: Int, height: Int)
-> UnsafeMutablePointer<CChar>? {

print("Attempting to create image from raw data")
print("Image dimensions: \(width)x\(height)")
// print("Attempting to create image from raw data")
// print("Image dimensions: \(width)x\(height)")

guard let dataProvider = CGDataProvider(data: Data(bytes: imageData, count: length) as CFData)
else {
print("Failed to create CGDataProvider.")
// print("Failed to create CGDataProvider.")
return strdup("Error: Failed to create CGDataProvider")
}

Expand All @@ -30,11 +30,11 @@ public func performOCR(imageData: UnsafePointer<UInt8>, length: Int, width: Int,
intent: .defaultIntent
)
else {
print("Failed to create CGImage.")
// print("Failed to create CGImage.")
return strdup("Error: Failed to create CGImage")
}

print("CGImage created successfully.")
// print("CGImage created successfully.")

let semaphore = DispatchSemaphore(value: 0)
var ocrResult = ""
Expand All @@ -43,22 +43,22 @@ public func performOCR(imageData: UnsafePointer<UInt8>, length: Int, width: Int,
defer { semaphore.signal() }

if let error = error {
print("Error in text recognition request: \(error)")
// print("Error in text recognition request: \(error)")
ocrResult = "Error: \(error.localizedDescription)"
return
}

guard let observations = request.results as? [VNRecognizedTextObservation] else {
print("Failed to process image or no text found.")
// print("Failed to process image or no text found.")
ocrResult = "Error: Failed to process image or no text found"
return
}

print("Number of text observations: \(observations.count)")
// print("Number of text observations: \(observations.count)")

for (index, observation) in observations.enumerated() {
for (_, observation) in observations.enumerated() {
guard let topCandidate = observation.topCandidates(1).first else {
print("No top candidate for observation \(index)")
// print("No top candidate for observation \(index)")
continue
}
ocrResult += "\(topCandidate.string)\n"
Expand All @@ -69,10 +69,10 @@ public func performOCR(imageData: UnsafePointer<UInt8>, length: Int, width: Int,

let handler = VNImageRequestHandler(cgImage: cgImage, options: [:])
do {
print("Performing OCR...")
// print("Performing OCR...")
try handler.perform([request])
} catch {
print("Failed to perform OCR: \(error)")
// print("Failed to perform OCR: \(error)")
return strdup("Error: Failed to perform OCR - \(error.localizedDescription)")
}

Expand All @@ -81,6 +81,7 @@ public func performOCR(imageData: UnsafePointer<UInt8>, length: Int, width: Int,
return strdup(ocrResult.isEmpty ? "No text found" : ocrResult)
}

// swiftc -emit-library -o screenpipe-vision/lib/libocr.dylib screenpipe-vision/src/ocr.swift
// swiftc -emit-library -o screenpipe-vision/lib/libscreenpipe.dylib screenpipe-vision/src/ocr.swift

// or
// swiftc -emit-library -o /usr/local/lib/libocr.dylib screenpipe-vision/src/ocr.swift
// swiftc -emit-library -o /usr/local/lib/libscreenpipe.dylib screenpipe-vision/src/ocr.swift

0 comments on commit 35787e7

Please sign in to comment.