Pre-defined Libraries & Package Manager

Tram Ho

There is a rather interesting fact about Ada – that there is no person or organization that actually owns the language. And the American organization DoD only sees Ada as a standard configuration to build a modern programming language. Just like ECMA International only sees ECMA as a standard configuration for deploying environments for cross-platform programming languages ​​such as JavaScript , Dart , C# , Eiffel , C++ , etc..

That means the functionality of the above languages ​​will depend on the specific development environment we use, like interpreter or compiler . And for Ada in particular, there are also compilers created by different organizations, geared towards specific application environments with slightly different default resource sets.

Predefined Libraries

Here. we have the minimum standard configuration libraries that development environments need to fully deploy, including:

  • Ada – library containing definitions of basic data types like Interger , Float , Boolean , Char , String , etc..
  • Standard – a library that provides tools for manipulating basic data types defined in the Ada library.
  • Interfaces – provides tools to communicate with other languages: C , Cobol , Fortran .
  • System – provides tools related to resource management of the system that will run the built software: RAM or Cache , Storage , Multiprocessor .

GNAT that we are using in the Sub-Series is a compiler designed towards a broad application class including embedded programming and general programming. So we have another library defined with the same name: GNAT .

This library provides some alternative tools at a higher level of abstraction than standard libraries for managing code task , or working with collection data types such as String , Heap Table … and already implemented data sorting algorithms such as Bubble Sort , Heap Sort … and also communication tools for network applications such as Sockets , Stream

By the way, we can find the Ada language implementation details in the GNAT environment fully documented here: GNAT Reference Manual . In it, there is a section about predefined Attributes that is also very important. The rest of the indexes like Pragma or Aspect , you probably won’t need to care about unless you touch the embedded programming application layer.

Package Manager

In the software building process, in addition to using the predefined libraries of a programming language, we will often need to use other support libraries that are specifically designed towards the application layer. desired use. Downloading a shared code library somewhere and integrating it into project Ada is quite simple with the declared structure in the project ‘s configuration file as we all know.

In the example code above, the declarative lines of code that are comment on the last lines are to simulate the syntax of declaring a library named compiled_pkg , the type of compiled library called Dynamic , and finally is the path to the directory containing that library from the root directory of project containing the src directory.

This is the project management feature that GNAT ‘s gprbuild provides: very intuitive and easy to use. However, compared to the tools that we have known through the previous Self-Taught Series, the process of managing additional libraries like this is quite manual. For example, with npm , we just need to type the install package command and the code files of the library to be installed will be automatically downloaded, along with the operation declared in the project ‘s package.json file. perform.

Recently, a project called Alire (Ada Lirary Repository) – roughly translated as “Ada repository and management of code libraries” – has appeared and is known in the community of programmers who love the language. this. The library are called by Alire another name crate and have a current aggregate count of about 318.

You can download the latest Alire installation files for Windows , Linux , etc. operating systems here: Alire Releases . For Windows , after running the installation file and completing, we will need to declare a new environment variable that points to the C:Program FilesAlirebin directory. In case you change the default installation directory, you need to find that directory and copy the full path as such. As for Linux , after extracting the downloaded file, we will need to move the alr executable to the usr/bin directory.

After we have completed the installation and environment variable declaration, we can open the command line window and type alr to check the results. If you are using Windows , you may receive a message to install additional msys2 and just select (Y)es to make the installation process automatic. You will then see a list of commands supported by alr .

image.png

To create a crate – that is, a project – managed by alr , we type the command:

  • alr init --bin project_name – to initialize an application .
  • alr init --lib project_name – to initialize a library library .

Try creating a hello_alire application:

If your computer does not have Git installed before, alr will display a message suggesting to install more before executing this command. After that, the hello_alire directory will be initialized with the basic management files and a success message in the command line.

image.png

And we have the basic structure of a project managed by alr including:

  • 01 project configuration file for gprbuild – because alr is actually the project manager and controls the translation side commands via gprbuild .
  • 01 management declaration file for alr named alire.toml .
  • 01 src folder to contain the code files for gprbuild as known before.
  • 01 share folder to contain external libraries downloaded with alr .

Here alr also considers the hello_alire application itself that we initialize as a shared library, and can be reactivated within project itself, eg reactivating multiple times with multiple parallel task . So in the share folder there will be a folder called hello_alire .

image.png

Now let’s try to edit the opening code again and test project with alr :

When we run the alr build command for the first time, we will be asked for some information about the version of GNAT we want to use, and just select the latest gnat_native and gprbuild versions from the printed selection list.

image.png

After setting up alr build , it will proceed to control gprbuild to compile the code and create additional directories:

  • config – contains configuration files that store development environment setup information including the operating system and versions of gnat_native and gprbuild .
  • obj – contains compiled code files.
  • bin – contains the launch file corresponding to the operating system in use.

Now we can run the program by pointing directly to the executable in the bin directory or by running the command alr run

Oh, so the alr run command will also automatically trigger alr build to make sure project is being translated with the latest code we wrote. And we have a full range of software development tools in the Ada language, including:

  • Common syntactic elements of the Ada language
  • Libraries already defined and built-in with the gnatmake compiler
  • Alire Installation Package Manager

As I said earlier, I do not intend to apply embedded programming or web programming with the Ada language, but just want to use Ada as a reference standard for the Procedural Programming Programming model. So perhaps at this point, to choose a small project and find a way to express Procedural thinking in code, a CLI application will be the most suitable choice.

If you have some time, let’s see how to build a Tic-Tac-Toe application on CLI command line interface implemented in Ada language and what’s remarkable about Procedural Programming programming model. idea.

Share the news now

Source : Viblo