Skip to content

Commit 4d837e7

Browse files
authored
Merge pull request #7303 from Irvise/master
[Ada] Initial library support
2 parents 72fc08e + 5ea22ef commit 4d837e7

5 files changed

Lines changed: 140 additions & 31 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ debian/changelog
442442
debian/control
443443
*.deb
444444

445+
# Ada/Alire files
446+
wrapper/Ada/alire/
447+
wrapper/Ada/config/
448+
wrapper/Ada/lib/
449+
wrapper/Ada/obj/
450+
445451
# PlatformIO
446452
/**/.pio
447453
/**/.vscode/.browse.c_cpp.db*

wrapper/Ada/README.md

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ Not only can the WolfSSL Ada binding be used in Ada applications but
2828
also SPARK applications (a subset of the Ada language suitable
2929
formal verification). To formally verify the Ada code in this repository
3030
open the client.gpr with GNAT Studio and then select
31-
SPARK -> Prove All Sources and use Proof Level 2.
31+
SPARK -> Prove All Sources and use Proof Level 2. Or when using the command
32+
line, use `gnatprove -Pclient.gpr --level=4 -j12` (`-j12` is there in
33+
order to instruct the prover to use 12 CPUs if available).
3234

3335
```
3436
Summary of SPARK analysis
@@ -53,19 +55,31 @@ Total 172 17 (10%) . 1
5355

5456
## Compiler and Build System installation
5557

56-
### GNAT Community Edition 2021
57-
Download and install the GNAT community Edition 2021 compiler and studio:
58-
https://www.adacore.com/download
58+
### Recommended: [Alire](https://alire.ada.dev)
59+
[Alire](https://alire.ada.dev) is a modern package manager for the Ada
60+
ecosystem. The latest version is available for Windows, OSX, Linux and FreeBSD
61+
systems. It can install a complete Ada toolchain if needed, see `alr install`
62+
for more information.
5963

60-
Linux Install:
64+
In order to use WolfSSL in a project, just add WolfSSL as a dependency by
65+
running `alr with wolfssl` within your project's directory.
6166

62-
```sh
63-
chmod +x gnat-2021-20210519-x86_64-linux-bin
64-
./gnat-2021-20210519-x86_64-linux-bin
65-
```
67+
If the project is to be verified with SPARK, just add `gnatprove` as a
68+
dependency by running `alr with gnatprove` and then running `alr gnatprove`,
69+
which will execute the SPARK solver. If you get warnings, it is recommended to
70+
increase the prove level: `alr gnatprove --level=4`.
71+
72+
### GNAT FSF Compiler and GPRBuild manual installation
73+
In May 2022 AdaCore announced the end of the GNAT Community releases.
74+
Pre-built binaries for the GNAT FSF compiler and GPRBuild can be
75+
downloaded and manually installed from here:
76+
https://github.com/alire-project/GNAT-FSF-builds/releases
77+
Make sure the executables for the compiler and GPRBuild are on the PATH
78+
and use gprbuild to build the source code.
79+
80+
#### Manual build of the project
6681

6782
```sh
68-
export PATH="/opt/GNAT/2021/bin:$PATH"
6983
cd wrapper/Ada
7084
gprclean
7185
gprbuild default.gpr
@@ -82,15 +96,6 @@ gprbuild -XOS=Windows default.gpr
8296
gprbuild -XOS=Windows client.gpr
8397
```
8498

85-
86-
### GNAT FSF Compiler and GPRBuild manual installation
87-
In May 2022 AdaCore announced the end of the GNAT Community releases.
88-
Pre-built binaries for the GNAT FSF compiler and GPRBuild can be
89-
downloaded and manually installed from here:
90-
https://github.com/alire-project/GNAT-FSF-builds/releases
91-
Make sure the executables for the compiler and GPRBuild are on the PATH
92-
and use gprbuild to build the source code.
93-
9499
## Files
95100
The (D)TLS v1.3 client example in the Ada/SPARK programming language
96101
using the WolfSSL library can be found in the files:
@@ -103,15 +108,3 @@ using the WolfSSL library can be found in the files:
103108
tls_server_main.adb
104109
tls_server.ads
105110
tls_server.adb
106-
107-
A feature of the Ada language that is not part of SPARK is exceptions.
108-
Some packages of the Ada standard library and GNAT specific packages
109-
provided by the GNAT compiler can therefore not be used directly but
110-
need to be put into wrapper packages that does not raise exceptions.
111-
The packages that provide access to sockets and command line arguments
112-
to applications implemented in the SPARK programming language can be
113-
found in the files:
114-
spark_sockets.ads
115-
spark_sockets.adb
116-
spark_terminal.ads
117-
spark_terminal.adb

wrapper/Ada/alire.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name = "wolfssl"
2+
description = "WolfSSL encryption library and its Ada bindings"
3+
version = "5.7.0"
4+
5+
authors = ["Fernando Oleo Blanco"]
6+
maintainers = ["Fernando Oleo Blanco <irvise@irvise.xyz>"]
7+
maintainers-logins = ["Irvise"]
8+
licenses = "GPL-2.0-only"
9+
website = "https://www.wolfssl.com/"
10+
project-files = ["wolfssl.gpr"]
11+
tags = ["ssl", "tls", "embedded", "spark"]

wrapper/Ada/user_settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ extern "C" {
3737
/* Usually comes from configure -> config.h */
3838
#define HAVE_SYS_TIME_H
3939

40+
/* Explicitly define NETDB support */
41+
#define HAVE_NETDB_H
42+
4043
/* Features */
4144
#define SINGLE_THREADED
4245
#define WOLFSSL_IGNORE_FILE_WARN /* Ignore *.c include warnings */

wrapper/Ada/wolfssl.gpr

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
library project WolfSSL is
2+
3+
for Library_Name use "wolfssl";
4+
-- for Library_Version use Project'Library_Name & ".so";
5+
type OS_Kind is ("Windows", "Linux_Or_Mac");
6+
7+
OS : OS_Kind := external ("OS", "Linux_Or_Mac");
8+
9+
for Languages use ("C", "Ada");
10+
11+
for Source_Dirs use (".",
12+
"../../",
13+
"../../src",
14+
"../../wolfcrypt/src");
15+
16+
-- Don't build the tls client or server application.
17+
-- They are not needed in order to build the library.
18+
for Excluded_Source_Files use ("tls_client_main.adb",
19+
"tls_client.ads",
20+
"tls_client.adb",
21+
"tls_server_main.adb",
22+
"tls_server.ads",
23+
"tls_server.adb");
24+
25+
for Object_Dir use "obj";
26+
for Library_Dir use "lib";
27+
for Create_Missing_Dirs use "True";
28+
29+
type Library_Type_Type is ("relocatable", "static", "static-pic");
30+
Library_Type : Library_Type_Type := external("LIBRARY_TYPE", "static");
31+
for Library_Kind use Library_Type;
32+
33+
package Naming is
34+
for Spec_Suffix ("C") use ".h";
35+
end Naming;
36+
37+
package Builder is
38+
for Global_Configuration_Pragmas use "gnat.adc";
39+
end Builder;
40+
41+
package Compiler is
42+
for Switches ("C") use
43+
("-DWOLFSSL_USER_SETTINGS", -- Use the user_settings.h file.
44+
"-Wno-pragmas",
45+
"-Wall",
46+
"-Wextra",
47+
"-Wunknown-pragmas",
48+
"--param=ssp-buffer-size=1",
49+
"-Waddress",
50+
"-Warray-bounds",
51+
"-Wbad-function-cast",
52+
"-Wchar-subscripts",
53+
"-Wcomment",
54+
"-Wfloat-equal",
55+
"-Wformat-security",
56+
"-Wformat=2",
57+
"-Wmaybe-uninitialized",
58+
"-Wmissing-field-initializers",
59+
"-Wmissing-noreturn",
60+
"-Wmissing-prototypes",
61+
"-Wnested-externs",
62+
"-Wnormalized=id",
63+
"-Woverride-init",
64+
"-Wpointer-arith",
65+
"-Wpointer-sign",
66+
"-Wshadow",
67+
"-Wsign-compare",
68+
"-Wstrict-overflow=1",
69+
"-Wstrict-prototypes",
70+
"-Wswitch-enum",
71+
"-Wundef",
72+
"-Wunused",
73+
"-Wunused-result",
74+
"-Wunused-variable",
75+
"-Wwrite-strings",
76+
"-fwrapv") & External_As_List ("CFLAGS", " ");
77+
78+
for Switches ("Ada") use ("-g") & External_As_List ("ADAFLAGS", " ");
79+
end Compiler;
80+
81+
package Binder is
82+
for Switches ("Ada") use ("-Es"); -- To include stack traces.
83+
end Binder;
84+
85+
-- case OS is
86+
-- when "Windows" =>
87+
-- for Library_Options use ("-lm", -- To include the math library (used by WolfSSL).
88+
-- "-lcrypt32"); -- Needed on Windows.
89+
-- when "Linux_Or_Mac" =>
90+
-- for Library_Options use ("-lm"); -- To include the math library (used by WolfSSL).
91+
-- end case;
92+
--
93+
-- -- Put user options in front, for options like --as-needed.
94+
-- for Leading_Library_Options use External_As_List ("LDFLAGS", " ");
95+
96+
end WolfSSl;

0 commit comments

Comments
 (0)