Skip to content

Commit

Permalink
improvements to the build system
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbarter committed Nov 15, 2022
1 parent 4130a62 commit 559da62
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 52 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
build
result
result
.envrc
.cache
compile_commands.json
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RNMC depends on [GSL](https://www.gnu.org/software/gsl/) for pseudo random numbe

On a machine with system versions of GSL and sqlite, the executables can be built like this:
```
CC=g++ ./build.sh
./build.sh
```
The executables are put in the `build` directory. Note that the build script uses the `gsl-config` utility to find headers and libraries for GSL. If you are on a cluster and sqlite is not present, it can be built as follows:

Expand All @@ -32,7 +32,7 @@ in which case, the simulators can be built like this:
```
export CPATH=$HOME/sqlite-amalgamation-3360000:$CPATH
export LIBRARY_PATH=$HOME/sqlite-amalgamation-3360000:$LIBRARY_PATH
CC=g++ ./build.sh
./build.sh
```

### Testing
Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ mkdir -p build
flags="-fno-rtti -fno-exceptions -std=c++17 -Wall -Wextra -g $(gsl-config --cflags) $(gsl-config --libs) -lsqlite3 -lpthread"

echo "building test_core"
$CC $flags ./core/test.cpp -o ./build/test_core
$CXX $flags ./core/test.cpp -o ./build/test_core
echo "building GMC"
$CC $flags ./GMC/GMC.cpp -o ./build/GMC
$CXX $flags ./GMC/GMC.cpp -o ./build/GMC
echo "building NPMC"
$CC $flags ./NPMC/NPMC.cpp -o ./build/NPMC
$CXX $flags ./NPMC/NPMC.cpp -o ./build/NPMC
3 changes: 0 additions & 3 deletions compile_flags.txt

This file was deleted.

5 changes: 1 addition & 4 deletions core/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ struct SimulatorPayload {
break;
}


history_queue.insert_history(
std::move(
HistoryPacket {
.history = std::move(simulation.history),
.seed = seed
}));
});

}

Expand Down Expand Up @@ -216,7 +214,6 @@ template <
void Dispatcher<Solver, Model, Parameters, TrajectoriesSql>::record_simulation_history(HistoryPacket history_packet) {
initial_state_database.exec("BEGIN");


for (unsigned long int i = 0; i < history_packet.history.size(); i++) {
trajectories_writer.insert(
model.history_element_to_sql(
Expand Down
3 changes: 1 addition & 2 deletions core/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ bool Simulation<Solver, Model>::execute_step() {

if ( history.size() == history_chunk_size ) {
history_queue.insert_history(
std::move(
HistoryPacket {
.history = std::move(history),
.seed = seed
}));
});

history = std::vector<HistoryElement> ();
history.reserve(history_chunk_size);
Expand Down
25 changes: 21 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 15 additions & 33 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,44 @@
description = "High performance Monte Carlo simulator";

inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
nixpkgs.url = github:NixOS/nixpkgs/master;
flake-compat = {
url = github:edolstra/flake-compat;
flake = false;
};
mini-compile-commands = {
url = github:danielbarter/mini_compile_commands;
flake = false;
};
};

outputs = { self, nixpkgs, flake-compat }:
outputs = { self, nixpkgs, flake-compat, mini-compile-commands }:

# RNMC is so simple that the build derivation looks exactly the same on
# all platforms.
let genericDefaultPackage = systemString:
with import nixpkgs { system = systemString; };
stdenv.mkDerivation {
clang13Stdenv.mkDerivation {
name = "RNMC";
src = self;

buildInputs = [
clang
gsl
sqlite
];


buildPhase = "CC=clang++ ./build.sh";
buildPhase = "./build.sh";
installPhase = "mkdir -p $out/bin; mv ./build/* $out/bin";
doCheck = true;
checkPhase = "./test.sh";

};

in {
devShell.x86_64-linux =
with import nixpkgs { system = "x86_64-linux"; };
mkShell {

# (mkShell.override { stdenv = (callPackage mini-compile-commands {}).wrap clang13Stdenv; }) {
(mkShell.override { stdenv = clang13Stdenv; }) {
buildInputs = [
gcc
clang
Expand All @@ -45,25 +48,6 @@
sqlitebrowser
gdb
valgrind
bintools-unwrapped # gprof
];

# environment for CLANGD
# CPATH=$CLANGD_PATH emacs
CLANGD_PATH = builtins.concatStringsSep ":" [

# C++ stdlib headers
"${gcc-unwrapped}/include/c++/10.3.0"
"${gcc-unwrapped}/include/c++/10.3.0/x86_64-unknown-linux-gnu"

# libc headers
"${glibc.dev}/include"

# compiler specific headers
"${clang}/resource-root/include"

"${sqlite.dev}/include"
"${gsl}/include"
];
};

Expand All @@ -72,11 +56,9 @@
x86_64-darwin = genericDefaultPackage "x86_64-darwin";
};

checks = {
x86_64-linux.tests = genericDefaultPackage "x86_64-linux";
x86_64-darwin.tests = genericDefaultPackage "x86_64-darwin";

};

checks = {
x86_64-linux.tests = genericDefaultPackage "x86_64-linux";
x86_64-darwin.tests = genericDefaultPackage "x86_64-darwin";
};
};
}

0 comments on commit 559da62

Please sign in to comment.