Skip to content

Commit

Permalink
Add support for FreeBSD (#1148)
Browse files Browse the repository at this point in the history
* Add support for FreeBSD (#22)

* update GNAT project to recognize -XOS=freebsd and configure accordingly
* add FreeBSD as a valid operating system
* add AMD64 as an alias for X86_64 because uname -m returns amd64 on FreeBSD
* add platform specific implementation for FreeBSD

To build on FreeBSD, we should use

gprbuild -j0 -P alr_env -XOS=freebsd

* Fixes requested during code review

Co-authored-by: GHA <[email protected]>
  • Loading branch information
stcarrez and actions-user committed Aug 26, 2022
1 parent 4f9191a commit e77a410
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
4 changes: 4 additions & 0 deletions alire.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ library project Alire is
case Alire_Common.Host_Os is
when "windows" => Src_Dirs := Src_Dirs & ("src/alire/os_windows");
when "osx" => Src_Dirs := Src_Dirs & ("src/alire/os_macos");
when "freebsd" => Src_Dirs := Src_Dirs & ("src/alire/os_freebsd");
when others => Src_Dirs := Src_Dirs & ("src/alire/os_linux");
end case;

Expand All @@ -36,6 +37,9 @@ library project Alire is
when "osx" =>
for body ("Alire.Platforms.Current") use "alire-platforms-current__macos.adb";
for body ("Alire.Platforms.Folders") use "alire-platforms-folders__macos.adb";
when "freebsd" =>
for body ("Alire.Platforms.Current") use "alire-platforms-current__freebsd.adb";
for body ("Alire.Platforms.Folders") use "alire-platforms-folders__freebsd.adb";
when others =>
for body ("Alire.Platforms.Current") use "alire-platforms-current__linux.adb";
for body ("Alire.Platforms.Folders") use "alire-platforms-folders__linux.adb";
Expand Down
3 changes: 3 additions & 0 deletions alr_env.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ aggregate project Alr_Env is
when "macOS" | "macos" | "OSX" | "osx" =>
for External ("ALIRE_OS") use "osx";
for External ("GNATCOLL_OS") use "osx";
when "freebsd" =>
for External ("ALIRE_OS") use "freebsd";
for External ("GNATCOLL_OS") use "unix";
when others =>
for External ("ALIRE_OS") use "unix";
for External ("GNATCOLL_OS") use "unix";
Expand Down
12 changes: 9 additions & 3 deletions src/alire/alire-platforms.ads
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package Alire.Platforms with Preelaborate is
-- Platform information necessary for some releases

type Extended_Architectures is
(ARM64, -- Equivalent to AARCH64
(AMD64, -- Equivalent to X86_64 (FreeBSD)
ARM64, -- Equivalent to AARCH64
End_Of_Duplicates,
-- Up to this point, these are architectures that we want to rename to
-- some of the following because they are equivalent.
Expand All @@ -19,12 +20,14 @@ package Alire.Platforms with Preelaborate is
Extended_Architectures'Succ (End_Of_Duplicates) .. Architecture_Unknown;
-- See e.g. https://stackoverflow.com/a/45125525/761390

type Operating_Systems is (Linux,
type Operating_Systems is (FreeBSD,
Linux,
MacOS,
Windows,
OS_Unknown);
subtype Known_Operating_Systems is
Operating_Systems range Linux .. Windows;
Operating_Systems range
Operating_Systems'First .. Operating_Systems'Pred (OS_Unknown);

type Targets is (Native,
Unknown_Cross_Target);
Expand Down Expand Up @@ -72,8 +75,11 @@ package Alire.Platforms with Preelaborate is

private

-- Should be in sync with testsuite/drivers/helpers.py#L106

function Arch_Mapping (Arch : Extended_Architectures) return Architectures
is (case Arch is
when AMD64 => X86_64,
when ARM64 => AARCH64,
when Architectures => Arch,
when others =>
Expand Down
7 changes: 7 additions & 0 deletions src/alire/os_freebsd/alire-check_absolute_path.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
separate (Alire)
function Check_Absolute_Path (Path : Any_Path) return Boolean is
begin
return (Path'Length >= 1
and then
Path (Path'First) = GNAT.OS_Lib.Directory_Separator);
end Check_Absolute_Path;
34 changes: 34 additions & 0 deletions src/alire/os_freebsd/alire-platforms-current__freebsd.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

package body Alire.Platforms.Current is

-- FreeBSD implementation (very close to Linux)

---------------------------
-- Detected_Distribution --
---------------------------

function Detected_Distribution return Platforms.Distributions is
(Platforms.Distro_Unknown);

-----------------------
-- Distribution_Root --
-----------------------

function Distribution_Root return Absolute_Path
is ("/");

----------------------
-- Load_Environment --
----------------------

procedure Load_Environment (Ctx : in out Alire.Environment.Context)
is null;

----------------------
-- Operating_System --
----------------------

function Operating_System return Alire.Platforms.Operating_Systems
is (Alire.Platforms.FreeBSD);

end Alire.Platforms.Current;
19 changes: 19 additions & 0 deletions src/alire/os_freebsd/alire-platforms-folders__freebsd.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
with Alire.Platforms.Common;

package body Alire.Platforms.Folders is

-- Linux implementation

-----------
-- Cache --
-----------

function Cache return String is (Common.XDG_Config_Folder);

-----------
-- Config--
-----------

function Config return String is (Common.XDG_Config_Folder);

end Alire.Platforms.Folders;

0 comments on commit e77a410

Please sign in to comment.