mirror of
https://github.com/NixOS/nix
synced 2025-07-07 01:51:47 +02:00
Add some Rust code
This commit is contained in:
parent
abb8ef619b
commit
11da5b2816
10 changed files with 194 additions and 3 deletions
|
@ -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, \
|
||||
|
|
61
src/nix/test.cc
Normal file
61
src/nix/test.cc
Normal file
|
@ -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>());
|
Loading…
Add table
Add a link
Reference in a new issue