-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aiden Fox Ivey <[email protected]>
- Loading branch information
1 parent
189e306
commit 13d5c87
Showing
3 changed files
with
115 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,87 @@ | ||
# To develop: | ||
# | ||
# nix develop | ||
# cmake -B build -GNinja | ||
# ninja -C build | ||
# | ||
# To build: | ||
# nix build .#static | ||
# nix build .#shared | ||
|
||
{ | ||
inputs = { | ||
# we need this to access nix packages | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
# we need this to build for each system | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
outputs = { self, nixpkgs, flake-utils }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
name = "liboqs"; | ||
version = "0.8.0"; | ||
src = ./.; | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
outputs = { | ||
self, | ||
nixpkgs, | ||
flake-utils, | ||
}: | ||
flake-utils.lib.eachDefaultSystem (system: let | ||
name = "liboqs"; | ||
src = ./.; | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
|
||
# function to create derivation with configurable shared lib option | ||
mkLib = shared: pkgs.stdenv.mkDerivation { | ||
inherit name src; | ||
# Function to create compiler-specific package sets | ||
mkPackageSet = compiler: let | ||
# Override the stdenv to use the specified compiler | ||
stdenv = | ||
if compiler == "clang" | ||
then pkgs.clangStdenv | ||
else pkgs.stdenv; | ||
|
||
# build-time dependencies | ||
nativeBuildInputs = with pkgs; [ | ||
cmake | ||
ninja | ||
doxygen | ||
pkg-config | ||
graphviz | ||
gcc | ||
]; | ||
mkLib = shared: | ||
stdenv.mkDerivation { | ||
inherit name src; | ||
nativeBuildInputs = with pkgs; | ||
[cmake ninja doxygen pkg-config graphviz] | ||
++ ( | ||
if compiler == "clang" | ||
then [pkgs.clang] | ||
else [pkgs.gcc] | ||
); | ||
|
||
# run-time dependencies | ||
buildInputs = with pkgs; [ | ||
openssl | ||
]; | ||
buildInputs = with pkgs; [openssl]; | ||
|
||
cmakeFlags = [ | ||
"-GNinja" | ||
"-DOQS_DIST_BUILD=ON" | ||
"-DOQS_BUILD_ONLY_LIB=ON" | ||
"-DBUILD_SHARED_LIBS=${if shared then "ON" else "OFF"}" | ||
"-DCMAKE_INSTALL_LIBDIR=lib" | ||
"-DCMAKE_INSTALL_INCLUDEDIR=include" | ||
"-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" | ||
"-DCMAKE_INSTALL_FULL_LIBDIR=${placeholder "out"}/lib" | ||
"-DCMAKE_INSTALL_FULL_INCLUDEDIR=${placeholder "out"}/include" | ||
]; | ||
}; | ||
in | ||
{ | ||
# default package builds shared library | ||
packages.default = mkLib true; | ||
cmakeFlags = [ | ||
"-GNinja" | ||
"-DOQS_DIST_BUILD=ON" | ||
"-DOQS_BUILD_ONLY_LIB=ON" | ||
"-DBUILD_SHARED_LIBS=${ | ||
if shared | ||
then "ON" | ||
else "OFF" | ||
}" | ||
"-DCMAKE_INSTALL_LIBDIR=lib" | ||
"-DCMAKE_INSTALL_INCLUDEDIR=include" | ||
"-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" | ||
"-DCMAKE_INSTALL_FULL_LIBDIR=${placeholder "out"}/lib" | ||
"-DCMAKE_INSTALL_FULL_INCLUDEDIR=${placeholder "out"}/include" | ||
]; | ||
}; | ||
in { | ||
shared = mkLib true; | ||
static = mkLib false; | ||
}; | ||
|
||
packages = { | ||
shared = mkLib true; | ||
static = mkLib false; | ||
}; | ||
|
||
devShells.default = pkgs.mkShell { | ||
# use runtime and build time dependencies | ||
inherit (self.packages.${system}.default) | ||
nativeBuildInputs | ||
buildInputs; | ||
# Create development shell for specified compiler | ||
mkDevShell = compiler: let | ||
packageSet = mkPackageSet compiler; | ||
in | ||
pkgs.mkShell { | ||
inherit (packageSet.shared) nativeBuildInputs buildInputs; | ||
|
||
# development only packages | ||
packages = with pkgs; [ | ||
astyle | ||
]; | ||
# astyle formats C source code and alejandra formats nix source code | ||
packages = with pkgs; [astyle alejandra]; | ||
|
||
# export compile commands to simplify | ||
shellHook = '' | ||
export CMAKE_EXPORT_COMPILE_COMMANDS=1 | ||
echo "Using ${compiler} toolchain" | ||
''; | ||
}; | ||
} | ||
); | ||
} | ||
in { | ||
packages = { | ||
default = (mkPackageSet "gcc").shared; # default is gcc shared | ||
gcc = mkPackageSet "gcc"; | ||
clang = mkPackageSet "clang"; | ||
}; | ||
|
||
# Development shells | ||
devShells = { | ||
default = mkDevShell "gcc"; | ||
gcc = mkDevShell "gcc"; | ||
clang = mkDevShell "clang"; | ||
}; | ||
}); | ||
} |