Skip to content

Commit

Permalink
deps: add template for generated headers
Browse files Browse the repository at this point in the history
OpenSSL 3.0 has a number of header files that are generated, and
currently these headers are copied into the architecture specific
directories. This is done for each asm type, 'asm', 'asm_avx2', and
'no-asm' which has takes up quite a lot of disk space and also becomes
an issue with the headers.tar file which has increased due to this.

This commit adds copies the headers to a common directory for the
architecture, for example with linux-x86_64 there will be a directory
named deps/openssl/config/archs/linux-x86_64/common/include where the
headers will be copied (into subdirectories 'openssl' and 'crypto'.
And in the original locations a header file with the same name will be
generated which points (includes) the common header file.

Fixes: #42081
  • Loading branch information
danbev committed Apr 6, 2022
1 parent 0c9273d commit 3dcde51
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions deps/openssl/config/arch_include.h.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../../common/%%- $path -%%"
44 changes: 35 additions & 9 deletions deps/openssl/config/generate_gypi.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

our $src_dir = "../openssl";
our $arch_dir = "../config/archs/$arch";
our $arch_common_dir = "$arch_dir/common";
our $base_dir = "$arch_dir/$asm";

my $is_win = ($arch =~/^VC-WIN/);
Expand All @@ -59,6 +60,14 @@
"$base_dir/apps",
{
error => \my $make_path_err});

if (not $is_win) {
make_path("$arch_common_dir/include", "$arch_common_dir/include/openssl",
"$arch_common_dir/include/crypto",
{
error => \my $make_path_err});
}

if (@$make_path_err) {
for my $diag (@$make_path_err) {
my ($file, $message) = %$diag;
Expand All @@ -73,11 +82,6 @@
my @crypto_dir_headers = shift @ARGV;
copy_headers(@crypto_dir_headers, 'crypto');

move("$src_dir/include/crypto/bn_conf.h",
"$base_dir/include/crypto/bn_conf.h") or die "Move failed: $!";
move("$src_dir/include/crypto/dso_conf.h",
"$base_dir/include/crypto/dso_conf.h") or die "Move failed: $!";

copy("$src_dir/$buildinf",
"$base_dir/crypto/") or die "Copy failed: $!";
move("$src_dir/$progs",
Expand Down Expand Up @@ -367,13 +371,35 @@
system($cmd2) == 0 or die "Error in system($cmd2)";



sub copy_headers {
my @headers = split / /, $_[0];
my $inc_dir = $_[1];
my $header_path = "";
my $arch_header_include_template = Text::Template->new(TYPE => 'FILE',
SOURCE => 'arch_include.h.tmpl',
DELIMITERS => [ "%%-", "-%%" ]
);
foreach my $header_name (@headers) {
# Copy the header from OpenSSL source directory to the arch specific dir.
#print("copy header $src_dir/include/$inc_dir/${header_name}.h to $base_dir/include/$inc_dir \n");
copy("$src_dir/include/$inc_dir/${header_name}.h",
"$base_dir/include/$inc_dir/") or die "Copy failed: $!";
$header_path = "include/$inc_dir/${header_name}.h";
if ($is_win) {
#print("copy header $src_dir/$header_path to $base_dir/$header_path \n");
copy("$src_dir/$header_path",
"$base_dir/include/$inc_dir/") or die "Copy failed: $!";
} else {
print("copy header $src_dir/$header_path to $arch_common_dir/$header_path \n");
copy("$src_dir/$header_path",
"$arch_common_dir/$header_path") or die "Copy failed: $!";
# Generate a header file with the same name in the arch dependant directory
# which points to the common directory. This is done to avoid copying
# duplicate headers.
my $arch_header_include = $arch_header_include_template->fill_in(
HASH => {
path => "$header_path",
});
open(ARCH_HEADER_INC, "> $base_dir/$header_path");
print ARCH_HEADER_INC "$arch_header_include";
close(ARCH_HEADER_INC);
}
}
}

0 comments on commit 3dcde51

Please sign in to comment.