Crypt-Sodium-XS

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;

use ExtUtils::MakeMaker;
use Config;
use Cwd;
use File::Spec;
use File::Temp;
use Text::ParseWords;

# builtin libsodium (these comments are to be updated when bundled lib is updated):

# gpg: Signature made Thu Apr  9 22:46:33 2026 UTC
# gpg:                using RSA key 0C7983A8FD9A104C623172CB62F25B592B6F76DA
# gpg: Good signature from "Frank Denis (Jedi/Sector One) <0daydigest@pureftpd.org>" [unknown]
# gpg:                 aka "Frank Denis (Jedi/Sector One) <j@pureftpd.org>" [unknown]
# gpg:                 aka "Frank Denis <github@pureftpd.org>" [unknown]
# gpg:                 aka "Frank Denis <frank.denis@corp.ovh.com>" [unknown]
# gpg: Signature notation: manu=2,2.5+1.12,2,3
# Primary key fingerprint: 54A2 B889 2CC3 D6A5 97B9  2B6C 2106 27AA BA70 9FE1
#      Subkey fingerprint: 0C79 83A8 FD9A 104C 6231  72CB 62F2 5B59 2B6F 76DA
# if building from the source rather than a distribution, put in src/:
# https://download.libsodium.org/libsodium/releases/libsodium-1.0.22.tar.gz
# https://download.libsodium.org/libsodium/releases/libsodium-1.0.22.tar.gz.sig
# check the signature, or at least:
# sha256: adbdd8f16149e81ac6078a03aca6fc03b592b89ef7b5ed83841c086191be3349  libsodium-1.0.22.tar.gz
# sha512: 8f392de781f09578d9a32000a4198e8d199ab910743017af3b3c5cae8053f745bcc885a9417fcaffb03b832400d829aef3a93c065bbb77b92598d882b6dcf187  libsodium-1.0.22.tar.gz

# see main module INSTALLATION section for how to install with a different
# release.

# almost certainly none of this will work on windows. although libsodium is
# cross-platform and provides some msvc scripts (or however that works), i've
# no idea how to get it to function. it should be possible.
# so for now, sorry charlie; patches and suggestions are appreciated!

die "OS unsupported\n" if $^O eq 'MSWin32';

my $src_dir = File::Spec->catdir(getcwd(), "src");
my $libsodium_version = '1.0.22';
my $libsodium_major_minimum = '10';
my $libsodium_minor_minimum = '3';
my $bundled_src_path = File::Spec->catfile($src_dir, "libsodium-$libsodium_version.tar.gz");
my $test_src = 'int main (int argc, char **argv) { return 0; }';
my $test_sodium_src = <<EOTEST;
#include <sodium.h>

#if (SODIUM_LIBRARY_VERSION_MAJOR < ${libsodium_major_minimum}U)
#error "major version is less than ${libsodium_major_minimum}: " _ SODIUM_LIBRARY_VERSION_MAJOR
#endif
#if (SODIUM_LIBRARY_VERSION_MINOR == ${libsodium_major_minimum}U) && (SODIUM_LIBRARY_VERSION_MINOR < ${libsodium_minor_minimum}U)
#error "minor version is less than ${libsodium_minor_minimum}: " _ SODIUM_LIBRARY_VERSION_MINOR
#endif

$test_src
EOTEST
my %eumm_args;

my $cflags = " $Config{ccflags} $Config{cccdlflags} $Config{optimize} ";
$cflags .= "$ENV{CFLAGS} " if $ENV{CFLAGS};
$cflags .= "$ENV{CPPFLAGS} " if $ENV{CPPFLAGS};
$cflags .= "$ENV{LDFLAGS} " if $ENV{LDFLAGS};
# lto is recommended against by upstream. best effort to prevent it.
if (_c_compile_test($test_src, "$Config{cc} -fno-lto")) {
  $cflags .= '-fno-lto ';
}
else {
  $cflags =~ s/(\A|\s)-flto\S*(\s|\z)//g;
}
# and sanitizers are more strongly discouraged, as they can introduce
# side-channels. upstream does test with sanitizers, and if you're doing your
# own testing and reading this...well you can comment it out.
if (_c_compile_test($test_src, "$Config{cc} -fno-sanitize=all")) {
  $cflags .= '-fno-sanitize=all ';
}
else {
  $cflags =~ s/(\A|\s)-fsanitize\S*(\s|\z)//g;
}



( run in 0.418 second using v1.01-cache-2.11-cpan-389fe586d7c )