reznikmm / protobuf

The Google Protocol Buffers implementation in Ada
MIT License
32 stars 5 forks source link

Building with Alire (gnat_native 11.2) violates restriction #4

Closed mgrojo closed 3 years ago

mgrojo commented 3 years ago

I tried building it with Alire, but got this error:

matreshka-internals-unicode-ucd-cases.ads:7375:09: violation of restriction "No_Elaboration_Code" at line 45
matreshka-internals-unicode-ucd-core.ads:344:09: violation of restriction "No_Elaboration_Code" at line 45
$ alr toolchain
CRATE       VERSION  STATUS    NOTES
gprbuild    21.0.2   Default
gprbuild    2019.0.0 Available Provided by system package: gprbuild
gnat_native 11.2.2   Default

$ alr version
Alr version: 1.1.0
Alire Library version: 1.1.0
alr status is (valid) (0 releases indexed) (loaded in 0.141s)
config folder is /home/mgrojo/.config/alire
source folder is /home/mgrojo/.config/alire/alire
interaction flags are: force:FALSE not-interactive:FALSE
alr root is empty
alr root detection has settled on path: /home/mgrojo/src/alire/protobuf_1.0.0_43962766
alr is finding 0 GPR project files
alr session state is [OUTSIDE]
alr compiled on [2021-09-16 15:26:52] with GNAT version [Community 2021 (20210519-103)]
platform fingerprint: Linux Bits_64 Ubuntu
platform properties: UBUNTU LINUX NATIVE USER BITS_64
community index required branch: stable-1.1
mgrojo commented 3 years ago

Fixed with patch https://github.com/reznikmm/matreshka/commit/d907a15b628f17df4ab469960373e2ae31e1edd3

Can be closed, I leave it open, just in case you want (me) to close it when the patch is delivered in Alire.

mgrojo commented 3 years ago

After alr build and make install I had to manually enter in the alire dependencies and install theme separately. It is not clear which is the expected procedure for installing after alr build.

For example, for League I had to cd to alire/cache/dependencies/matreshka_league_20.1.0_41ddb44a and figure out this command: make install PREFIX=/opt/protobuf-ada-v1.0.0/ INSTALL_ALI_DIR=/opt/protobuf-ada-v1.0.0/lib INSTALL_EXEC_DIR=/opt/protobuf-ada-v1.0.0/bin GPRINSTALL=$GNAT/bin/gprinstall I hope this installation method doesn't cause me problems in the future.

In any case, it's generating the Ada code! (haven't compiled it yet, though)

Another minor issue to make the process smoother: it takes the proto file name as Ada identifier, but my file contains hyphens. It is adding underscores, but it is not removing the hyphens, so the generated result is not directly compilable. I'll change the filename before generating to work around it.

Example: file test-file-with-hyphens.proto generates package Testpkg.Test_-file_-with_-hyphens in files: testpkg-test_-file_-with_-hyphens.adb testpkg-test_-file_-with_-hyphens.ads

reznikmm commented 3 years ago

@mgrojo

Issue with Matreshka should be fixed now: new crate for matreshka 21.0 has been merged. Also matreshka 20.1 build has been fixed too.

Regarding installing alr build, in my POV, alr isn't supposed to install anything. The main its purpose is for simplifying development. So I suggest you to put the executable directory in PATH environment and use it in place.

I keep this issue as a bug report for files with hyphens.

mgrojo commented 3 years ago

@mgrojo

Issue with Matreshka should be fixed now: new crate for matreshka 21.0 has been merged. Also matreshka 20.1 build has been fixed too.

Thanks

Regarding installing alr build, in my POV, alr isn't supposed to install anything. The main its purpose is for simplifying development. So I suggest you to put the executable directory in PATH environment and use it in place.

I know, but building with alr and then having to look at how to install the dependencies which were automatically downloaded and built with Alire seems to go only half of the way of the dependency automation. But no problem, in any case, I was able to figure it out and install all the needed dependencies, and so could do others in the future. And it is easier to do it in this way, than having to make all the process manually.

I keep this issue as a bug report for files with hyphens.

Ok, thanks.

mgrojo commented 3 years ago

@reznikmm

I've fixed the problem with the hyphens in the filename for me using this patch:

--- ./source/compiler/compiler-file_descriptors.adb~    2021-11-09 12:20:36.519903040 +0000
+++ ./source/compiler/compiler-file_descriptors.adb     2021-11-09 12:20:14.968328895 +0000
@@ -21,6 +21,8 @@
 --  DEALINGS IN THE SOFTWARE.

 with Ada.Characters.Wide_Wide_Latin_1;
+with Ada.Strings.Fixed;
+with Ada.Strings.Maps;
 with Ada.Directories;

 with Ada_Pretty;
@@ -286,7 +288,11 @@
       return League.Strings.Universal_String
    is
       File_Name : constant String := Self.Name.Value.To_UTF_8_String;
-      Base_Name : constant String := Ada.Directories.Base_Name (File_Name);
+      Base_Name : constant String :=
+        Ada.Strings.Fixed.Translate
+          (Source  => Ada.Directories.Base_Name (File_Name),
+           Mapping => Ada.Strings.Maps.To_Mapping
+             (From => "-", To => "_"));
       PB_Pkg    : League.Strings.Universal_String;
       Result    : League.Strings.Universal_String :=
         Compiler.Context.To_Ada_Name

I can make a pull request if you want and like this solution.

By the way, protobuf for Ada is working fine for me. I've been able to communicate Ada with Java without issues. Thanks for everything.

reznikmm commented 3 years ago

Thank you. I think, I can do it a bit easier with Matreshka Split/Join functions.

mgrojo commented 3 years ago

Perfect, thanks for including the fix.