What is the ideal way to configure alire/gprbuild?

Hi there, I have been learning Ada for about 3 or so months. I am currently using it to build my game engine. I sort of am getting the hang of it, but I started building this engine actually using gprbuild and only just “kind of” moved to Alire. I am on Windows (but I have a Linux environment and been using that for over 4 years so I know what I am getting myself into), and I want my engine to be on Windows/Linux. So my question is what is the best way to manually configure alire/gprbuild?

So far this works with a minimal raylib window and while I am going to build my cmake deps soonish, I am a bit hesistant to use it after building. (I never really liked cmake, I found it too big/hard to navigate). I would like some help on general project structure with alire/gprbuild if possible.

Also, if you are going to ask “why didn’t you just use alr init to start?” I came from Swift and I have had very, very bad experiences with package managers. Almost all the ones I have used in the dozen or so languages I have used have been kind of painful to audit dependencies and generally abstract away too much and for Swift, it doesn’t do FFI particularly “well” with it.

So yeah, call it ptsd, but I am recovering. I like alire (reminds me of cargo, one of the more acceptable PM’s imho) but any help would be nice. The ‘wiring’ for the other stuff is going to be done in the next few weeks, but yeah.

Here is my minimum project, I am entirely self taught so I am not very creative. But it at least does a window/ffi far better then Swift! GitHub - UltimaTerra/Shrine: An experimental game engine stack.

Any general tips, help and links would be appreciated. I have also found the docs for gprbuild here: 2. GNAT Project Manager — GPR Tools User's Guide 26.0w documentation

And I promise/swear if I can get alire working ‘nicely’ I wouldn’t mind adding just one more dependencies on GNATColl if I can. But for now, I am mostly just turtle-walking to the finish line.

Lastly, I know I could I have asked AI, but I wanted to come here both to introduce myself and to also get “the facts”. So here we are.

Thank you! :heart: :green_heart: Look forward to staying around here. I have only been seriously self teaching myself for like, two years now, but I know I have a lot to learn.

7 Likes

Welcome to Ada.

For me - who does not use Alire yet - I recommend to really learn the how-to of gpr-files.

And learn to write them manually.

Alire uses gpr-files as well

some examples of non-trivial gpr-files.

global.gpr

adabot.gpr

adabot withs global

environment variables can be used within gpr-files as scenario variables

they can be passed on prompt too with -x I think

You can use them to compile c-files as well

for Languages use (“Ada”, “c“);

There’s an --in-place option so you can create a project within an existing code base.

1 Like

Hi Terra,

first things first. Welcome to the forums!

That is no coincidence. Alire was started as a somewhat copy of cargo for the Ada ecosystem :slight_smile:

Yay! Someone that actually RTFM! :smiley:

I took a look at your repo. I saw that you had already added Alire, probably as Lucretia indicated. I ran a alr build and it fails. alr -v build (verbose build) indicates that you have a typo on your shrine.gpr, the name of the directory is Duo/DuoFE :slight_smile:

info: ⓘ Building shrine=0.1.0-dev/shrine.gpr...
detail: Spawning: ["gprbuild", "-v", "-s", "-j0", "-p", "-P", "/home/fernando/Dirt/Shrine/shrine.gpr"]

==============Messages for file: /home/fernando/Dirt/Shrine/shrine.gpr
     3.    for Source_Dirs use ("Sources", "Sources/custom", "Sources/engine", "Sources/swl","Sources/kernel", "Duo/DuoBE");
                                                                                                               |
        >>> "Duo/DuoBE" is not a valid directory
gprbuild: "/home/fernando/Dirt/Shrine/shrine.gpr" processing failed
error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/fernando/Dirt/Shrine/shrine.gpr"] exited with code 5
error: Compilation failed.
detail: alr build unsuccessful

After the fix, the build starts and fails as expected in my linux system once it gets to linking. So you are pretty much done!

However, I see that you have some .odin files in your repo. GPRbuild is not prepared to compile that language… It uses some pre-defined drivers and it mostly only supports Ada, Assembly, C/C++, Fortran and Matlab… If you want Alire to build everything with GPRbuild, that wont be possible… Though Alire can call external tools/commands as documented in Alire - Docs (see the actions section).

Please, do ask any questions or doubts that you may have!!

Happy learning and hacking,
Fer

1 Like

As a note, you can sometimes configure GPRBuild to compile non supported languages. I do it for a custom compiler we get from a vendor that has a C like syntax but non C supported features. Here’s an example of one of my GPR files for it (NOTE: I took out the source folder and other non pertinent declarations):

project Default is

   Compiler_Path  := "C:\Program Files (x86)\PICC\";
   
   for Languages use ("CCS");

   package Compiler is
      for Driver ("CCS") use Compiler_Path & "ccsc.exe";
      for Leading_Required_Switches("CCS") use
        ("+FD",
         "+P3", "+PE",
         "+STDOUT",
         "+EA",
         "-J", "-D", "+A", "+T",
         "I=" & Compiler_Path & "Devices;" & Compiler_Path & "Drivers");
   end Compiler;

   for Objects_Linked ("CCS") use "False"; -- There is no linker for this compiler
   for Object_Generated ("CCS") use "False";

   package Naming is
      for Spec_Suffix ("CCS") use ".h";
      for Body_Suffix ("CCS") use ".c";
   end Naming;

