Tech Days 2015: Multi-language Programming with GPRbuild

16
Multi-language Programming with GPRbuild Vasiliy Fofanov October 1, 2015

Transcript of Tech Days 2015: Multi-language Programming with GPRbuild

Page 1: Tech Days 2015: Multi-language Programming with GPRbuild

Multi-language Programming with GPRbuild

Vasiliy FofanovOctober 1, 2015

Page 2: Tech Days 2015: Multi-language Programming with GPRbuild

What is GNAT Project technology? (representation)• Project definition language

– What programming languages are used by project ?– Where are the sources ?– How are they called ?– How to build them ?

• Toolchain definition database– How to find and use toolchains and runtimes ?– User-extensible

Page 3: Tech Days 2015: Multi-language Programming with GPRbuild

What is GNAT Project technology? (operational)

• Project-aware tools– GPR* family

• gprbuild• gprclean• gprinstall …

– Standard GNAT Pro tools• gnatcheck• gnatcoverage …

– IDEs (GPS and GNATbench)

• Project handling API– To develop user tools…

Page 4: Tech Days 2015: Multi-language Programming with GPRbuild

GNAT Project File• A text file describing the various properties of a project• Declarative language (no actions)

– Intuitive Ada-inspired syntax– Compact description even for a complex multi-language project

• Project files can be used to describe most industrial software projects– Multiple build scenarios and configurations– Complex system architectures

• Shared, standalone libraries– Multi-language (including user-defined)

Page 5: Tech Days 2015: Multi-language Programming with GPRbuild

A Simple Examplewith "gtkada";

project My_Project is

for Source_Dirs use ("src1", "src2"); for Object_Dir use "obj"; for Main use ("file.adb");

type Mode is ("production", "debug"); M : Mode := external ("MODE", "debug");

package Compiler is case M is when "production" => for Default_Switches ("Ada") use ("-O2"); when "debug" => for Default_Switches ("Ada") use ("-O0", "-g", "-gnata"); end case; end Compiler;

end My_Project;

Page 6: Tech Days 2015: Multi-language Programming with GPRbuild

Used everywhere!• Common way to describe user software project across all AdaCore

toolchains– Edit sources– Analyze sources– Build / cleanup …

• Common interface

$> gps –P my_project.gpr

$> gprbuild –P my_project.gpr -Xmode=debug

$> gnatmetric –P my_project.gpr

Page 7: Tech Days 2015: Multi-language Programming with GPRbuild

Project Hierarchies• Modularity of software projects can be achieved through a

hierarchy of GNAT projects

• Highly recommended for medium and big projects

• The "with" keyword identifies project dependencieswith "gtkada";with "../core";

project Prj is

end Prj;

Page 8: Tech Days 2015: Multi-language Programming with GPRbuild

Multi-Language Projects• GNAT Projects are multi-language multi-compiler aware

– Supports a number of languages by default, including C and C++• A project file is assumed to be Ada by default, but can declare your

own set via Languages attribute

• All languages are first class citizens• Extensible

– Define your own languages/toolchains if needed(binding generators, scripts, resource compilers, etc…)

for Languages use ("Ada", "C"); -- My sources are Ada and C

Page 9: Tech Days 2015: Multi-language Programming with GPRbuild

Multi-language Project Examplewith "trig";

project My_App is for Languages use ("C"); for Main use ("my_app.c");end My_App;

#include <stdio.h>

float my_sin (float angle);

main ()

{ printf ("%f\n", my_sin (3.1415/2.0)); }

package Trig is function My_Sin (Angle : Float) return Float; pragma Export (C, My_Sin, "my_sin");end Trig;

with Ada.Numerics.Generic_Elementary_Functions;package body Trig is package GEF is new Ada.Numerics.Generic_Elementary_Functions (Float); function My_Sin (Angle : Float) return Float is begin return GEF.Sin (Angle); end My_Sin;end Trig;

library project Trig is for Library_Dir use "lib"; for Library_Kind use "dynamic"; for Library_Interface use ("trig"); for Library_Name use "trig”;

end Trig; for Library_Standalone use "encapsulated";

$> gprbuild my_app.gpr...$> ./my_app1.000000 That’s it!

Page 10: Tech Days 2015: Multi-language Programming with GPRbuild

Defining Targets and Runtimes• Non-native target and specific runtimes can be specified

– In a project:

– On a command line:

for Target use "powerpc-elf";for Runtime("Ada") use "ravenscar-cert";

$> gprbuild –P prj.gpr –-target=powerpc-elf --RTS=ravenscar-cert

Page 11: Tech Days 2015: Multi-language Programming with GPRbuild

GPRbuild• Our multi-language builder

• Understands different languages, compilers and targets

• Takes care of all building steps and complex cases– compiling, binding, linking– shared libraries, encapsulated libraries …

• Can be extended to understand new toolchains

• Can distribute compilation over several computers ?

Page 12: Tech Days 2015: Multi-language Programming with GPRbuild

Distributed builder• Parallel builds have been supported for a long time

gcc –c …gcc –c …gcc –c …gcc –c …

gprbuild prj.gpr –j0

• …but not good enough!– At best a dozen cores or so– But we can drive hundreds of

build decisions at once– Solution: distributed build farm

Page 13: Tech Days 2015: Multi-language Programming with GPRbuild

Distributed builder (2)

• Communication and file sync by lightweight sockets-based protocols

Master machine Slave machines

gprslave gprslave gprslave gprslave

• sources• compile commands

• objects• availability state

$ gprbuild prj --distributed= file://comp1.xyz.com, 164.10.127.4, ...

Page 14: Tech Days 2015: Multi-language Programming with GPRbuild

Where to find it all?• Bundled with all GNAT compiler toolchains• Also as a separate package

– If you want to keep the current compiler and only update the builder• Soon on GitHub (~early 2016)

Page 15: Tech Days 2015: Multi-language Programming with GPRbuild

Use It!• GNAT Project Facility is a mature technology

– Good match for AdaCore product line and our vision of development process

– Should be powerful enough to replace most if not all custom build procedures, while remaining accessible

• Are you using it? If not, why?• Don’t hesitate to ask us for help!