Skip to content

Commit cfcd796

Browse files
committed
Fix build windows dll file build script
1 parent 03286f2 commit cfcd796

1 file changed

Lines changed: 33 additions & 88 deletions

File tree

build.sh

Lines changed: 33 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,50 @@
22

33
echo "Building dynamic c library from Swift code..."
44

5-
# Run the Swift package commands to build the dynamic c library
5+
# Run the Swift package commands
66
swift package clean
77
swift package update
88
echo "Building Swift package..."
9+
# Note: Windows requires the toolchain to be set up, which your YAML handles
910
swift build --configuration release --verbose
1011

11-
echo "Build completed. Checking build output..."
12-
13-
# Check if build directory exists
14-
if [ ! -d ".build/release/" ]; then
15-
echo "ERROR: No .build/release directory found!"
16-
echo "Available .build directories:"
17-
ls -la .build/ 2>/dev/null || echo "No .build directory found at all"
18-
exit 1
19-
fi
20-
21-
echo "Files in .build/release/:"
22-
ls -la .build/release/ 2>/dev/null || echo "No .build/release directory found"
23-
24-
# Also check for any library files specifically
25-
echo "Looking for library files in .build/release/:"
26-
find .build/release/ -name "*Loop*" -o -name "*.dylib" -o -name "*.so" -o -name "*.dll" 2>/dev/null || echo "No library files found"
27-
28-
# Detect the operating system and set the library paths
29-
echo "Detected OSTYPE: $OSTYPE"
30-
echo "Detected OS: $(uname -s 2>/dev/null || echo 'unknown')"
12+
echo "Build completed. Locating artifacts..."
3113

14+
# Detect the operating system
3215
if [[ "$OSTYPE" == "darwin"* ]]; then
3316
echo "Detected macOS system..."
34-
SOURCE_LIB=".build/release/libLoopAlgorithmToPython.dylib"
35-
DEST_LIB="./loop_to_python_api/dlibs/macos/libLoopAlgorithmToPython.dylib"
36-
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
37-
echo "Detected Linux system. Searching for library files..."
38-
# Linux: Swift might generate different library names/paths
39-
# Check for possible library names
40-
if [ -f ".build/release/libLoopAlgorithmToPython.so" ]; then
41-
SOURCE_LIB=".build/release/libLoopAlgorithmToPython.so"
42-
echo "Found library: $SOURCE_LIB"
43-
elif [ -f ".build/release/LoopAlgorithmToPython.so" ]; then
44-
SOURCE_LIB=".build/release/LoopAlgorithmToPython.so"
45-
echo "Found library: $SOURCE_LIB"
46-
elif [ -f ".build/release/libLoopAlgorithmToPython" ]; then
47-
SOURCE_LIB=".build/release/libLoopAlgorithmToPython"
48-
echo "Found library (no extension): $SOURCE_LIB"
49-
else
50-
echo "ERROR: Could not find Linux library file!"
51-
echo "Searched for:"
52-
echo " - .build/release/libLoopAlgorithmToPython.so"
53-
echo " - .build/release/LoopAlgorithmToPython.so"
54-
echo " - .build/release/libLoopAlgorithmToPython"
55-
echo ""
56-
echo "Available files in .build/release/:"
57-
ls -la .build/release/ 2>/dev/null || echo "Directory not accessible"
58-
echo ""
59-
echo "All library-like files found:"
60-
find .build/release/ -name "*Loop*" -o -name "*.so" -o -name "*.a" -o -name "lib*" 2>/dev/null || echo "No library files found"
61-
echo ""
62-
echo "Swift build might have failed or generated different output on Linux."
63-
exit 1
64-
fi
65-
DEST_LIB="./loop_to_python_api/dlibs/linux/libLoopAlgorithmToPython.so"
66-
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]] || [[ "$(uname -s 2>/dev/null)" == MINGW* ]] || [[ "$OS" == "Windows_NT" ]]; then
67-
echo "Detected Windows system. Searching for library files..."
68-
# Windows: Swift might generate different library names/paths
69-
if [ -f ".build/release/libLoopAlgorithmToPython.dll" ]; then
70-
SOURCE_LIB=".build/release/libLoopAlgorithmToPython.dll"
71-
echo "Found library: $SOURCE_LIB"
72-
elif [ -f ".build/release/LoopAlgorithmToPython.dll" ]; then
73-
SOURCE_LIB=".build/release/LoopAlgorithmToPython.dll"
74-
echo "Found library: $SOURCE_LIB"
75-
else
76-
echo "ERROR: Could not find Windows library file!"
77-
echo "Searched for:"
78-
echo " - .build/release/libLoopAlgorithmToPython.dll"
79-
echo " - .build/release/LoopAlgorithmToPython.dll"
80-
echo ""
81-
echo "Available files in .build/release/:"
82-
ls -la .build/release/ 2>/dev/null || echo "Directory not accessible"
83-
echo ""
84-
echo "All library-like files found:"
85-
find .build/release/ -name "*Loop*" -o -name "*.dll" -o -name "*.a" -o -name "lib*" 2>/dev/null || echo "No library files found"
86-
echo ""
87-
echo "Swift build might have failed or generated different output on Windows."
88-
exit 1
89-
fi
90-
DEST_LIB="./loop_to_python_api/dlibs/windows/libLoopAlgorithmToPython.dll"
17+
OS_DIR="macos"
18+
EXT="dylib"
19+
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OS" == "Windows_NT" ]]; then
20+
echo "Detected Windows system..."
21+
OS_DIR="windows"
22+
EXT="dll"
9123
else
92-
echo "Unsupported operating system: $OSTYPE"
24+
echo "Detected Linux system..."
25+
OS_DIR="linux"
26+
EXT="so"
27+
fi
28+
29+
# THE FIX: Search the entire .build folder for the library.
30+
# Windows uses paths like .build/x86_64-unknown-windows-msvc/release/
31+
echo "Searching for *LoopAlgorithmToPython.$EXT in .build directory..."
32+
SOURCE_LIB=$(find .build -name "*LoopAlgorithmToPython.$EXT" | grep -i "release" | head -n 1)
33+
34+
if [ -z "$SOURCE_LIB" ] || [ ! -f "$SOURCE_LIB" ]; then
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
9339
exit 1
9440
fi
9541

96-
# Create destination directory if it doesn't exist
97-
DEST_DIR=$(dirname "$DEST_LIB")
42+
echo "Found library at: $SOURCE_LIB"
43+
44+
# Define destination
45+
DEST_DIR="./loop_to_python_api/dlibs/$OS_DIR"
46+
DEST_LIB="$DEST_DIR/libLoopAlgorithmToPython.$EXT"
47+
48+
# Create destination directory
9849
if [ ! -d "$DEST_DIR" ]; then
9950
echo "Creating destination directory: $DEST_DIR"
10051
mkdir -p "$DEST_DIR"
@@ -107,14 +58,8 @@ echo " To: $DEST_LIB"
10758

10859
if cp "$SOURCE_LIB" "$DEST_LIB"; then
10960
echo "✓ Library successfully copied!"
110-
echo "Final library info:"
11161
ls -la "$DEST_LIB"
11262
else
11363
echo "✗ Failed to copy the library!"
114-
echo "Source file info:"
115-
ls -la "$SOURCE_LIB" 2>/dev/null || echo "Source file does not exist or is not accessible"
116-
echo "Available files in .build/release/:"
117-
ls -la .build/release/ 2>/dev/null || echo "No build output found"
11864
exit 1
119-
fi
120-
65+
fi

0 commit comments

Comments
 (0)