Skip to content

Commit 4f7bab7

Browse files
committed
Support building with the Perl XS bindings disabled
Since the Perl bindings require shared libraries, this is required on platforms such as Cygwin where we do a static build.
1 parent 6a7b24a commit 4f7bab7

File tree

5 files changed

+92
-12
lines changed

5 files changed

+92
-12
lines changed

configure.ac

+16-9
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fi
7171
AC_PROG_CC
7272
AC_PROG_CXX
7373

74-
# To build programs to be run in the build machine
74+
# To build programs to be run in the build machine.
7575
if test "$CC_FOR_BUILD" = ""; then
7676
if test "$cross_compiling" = "yes"; then
7777
AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc)
@@ -86,13 +86,6 @@ AC_DISABLE_STATIC
8686
AC_ENABLE_SHARED
8787
AC_PROG_LIBTOOL
8888

89-
if test "$enable_shared" = yes; then
90-
SUB_CONFIGURE_FLAGS="--enable-shared --disable-static"
91-
else
92-
SUB_CONFIGURE_FLAGS="--enable-static --disable-shared"
93-
fi
94-
AC_SUBST(SUB_CONFIGURE_FLAGS)
95-
9689

9790
# Use 64-bit file system calls so that we can support files > 2 GiB.
9891
AC_SYS_LARGEFILE
@@ -247,7 +240,7 @@ PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19], [CXXFLAGS="$SQLITE3_CFLAGS $CX
247240

248241
# Whether to use the Boehm garbage collector.
249242
AC_ARG_ENABLE(gc, AC_HELP_STRING([--enable-gc],
250-
[enable garbage collection in the Nix expression evaluator (requires Boehm GC)]),
243+
[enable garbage collection in the Nix expression evaluator (requires Boehm GC) [default=no]]),
251244
gc=$enableval, gc=no)
252245
if test "$gc" = yes; then
253246
PKG_CHECK_MODULES([BDW_GC], [bdw-gc])
@@ -277,6 +270,20 @@ AC_MSG_RESULT(yes)
277270
AC_SUBST(perlFlags)
278271

279272

