Cross-platform C SDK logo

Cross-platform C SDK

Continuous integration

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

A Continuous Integration system will compile projects continuously automatically and on all platforms, as we make changes to the repository.


We already saw in Portability how to move our applications between different platforms and development environments, generating optimized executables for each CPU and operating system without having to modify a single line of the source code. Now we are going to go one step further by automating the compilation and test phases.

An average work team can modify the code of a project several times a day. In cross-platform environments, such changes must be compiled and tested on several machines as soon as possible in order to correct errors or anomalies. For this, the Continuous Integration (CI) system will work continuously, in the background and autonomously each time the content of the repository is modified (Figure 1).

Basic outline of a system of continuous integration.
Figure 1: Continuous Integration System will work autonomously in the background.

1. Build grid

The first thing we have to do is set up a heterogeneous computer network where different machines coexist with the appropriate compilers (Figure 2) and that can communicate with each other Enable SSH. The main actors of this network are:

  • Build Grid: Network formed by all the machines that will cooperate in compilation tasks. They can be distributed over the Internet.
  • Build Master: Computer within the network that runs the Continuous Integration utility, coordinates the rest of the machines, stores the results and reports errors.
  • Build Host/Slave: Machine for compilation and test tasks, which will be remotely managed by the Build Master.
  • Build Agent: Configuration that identifies a compiler and CPU version. For example, the agent v142_x64 represents Visual Studio 2019 (VC++) 64bit. An agent can be executed by any Host that has the appropriate compiler installed. The Build Master will be in charge of balancing the load.
  • Build Profile: Profile that indicates all targets (libraries and/or executables) to be generated within a solution and which agents must intervene. The Build Master can handle several profiles at the same time.
  • Build Config: Indicates the level of optimization and debug options of the compilation: Debug, Release, ReleaseWithAssert. Configurations.
  • Scheme of a network of compilers, governed by a Build Master.
    Figure 2: Example Build Grid.

2. Command line

However complex the Build Profile may be, the remote compilation process can be divided into four steps:

  • Update: The working copy of the host, if outdated.
  • CMake: To generate compilation solutions .sln, .xcodeprojor Makefile.
  • Build: Compile by msbuild, xcodebuild or make depending on the platform.
  • Copiar: Compilation results, errors, warnings, libraries or executables. The Master will package all products and submit reports.

El Build Master you must use the command line version of all the tools involved and launch them on the remote host using SSH. We will review its syntax below.

2.1. SVN from command line

Listing 1: Version number of an SVN repository.
1
2
svn info --show-item revision svn://192.168.1.2/svn/myrepo -r HEAD
1642
Listing 2: Update the working copy of a Host.
1
svn checkout --username USER --password PASS svn://192.168.1.2/svn/NAPPGUI/1_0 C:\src -r 1642
Listing 3: Content of a repository directory at standard output stdout.
1
svn list svn://192.168.1.2/svn/NAPPGUI/1_0/src/osbs -r 1642
Listing 4: Contents of a file a stdout.
1
svn cat svn://192.168.1.2/svn/NAPPGUI/1_0/src/osbs/bmem.h -r 1642

2.2. CMake from command line

Listing 5: Creating a Visual Studio solution.
1
2
cd C:\build
cmake -G"Visual Studio 15 2017 Win64" -Tv141 C:\src
Listing 6: Install CMake by command line on macOS.
1
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
Listing 7: Creating an Xcode solution.
1
2
cd /Users/fran/build
cmake -G"Xcode" -DCMAKE_ARCHITECTURE:STRING=x86_64 /Users/fran/src
Listing 8: Creation of Makefile, to compile with GCC.
1
2
cd /home/fran/build
cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_ARCHITECTURE:STRING=x64 -DCMAKE_TOOLKIT=GTK3 /home/fran/src

In macOS and Linux we can alternate between different versions of the compiler, as we saw in xcode-select and update-alternatives. This must be done before launching cmake.

2.3. Visual Studio from command line

To compile a Visual Studio solution from the command line we will have to use the command MSBuild.exe, included in the distribution of the Microsoft environment.

Listing 9: Run Visual Studio from the command line.
1
2
cd C:\build
MSBuild.exe Project.sln /flp1:warningsonly;logfile=warnings.txt /flp2:errorsonly;logfile=errors.txt /p:Configuration=Debug /p:Platform=x64 /maxcpucount:1

This command redirects to stdout compiler messages. The warnings and errors found in the code will keep them in the archives warnings.txt and errors.txt respectively.

2.4. Xcode from command line

Like Visual Studio, Xcode can be executed from the command line. The syntax is as follows:

Listing 10: Run Xcode from command line.
1
2
cd /Users/fran/build
xcodebuild -project Project.xcodeproj -alltargets -configuration Debug

It also redirects to stdout the result of the compilation. Unlike MSBuild the notices and errors write them in stderr, preceded by tags warning: and error: respectively.

2.5. GCC/Make from the command line

In Linux the project is generated by files Makefile, which contain compilation scripts based on GCC. CMake has been responsible for creating these Makefile, so all you have to do is execute the command make.

Listing 11: Ejecutar make from command line.
1
2
cd /home/fran/build
make

2.6. Remote copies

Again we will use the SSH protocol, specifically the command scp to make the remote copy from the Host to the Master.

Listing 12: Copy a compiled library from a remote machine to a local directory.
1
scp fran@192.168.1.24:/build/Debug/core/libcore.a C:/pkg
❮ Back
Next ❯