skiptools / skip-c-demo

Demonstration of using SkipFFI to create a shared C library for iOS and Android NDK
GNU Lesser General Public License v3.0
1 stars 2 forks source link

Step by step instructions? #1

Open bryanaamot opened 1 month ago

bryanaamot commented 1 month ago

Any chance we could get step by step instruction on how to use this project? I tried swift build then imported the SPM into a project. But when I import SkipCDemo it says Missing required module 'LibCLibrary'. I see the CMakeLists.txt, but don't know if I should run cmake . or what. A step by step instruction would be nice even for a 35+ year veteran developer like myself. I'm very hopeful for this effort and interested in contributing.

bryanaamot commented 1 month ago

I created some example steps that worked for me. Prior to doing this I was trying to include the skip-demo-main SPM in my project because I didn't understand that I only needed to include the LibCLibrary. Duh!

  1. Copy LibCLibrary folder into your project's Sources directory

  2. In your Package.swift file, add the following to the products array:

        .library(name: "LibCLibrary", type: .dynamic, targets: ["LibCLibrary"]),
  3. Add the following to the dependencies array (if not already there):

        .package(url: "https://source.skip.tools/skip-unit.git", from: "0.7.0"),
  4. Add the following to the targets array:

        .target(name: "LibCLibrary", dependencies: [
            .product(name: "SkipUnit", package: "skip-unit")
        ], sources: ["src"], publicHeadersPath: "include", plugins: [.plugin(name: "skipstone", package: "skip")]),
  5. In your source code, add

    
    #if !SKIP
    import LibCLibrary
    #endif

if !SKIP

let string = LibCLibrary.demo_string()
let text = String(cString: string!)
Text("\(text)")

endif