273+
# Whether to build the Perl bindings
274+
AC_MSG_CHECKING([whether to build the Perl bindings])
275+
AC_ARG_ENABLE(perl-bindings, AC_HELP_STRING([--enable-perl-bindings],
276+
[whether to build the Perl bindings (recommended) [default=yes]]),
277+
perlbindings=$enableval, perlbindings=yes)
278+
if test "$enable_shared" = no; then
279+
# Perl bindings require shared libraries.
280+
perlbindings=no
281+
fi
282+
AM_CONDITIONAL(PERL_BINDINGS, test "$perlbindings" = "yes")
283+
AC_SUBST(perlbindings)
284+
AC_MSG_RESULT($perlbindings)
285+
286+
280287
AC_ARG_ENABLE(init-state, AC_HELP_STRING([--disable-init-state],
281288
[do not initialise DB etc. in `make install']),
282289
init_state=$enableval, init_state=yes)

perl/Makefile.am

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ PERL_MODULES = lib/Nix/Store.pm lib/Nix/Manifest.pm lib/Nix/GeneratePatches.pm l
22

33
all: $(PERL_MODULES:.in=)
44

5-
install-exec-local: $(PERL_MODULES:.in=)
5+
install-exec-local: $(PERL_MODULES:.in=) install-perl-xs
66
$(INSTALL) -d $(DESTDIR)$(perllibdir)/Nix
77
$(INSTALL_DATA) $(PERL_MODULES:.in=) $(DESTDIR)$(perllibdir)/Nix
8+
9+
if PERL_BINDINGS
10+
install-perl-xs:
811
$(INSTALL) -d $(DESTDIR)$(perllibdir)/auto/Nix/Store
912
ln -sfn $(pkglibdir)/libNixStore$(dynlib_suffix) $(DESTDIR)$(perllibdir)/auto/Nix/Store/Store$(dynlib_suffix)
1013

@@ -25,6 +28,10 @@ AM_CXXFLAGS = \
2528
lib/Nix/Store.cc: lib/Nix/Store.xs
2629
xsubpp $^ -output $@
2730

31+
else
32+
install-perl-xs:
33+
endif
34+
2835
EXTRA_DIST = $(PERL_MODULES) lib/Nix/Store.xs
2936

3037
include ../substitute.mk

perl/lib/Nix/Config.pm.in

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ $confDir = $ENV{"NIX_CONF_DIR"} || "@sysconfdir@/nix";
1010
$bzip2 = $ENV{"NIX_BZIP2"} || "@bzip2@";
1111
$curl = "@curl@";
1212

13+
$useBindings = "@perlbindings@" eq "yes";
14+
1315
sub readConfig {
1416
my %config;
1517
my $config = "@sysconfdir@/nix/nix.conf";

perl/lib/Nix/Store.pm

+65-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package Nix::Store;
22

33
use strict;
44
use warnings;
5+
use Nix::Config;
56

67
require Exporter;
78

@@ -21,8 +22,70 @@ our @EXPORT = qw(
2122

2223
our $VERSION = '0.15';
2324

24-
require XSLoader;
25-
XSLoader::load('Nix::Store', $VERSION);
25+
sub backtick {
26+
open(RES, "-|", @_) or die;
27+
local $/;
28+
my $res = <RES> || "";
29+
close RES or die;
30+
return $res;
31+
}
32+
33+
if ($Nix::Config::useBindings) {
34+
require XSLoader;
35+
XSLoader::load('Nix::Store', $VERSION);
36+
} else {
37+
38+
# Provide slow fallbacks of some functions on platforms that don't
39+
# support the Perl bindings.
40+
41+
use File::Temp;
42+
use Fcntl qw/F_SETFD/;
43+
44+
sub hashFile {
45+
my ($algo, $base32, $path) = @_;
46+
my $res = backtick("$Nix::Config::binDir/nix-hash", "--flat", $path, "--type", $algo, $base32 ? "--base32" : ());
47+
chomp $res;
48+
return $res;
49+
}
50+
51+
sub hashPath {
52+
my ($algo, $base32, $path) = @_;
53+
my $res = backtick("$Nix::Config::binDir/nix-hash", $path, "--type", $algo, $base32 ? "--base32" : ());
54+
chomp $res;
55+
return $res;
56+
}
57+
58+
sub hashString {
59+
my ($algo, $base32, $s) = @_;
60+
my $fh = File::Temp->new();
61+
print $fh $s;
62+
my $res = backtick("$Nix::Config::binDir/nix-hash", $fh->filename, "--type", $algo, $base32 ? "--base32" : ());
63+
chomp $res;
64+
return $res;
65+
}
66+
67+
sub addToStore {
68+
my ($srcPath, $recursive, $algo) = @_;
69+
die "not implemented" if $recursive || $algo ne "sha256";
70+
my $res = backtick("$Nix::Config::binDir/nix-store", "--add", $srcPath);
71+
chomp $res;
72+
return $res;
73+
}
74+
75+
sub isValidPath {
76+
my ($path) = @_;
77+
my $res = backtick("$Nix::Config::binDir/nix-store", "--check-validity", "--print-invalid", $path);
78+
chomp $res;
79+
return $res ne $path;
80+
}
81+
82+
sub queryPathHash {
83+
my ($path) = @_;
84+
my $res = backtick("$Nix::Config::binDir/nix-store", "--query", "--hash", $path);
85+
chomp $res;
86+
return $res;
87+
}
88+
}
2689

2790
1;
2891
__END__

substitute.mk

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
-e "s^@xsltproc\@^$(xsltproc)^g" \
3131
-e "s^@sqlite_bin\@^$(sqlite_bin)^g" \
3232
-e "s^@version\@^$(VERSION)^g" \
33+
-e "s^@perlbindings\@^$(perlbindings)^g" \
3334
-e "s^@testPath\@^$(coreutils):$$(dirname $$(type -p expr))^g" \
3435
< $< > $@ || rm $@
3536
if test -x $<; then chmod +x $@; fi

0 commit comments

Comments
 (0)