aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-03-27 14:12:20 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-26 22:07:28 +0100
commit11da5b2816e11b081d8ff38db4330addd2014f7e (patch)
treefeeffda49248279c72805048bcebf1839a869015 /src
parentabb8ef619ba2fab3ae16fb5b5430215905bac723 (diff)
Add some Rust code
Diffstat (limited to 'src')
-rw-r--r--src/nix/local.mk4
-rw-r--r--src/nix/test.cc61
2 files changed, 63 insertions, 2 deletions
diff --git a/src/nix/local.mk b/src/nix/local.mk
index c09efd1fc..a145cf9b1 100644
--- a/src/nix/local.mk
+++ b/src/nix/local.mk
@@ -15,9 +15,9 @@ nix_SOURCES := \
$(wildcard src/nix-prefetch-url/*.cc) \
$(wildcard src/nix-store/*.cc) \
-nix_LIBS = libexpr libmain libstore libutil
+nix_LIBS = libexpr libmain libstore libutil libnixrust
-nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) -lboost_context -lboost_thread -lboost_system
+nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) -lboost_context -lboost_thread -lboost_system -Lnix-rust/target/release
$(foreach name, \
nix-build nix-channel nix-collect-garbage nix-copy-closure nix-daemon nix-env nix-hash nix-instantiate nix-prefetch-url nix-shell nix-store, \
diff --git a/src/nix/test.cc b/src/nix/test.cc
new file mode 100644
index 000000000..70e0a903d
--- /dev/null
+++ b/src/nix/test.cc
@@ -0,0 +1,61 @@
+#include "command.hh"
+#include "store-api.hh"
+#include "common-args.hh"
+
+using namespace nix;
+
+namespace rust {
+
+// Depending on the internal representation of Rust slices is slightly
+// evil...
+template<typename T> struct Slice
+{
+ const T * ptr;
+ size_t size;
+
+ Slice(const T * ptr, size_t size) : ptr(ptr), size(size)
+ {
+ assert(ptr);
+ }
+};
+
+struct StringSlice : Slice<char>
+{
+ StringSlice(const std::string & s): Slice(s.data(), s.size()) { }
+};
+
+}
+
+extern "C" {
+ bool unpack_tarfile(rust::Slice<uint8_t> data, rust::StringSlice dest_dir);
+}
+
+struct CmdTest : StoreCommand
+{
+ CmdTest()
+ {
+ }
+
+ std::string name() override
+ {
+ return "test";
+ }
+
+ std::string description() override
+ {
+ return "bla bla";
+ }
+
+ void run(ref<Store> store) override
+ {
+ auto data = readFile("./nix-2.2.tar");
+
+ std::string destDir = "./dest";
+
+ deletePath(destDir);
+
+ unpack_tarfile({(uint8_t*) data.data(), data.size()}, destDir);
+ }
+};
+
+static RegisterCommand r(make_ref<CmdTest>());