end Default;

I don’t know Odin, but it may require some linker setup (the custom compiler I use doesn’t have a linker, so I specified that).

I got the idea from some Ada Gems articles:
1: Gem #152 : Defining a New Language in a Project File | AdaCore
2: Gem #155: Enhancing the GPRBuild Database for a New Language | AdaCore

I also had to reference the user guide some: GPRbuild and GPR Companion Tools User’s Guide — GPR Tools User's Guide 26.0w documentation

3 Likes

Hi! I am back! I have…had a week.

In short, after a linux update, my windows partition doesn’t work, so I am kind of stuck here until I can get money to get another usb for a iso boot/repair.

So I just want to clarify, I did make some changes to work on linux. I actually going to spend reconfiguring my git submodules with gpr files/alire.

Ironically unrelated, I kind of had other issues with Raygui/Nuklear not showing, so me in my hubris decided to try and make an imgui in ada myself. So I decided to fork and try to build it, here was the OG and it will build, but it will warn because the x11 crate does not exist

Old:

name = "openglada"
description = "Thick Ada binding for OpenGL"
version = "0.9.0"
website = "http://flyx.github.io/OpenGLAda/"
authors = ["Felix Krause"]
licenses = "MIT"
maintainers = ["Felix Krause <contact@flyx.org>"]
maintainers-logins = ["flyx"]
project-files = ["opengl.gpr"]
tags = ["opengl", "binding", "rendering", "graphics"]

[[depends-on]]
[depends-on."case(os)".linux]
libx11 = "^1"

[gpr-externals]
Auto_Exceptions = ["enabled", "disabled"]
Mode = ["debug", "release"]

[gpr-set-externals."case(os)"]
linux = { Windowing_System = "x11" }
macos = { Windowing_System = "quartz" }
windows = { Windowing_System = "windows" }

New:

name = "openglada"
description = "Thick Ada binding for OpenGL"
version = "0.9.0"
website = "http://flyx.github.io/OpenGLAda/"
authors = ["Felix Krause"]
licenses = "MIT"
maintainers = ["Nicol Meadows <you@example.com>"]
maintainers-logins = ["nicolm"]
project-files = ["opengl.gpr"]
tags = ["opengl", "binding", "rendering", "graphics"]

[[depends-on]]
name = "x11"
kind = "system"

[system."x11".pkg-config]
modules = ["x11"]

[gpr-externals]
Auto_Exceptions = ["enabled", "disabled"]
Mode = ["debug", "release"]

[gpr-set-externals."case(os)"]
linux = { Windowing_System = "x11" }
macos = { Windowing_System = "quartz" }
windows = { Windowing_System = "windows" }

So this is from the OpenGLAda crate (which I will happy consider maintaining after this hiccup). And so here is the skinny.

  1. The first one will build if you do gprbuild -p opengl.gpr. It will also produce a static file (as expected/what I want for my game engine/imgui anyway.) BUT it will still warn about x11
Dependencies automatically updated as follows:                           

   New solution is incomplete.
   Missing:
   +❗      libx11 ^1 (new,missing)
warn: The following external dependencies are unavailable within Alire:
warn:    libx11^1
warn: They should be made available in the environment by the user.

warn: Generating possibly incomplete configuration because of missing dependencies

And yada yada, builds “fine”

  1. The new which I tried to model from the docs using system deps, but I kind of wish had an example, will give you this.
nicolterra@uterra88:~/Documents/OpenGLAda/opengl$ alr build
error: Cannot continue without a workspace:
error:    Failed to load alire.toml:
error:    Unexpected symbol: s (at char 1)

I suspect a malformed alire toml when you try to reconfigure. AKA: I am screwing up somewhere, but not sure where.

If I take over, especially we need a wayland backend anyway, I am thinking of two fixes.

  1. Easiest is to fix the gprbuild I think. Just link x11 and GL and it should be fine.
  2. Slightly harder but useful to more users is to fix the alire crate and either have it link with the system deps for x11 (and later wayland) so we can get it properly working when you can use alr with

Ironically, this came to be because as I was tinkering with a smaller Raylib + Raygui project, I had an issue with displaying a button so I figured OpenGL was hiccuping somewhere in the binding. It is not too relevant and this post is already super long.

TLDR: Not related directly to above, but if you try to build the opengl binding in Ada, it will warn about x11 dependencies, but build fine. I want to fix the alire.toml file but I am also okay with just manually linking with gprbuild. If it pleases the thread, I can also make another post. Something like “FIxing OpenGL bindings with Alire.”

Edit: This was also flagged by the community, I suppose it is a false positive, but I hope this reveals it.

1 Like