11using System ;
22using System . IO ;
33using System . Net . Http ;
4- using System . Runtime . InteropServices ;
54using System . Threading . Tasks ;
5+ using System . Collections . Generic ;
66
77public class Setup
88{
@@ -11,103 +11,42 @@ static async Task Main(string[] args)
1111 const string baseUrl = "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v0.3.8" ;
1212 string powersyncCorePath = Path . Combine ( AppContext . BaseDirectory , "../../../../.." , "PowerSync/PowerSync.Common/" ) ;
1313
14- string rid = GetRuntimeIdentifier ( ) ;
15- string nativeDir = Path . Combine ( powersyncCorePath , "runtimes" , rid , "native" ) ;
16-
17- Directory . CreateDirectory ( nativeDir ) ;
18-
19- string sqliteCoreFilename = GetLibraryForPlatform ( ) ;
20- string sqliteCorePath = Path . Combine ( nativeDir , sqliteCoreFilename ) ;
14+ var runtimeIdentifiers = new Dictionary < string , ( string originalFile , string newFile ) >
15+ {
16+ { "osx-x64" , ( "libpowersync_x64.dylib" , "libpowersync.dylib" ) } ,
17+ { "osx-arm64" , ( "libpowersync_aarch64.dylib" , "libpowersync.dylib" ) } ,
18+ { "linux-x64" , ( "libpowersync_x64.so" , "libpowersync.so" ) } ,
19+ { "linux-arm64" , ( "libpowersync_aarch64.so" , "libpowersync.so" ) } ,
20+ { "win-x64" , ( "powersync_x64.dll" , "powersync.dll" ) }
21+ } ;
2122
22- try
23+ foreach ( var ( rid , ( originalFile , newFile ) ) in runtimeIdentifiers )
2324 {
24- await DownloadFile ( $ "{ baseUrl } /{ sqliteCoreFilename } ", sqliteCorePath ) ;
25+ string nativeDir = Path . Combine ( powersyncCorePath , "runtimes" , rid , "native" ) ;
26+ Directory . CreateDirectory ( nativeDir ) ;
2527
26- string newFileName = GetFileNameForPlatform ( ) ;
27- string newFilePath = Path . Combine ( nativeDir , newFileName ) ;
28+ string sqliteCorePath = Path . Combine ( nativeDir , originalFile ) ;
29+ string newFilePath = Path . Combine ( nativeDir , newFile ) ;
2830
29- if ( File . Exists ( sqliteCorePath ) )
31+ try
3032 {
31- File . Move ( sqliteCorePath , newFilePath , overwrite : true ) ;
32- Console . WriteLine ( $ "File renamed successfully from { sqliteCoreFilename } to { newFileName } ") ;
33+ await DownloadFile ( $ "{ baseUrl } /{ originalFile } ", sqliteCorePath ) ;
34+
35+ if ( File . Exists ( sqliteCorePath ) )
36+ {
37+ File . Move ( sqliteCorePath , newFilePath , overwrite : true ) ;
38+ Console . WriteLine ( $ "File renamed successfully from { originalFile } to { newFile } in { nativeDir } ") ;
39+ }
40+ else
41+ {
42+ throw new IOException ( $ "File { originalFile } does not exist.") ;
43+ }
3344 }
34- else
45+ catch ( Exception ex )
3546 {
36- throw new IOException ( $ "File { sqliteCoreFilename } does not exist. ") ;
47+ Console . Error . WriteLine ( $ "Error processing { rid } : { ex . Message } ") ;
3748 }
3849 }
39- catch ( Exception ex )
40- {
41- Console . Error . WriteLine ( $ "Error: { ex . Message } ") ;
42- Environment . Exit ( 1 ) ;
43- }
44- }
45-
46- static string GetRuntimeIdentifier ( )
47- {
48- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
49- {
50- if ( RuntimeInformation . ProcessArchitecture == Architecture . Arm64 )
51- return "osx-arm64" ;
52- else
53- return "osx-x64" ;
54- }
55- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
56- {
57- if ( RuntimeInformation . ProcessArchitecture == Architecture . Arm64 )
58- return "linux-arm64" ;
59- else
60- return "linux-x64" ;
61- }
62- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
63- {
64- return "win-x64" ;
65- }
66- throw new PlatformNotSupportedException ( "Unsupported platform." ) ;
67- }
68-
69- static string GetFileNameForPlatform ( )
70- {
71- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
72- {
73- return "libpowersync.dylib" ;
74- }
75- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
76- {
77- return "libpowersync.so" ;
78- }
79- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
80- {
81- return "powersync.dll" ;
82- }
83- else
84- {
85- throw new PlatformNotSupportedException ( "Unsupported platform." ) ;
86- }
87- }
88-
89- static string GetLibraryForPlatform ( )
90- {
91- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
92- {
93- return RuntimeInformation . ProcessArchitecture == Architecture . Arm64
94- ? "libpowersync_aarch64.dylib"
95- : "libpowersync_x64.dylib" ;
96- }
97- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
98- {
99- return RuntimeInformation . ProcessArchitecture == Architecture . Arm64
100- ? "libpowersync_aarch64.so"
101- : "libpowersync_x64.so" ;
102- }
103- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
104- {
105- return "powersync_x64.dll" ;
106- }
107- else
108- {
109- throw new PlatformNotSupportedException ( "Unsupported platform." ) ;
110- }
11150 }
11251
11352 static async Task DownloadFile ( string url , string outputPath )
0 commit comments