2 single: Distributing Ring Application using Ring2EXE; Introduction
4 =============================================
5 Distributing Ring Applications using Ring2EXE
6 =============================================
8 In this chapter we will learn about distributing Ring applications.
10 Starting from Ring 1.6 we have a nice tool called Ring2EXE (Written in Ring itself)
12 Using Ring2EXE we can distribute applications quickly for Windows, Linux, macOS and Mobile devices
14 .. note:: We can use the Distribute Menu in the Ring Notepad application (More Easy)
17 pair: Distributing Ring Application using Ring2EXE; Using Ring2EXE
24 ring2exe filename.ring [Options]
26 This will set filename.ring as input to the program
28 The next files will be generated
32 filename.ringo (The Ring Object File - by Ring Compiler)
33 filename.c (The C Source code file
34 Contains the ringo file content
35 Will be generated by this program)
36 filename_buildvc.bat (Will be executed to build filename.c using Visual C/C++)
37 filename_buildgcc.bat (Will be executed to build filename.c using GNU C/C++)
38 filename_buildclang.bat (Will be executed to build filename.c using CLang C/C++)
39 filename.obj (Will be generated by the Visual C/C++ compiler)
40 filename.exe (Will ge generated by the Visual C/C++ Linker)
41 filename (Executable File - On Linux & MacOS X platforms)
44 pair: Distributing Ring Application using Ring2EXE; How Ring2EXE works?
49 At first the Ring compiler will be used to generate the Ring object file (*.ringo)
51 If we have a C compiler (optional), This object file will be embedded inside a C source code file
53 Then using the C compiler and the Ring library (Contains the Ring Virtual Machine) the executable file
57 If we don't have a C compiler, the Ring executable will be copied and renamed to your application name
59 And your Ring object file (*.ringo) will become ring.ringo to be executed at startup of the executable file.
61 So it's better and easy to have a C compiler on your machine to be used by Ring2EXE.
64 pair: Distributing Ring Application using Ring2EXE; Example
69 We have test.ring contains the next code
73 see "Hello, World!" + nl
75 To build th executable file for Windows, Linux or macOS
81 To run the program (Windows)
87 To run the program (Linux and macOS)
95 pair: Distributing Ring Application using Ring2EXE; Options
102 -keep : Don't delete Temp. Files
103 -static : Build Standalone Executable File
104 (Don't use ring.dll/ring.so/ring.dylib)
105 -gui : Build GUI Application (Hide the Console Window)
106 -dist : Prepare application for distribution
107 -allruntime : Include all libraries in distribution
108 -mobileqt : Prepare Qt Project to distribute Ring Application for Mobile
109 -noqt : Remove RingQt from distribution
110 -noallegro : Remove RingAllegro from distribution
111 -noopenssl : Remove RingOpenSSL from distribution
112 -nolibcurl : Remove RingLibCurl from distribution
113 -nomysql : Remove RingMySQL from distribution
114 -noodbc : Remove RingODBC from distribution
115 -nosqlite : Remove RingSQLite from distribution
116 -noopengl : Remove RingOpenGL from distribution
117 -nofreeglut : Remove RingFreeGLUT from distribution
118 -nolibzip : Remove RingLibZip from distribution
119 -noconsolecolors : Remove RingConsoleColors from distribution
120 -nomurmuhash : Remove RingMurmurHash from distribution
121 -nocruntime : Remove C Runtime from distribution
122 -qt : Add RingQt to distribution
123 -allegro : Add RingAllegro to distribution
124 -openssl : Add RingOpenSSL to distribution
125 -libcurl : Add RingLibCurl to distribution
126 -mysql : Add RingMySQL to distribution
127 -odbc : Add RingODBC to distribution
128 -sqlite : Add RingSQLite to distribution
129 -postgresql : Add RingPostgreSQL to distribution
130 -opengl : Add RingOpenGL to distribution
131 -freeglut : Add RingFreeGLUT to distribution
132 -libzip : Add RingLibZip to distribution
133 -libuv : Add RingLibuv to distribution
134 -consolecolors : Add RingConsoleColors to distribution
135 -murmurhash : Add RingMurmurHash to distribution
136 -cruntime : Add C Runtime to distribution
139 pair: Distributing Ring Application using Ring2EXE; Building standalone console application
141 Building standalone console application
142 =======================================
144 Using the "-static" option we can build executable console application
146 So we don't have to use ring.dll, ring.so or ring.dylib
148 This avoid only the need to Ring dynamic link library
150 If you are using another libraries, You will need to include it with your application.
154 ring2exe test.ring -static
158 pair: Distributing Ring Application using Ring2EXE; Distributing RingAllegro Applications
160 Distributing RingAllegro Applications
161 =====================================
163 We have test2.ring contains the next code
168 # Just a simple program to test Ring2EXE Tool!
171 load "gameengine.ring" # Give Control to the Game Engine
173 func main # Called by the Game Engine
175 oGame = New Game # Create the Game Object
177 title = "My First Game"
181 To build the executable file and prepare for distributing the Game
183 We use "-dist" option and "-allruntime" to include all libraries
187 ring2exe test2.ring -dist -allruntime
189 After executing the previous command
191 On Windows we will have : target/windows folder
193 On Linux we will have : target/linux folder
195 On macOS we will have : target/macos folder
197 The previous command will add all of the Ring runtime libraries to our distribution
199 But we may need only RingAllegro, So it's better to use the next command
203 ring2exe test2.ring -dist -allegro -cruntime
205 This will produce smaller size distribution and will avoid the runtime files that we don't need!
208 Also we could use the "-gui" option to hide the console window
210 So it's better to use the next command
214 ring2exe test2.ring -dist -gui -allegro -cruntime
217 pair: Distributing Ring Application using Ring2EXE; Distributing RingAllegro Applications
219 Distributing RingQt Applications
220 ================================
222 We have test3.ring contains the next code
226 # Just a simple program to test Ring2EXE Tool!
233 setwindowtitle("Hello, World!")
241 To build the executable file and prepare for distributing the GUI application
243 We use "-dist" option and "-allruntime" to include all libraries
247 ring2exe test3.ring -dist -allruntime
249 After executing the previous command
251 On Windows we will have : target/windows folder
253 On Linux we will have : target/linux folder
255 On macOS we will have : target/macos folder
257 The previous command will add all of the Ring runtime libraries to our distribution
259 But we may need only RingQt, So it's better to use the next command
263 ring2exe test3.ring -dist -qt -cruntime
265 This will produce smaller size distribution and will avoid the runtime files that we don't need!
267 Also we could use the "-gui" option to hide the console window
269 So it's better to use the next command
273 ring2exe test3.ring -dist -gui -qt -cruntime
276 pair: Distributing Ring Application using Ring2EXE; Distributing Applications for Mobile using RingQt
278 Distributing Applications for Mobile using RingQt
279 =================================================
281 To prepare a Qt project for your RingQt application (test3.ring) use the "-mobileqt" option
287 ring2exe test3.ring -dist -mobileqt
289 After executing the previous command, We will have the Qt project in target/mobile/qtproject folder
291 The main project file will be project.pro which we can open using the Qt Creator IDE.
293 Also we will have the resource file : project.qrc
295 Another important file is our C++ main file : main.cpp
299 pair: Distributing Ring Application using Ring2EXE; Building the Cards Game for Mobile using RingQt
301 Building the Cards Game for Mobile using RingQt
302 ===============================================
304 For a better example, consider building an Android package for the Cards game that comes with the
306 Ring language in this folder : ring/application/cards
308 The Cards game folder contains three files
310 cards.ring : The Game source code
312 cards.jpg : The image file used by the game
314 project.qrc : Resource file to be used with the Qt project
316 The resource file contains the next content
322 <file>cards.ringo</file>
323 <file>cards.jpg</file>
327 We have two files in the resource file
329 The first file is cards.ringo (The Ring Object File) and the second file is cards.jpg (The image file)
331 As a start, Ring2EXE will generate this resource file in target/mobile/qtproject/project.qrc
333 But this file will contains only cards.ringo (That Ring2EXE will generate by calling Ring compiler)
335 We need to update this resource file to add the image file : cards.jpg
337 After this update, we copy the resource file to the main application folder
339 So when we use Ring2EXE again, Our updated resource file will be used!
341 Now to build the cards game for Mobile
343 (1) Run the next command
347 ring2exe cards.ring -dist -mobileqt
349 (2) Open target/mobile/qtproject/project.pro using Qt creator
351 (3) Build and Run using Qt Creator
354 How the Cards game will find the image file ?
356 RingQt comes with a simple function : AppFile() that we can use to determine the files that we may
358 access on Desktop or Mobile platforms
360 The next code from cards.ring
364 mypic = new QPixmap(AppFile("cards.jpg"))
366 So all what you need is using AppFile() function around your image files!
369 pair: Distributing Ring Application using Ring2EXE; Building the Weight History Application for Mobile using RingQt
371 Building the Weight History Application for Mobile using RingQt
372 ===============================================================
374 Another example to distribute your application for Mobile Devices using Ring2EXE and Qt
376 consider building an Android package for the Weight History application that comes with the
378 Ring language in this folder : ring/application/weighthistory
380 The Weight History application folder contains four files
382 weighthistory.ring : The application source code
384 weighthistory.db : The SQLite database
386 project.qrc : The resource file for the Qt project
388 main.cpp : The main C++ source file for the Qt project
390 To build the Weight History application for Mobile
392 (1) Run the next command
396 ring2exe weighthistory.ring -dist -mobileqt
398 (2) Open target/mobile/qtproject/project.pro using Qt creator
400 (3) Build and Run using Qt Creator
402 The resource file (project.qrc) contains two files
408 <file>weighthistory.ringo</file>
409 <file>weighthistory.db</file>
413 The first file is weighthistory.ringo (Ring Object File - Generated by Ring2EXE by calling Ring compiler)
415 The database file : weighthistory.db
417 The main.cpp contains the next little update, To copy the database file from resources to a writable location
424 path3 = path+"/weighthistory.db";
425 QFile::copy(":/weighthistory.db",path3);
427 You will need to do this with database files only!
429 When we use Ring2EXE, the tool will check for project.qrc and main.cpp, if they exist then your updated
431 files will be used in target/mobile/qtproject instead of the default version generated by Ring2EXE
433 So Use Ring2EXE to generate these files, Then copy them to your application folder when you update them.
436 pair: Distributing Ring Application using Ring2EXE; Building the Form Designer for Mobile using RingQt
438 Building the Form Designer for Mobile using RingQt
439 ==================================================
441 To build the Form Designer application (ring/applications/formdesigner) for Mobile
443 (1) Run the next command
447 ring2exe formdesigner.ring -dist -mobileqt
449 (2) Open target/mobile/qtproject/project.pro using Qt creator
451 (3) Build and Run using Qt Creator
453 in the folder ring/application/formdesigner You will find the resource file : project.qrc
455 It will be used automatically by Ring2EXE
461 <file>formdesigner.ringo</file>
462 <file>image/allevents.png</file>
463 <file>image/checkbox.png</file>
464 <file>image/close.png</file>
465 <file>image/combobox.bmp</file>
466 <file>image/datepicker.bmp</file>
467 <file>image/dial.png</file>
468 <file>image/formdesigner.png</file>
469 <file>image/frame.png</file>
470 <file>image/grid.bmp</file>
471 <file>image/hyperlink.png</file>
472 <file>image/image.png</file>
473 <file>image/label.png</file>
474 <file>image/layout.png</file>
475 <file>image/lcdnumber.png</file>
476 <file>image/listview.png</file>
477 <file>image/lock.png</file>
478 <file>image/new.png</file>
479 <file>image/open.png</file>
480 <file>image/progressbar.png</file>
481 <file>image/project.png</file>
482 <file>image/pushbutton.png</file>
483 <file>image/radiobutton.png</file>
484 <file>image/save.png</file>
485 <file>image/saveas.png</file>
486 <file>image/select.png</file>
487 <file>image/slider.png</file>
488 <file>image/spinner.bmp</file>
489 <file>image/statusbar.png</file>
490 <file>image/tab.png</file>
491 <file>image/textarea.png</file>
492 <file>image/textfield.png</file>
493 <file>image/timer.png</file>
494 <file>image/toolbar.png</file>
495 <file>image/tree.bmp</file>
496 <file>image/videowidget.png</file>
497 <file>image/webview.png</file>
501 As we did in the Cards game, The Form Designer will use the AppFile() function to determine the
502 name of the Image files.
504 The next code from ring/applications/formdesigner/mainwindow/formdesignerview.ring
510 new qtoolbutton(win) {
511 setbtnimage(self,AppFile("image/new.png"))
512 setclickevent(Method(:NewAction))
513 settooltip("New File")
515 new qtoolbutton(win) {
516 setbtnimage(self,AppFile("image/open.png"))
517 setclickevent(Method(:OpenAction))
518 settooltip("Open File")
520 new qtoolbutton(win) {
521 setbtnimage(self,AppFile("image/save.png"))
522 setclickevent(Method(:SaveAction))
525 new qtoolbutton(win) {
526 setbtnimage(self,AppFile("image/saveas.png"))
527 setclickevent(Method(:SaveAsAction))
528 settooltip("Save As")
530 new qtoolbutton(win) {
531 setbtnimage(self,AppFile("image/close.png"))
532 setclickevent(Method(:ExitAction))
537 tool1 = win.addtoolbar("files") {
538 for x in aBtns { addwidget(x) addseparator() }
541 From this example, We know that we can use sub folders for images.
545 pair: Distributing Ring Application using Ring2EXE; Creating the Qt resource file using Folder2qrc
547 Creating the Qt resource file using Folder2qrc
548 ==============================================
550 When we have large RingQt project that contains a lot of images and files, We need to add these files
551 to the resource file ( *.qrc ) when distributing applications for Mobile devices.
553 Instead of adding these files one by one, Ring 1.6 comes with a simple tool that save our time, It's
560 folder2qrc formdesigner.ring
562 We determine the main source file while we are in the application folder, and Folder2qrc will check all
563 of the files in the current folder and sub folders, Then add them to the resource file after the
564 mainfile.ringo (In our example this will be formdesigner.ringo)
566 The output file will be : project.qrc
568 You can open it and remove the files that you don't need in the resources!
572 pair: Distributing Ring Application using Ring2EXE; Important Information about Ring2EXE
574 Important Information about Ring2EXE
575 ====================================
577 * Using Ring2EXE to prepare distribution will delete all of the files in the old distribution
579 for example, if you have target/windows folder then used
583 ring2exe test3.ring -dist -allruntime
585 The files in target/windows will be deleted before adding the files again
587 This is important when you prepare a distribution for Mobile devices
591 ring2exe test3.ring -dist -mobileqt
593 If you modified the resource file : project.qrc or the main file : main.cpp
595 Don't forget to copy them to the application folder!
597 So Ring2EXE can use the updated version if you tried the previous command again!
599 * Ring2EXE is written in Ring, and you can read the source code from
601 https://github.com/ring-lang/ring/blob/master/ring2exe/ring2exe.ring
603 * The libraries information are stored in a separated files, So these files can be updated in the future
604 automatically to support new libraries
606 https://github.com/ring-lang/ring/blob/master/ring2exe/libs