|
2 | 2 |
|
3 | 3 | echo "Building dynamic c library from Swift code..." |
4 | 4 |
|
5 | | -# Run the Swift package commands |
| 5 | +# 1. Clean and Build |
6 | 6 | swift package clean |
7 | 7 | swift package update |
8 | 8 | echo "Building Swift package..." |
9 | | -# Note: Windows requires the toolchain to be set up, which your YAML handles |
10 | 9 | swift build --configuration release --verbose |
11 | 10 |
|
12 | 11 | echo "Build completed. Locating artifacts..." |
13 | 12 |
|
14 | | -# Detect the operating system |
| 13 | +# 2. Detect OS and set Extension |
15 | 14 | if [[ "$OSTYPE" == "darwin"* ]]; then |
16 | 15 | echo "Detected macOS system..." |
17 | 16 | OS_DIR="macos" |
|
26 | 25 | EXT="so" |
27 | 26 | fi |
28 | 27 |
|
29 | | -# THE FIX: Search the entire .build folder for the library. |
30 | | -# Windows uses paths like .build/x86_64-unknown-windows-msvc/release/ |
| 28 | +# 3. DYNAMIC SEARCH |
| 29 | +# We search the whole .build folder because Windows/Linux use subfolders |
| 30 | +# like .build/x86_64-unknown-windows-msvc/release/ |
31 | 31 | echo "Searching for *LoopAlgorithmToPython.$EXT in .build directory..." |
32 | 32 | SOURCE_LIB=$(find .build -name "*LoopAlgorithmToPython.$EXT" | grep -i "release" | head -n 1) |
33 | 33 |
|
34 | 34 | if [ -z "$SOURCE_LIB" ] || [ ! -f "$SOURCE_LIB" ]; then |
35 | 35 | echo "ERROR: Could not find the compiled library!" |
36 | | - echo "Check above for Swift compiler errors." |
37 | | - echo "Current directory contents:" |
38 | | - ls -R .build 2>/dev/null | grep ":$" | head -n 20 |
| 36 | + echo "Check the Swift compiler logs above for errors." |
39 | 37 | exit 1 |
40 | 38 | fi |
41 | 39 |
|
42 | 40 | echo "Found library at: $SOURCE_LIB" |
43 | 41 |
|
44 | | -# Define destination |
| 42 | +# 4. Prepare Destination |
45 | 43 | DEST_DIR="./loop_to_python_api/dlibs/$OS_DIR" |
| 44 | +# On Windows, we ensure the output follows the 'lib...' naming convention for your Python API |
46 | 45 | DEST_LIB="$DEST_DIR/libLoopAlgorithmToPython.$EXT" |
47 | 46 |
|
48 | | -# Create destination directory |
49 | | -if [ ! -d "$DEST_DIR" ]; then |
50 | | - echo "Creating destination directory: $DEST_DIR" |
51 | | - mkdir -p "$DEST_DIR" |
52 | | -fi |
53 | | - |
54 | | -# Copy the library |
55 | | -echo "Copying library:" |
56 | | -echo " From: $SOURCE_LIB" |
57 | | -echo " To: $DEST_LIB" |
| 47 | +mkdir -p "$DEST_DIR" |
58 | 48 |
|
| 49 | +# 5. Copy and Verify |
| 50 | +echo "Copying to: $DEST_LIB" |
59 | 51 | if cp "$SOURCE_LIB" "$DEST_LIB"; then |
60 | 52 | echo "✓ Library successfully copied!" |
61 | 53 | ls -la "$DEST_LIB" |
|
0 commit comments