Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards nix lib path discovery #65

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ libraryBuildInfo
-> IO HookedBuildInfo
libraryBuildInfo verbosity profile installPath platform@(Platform arch os) ghcVersion extraLibs extraIncludes = do
let
libraryPaths = cudaLibraryPath platform installPath : extraLibs
libraryPaths = cudaLibraryPaths platform installPath <> extraLibs
includePaths = cudaIncludePath platform installPath : extraIncludes

takeFirstExisting paths = do
Expand Down Expand Up @@ -214,16 +214,16 @@ cudaIncludePath _ installPath = installPath </> "include"

-- Return the location of the libraries relative to the base CUDA installation.
--
cudaLibraryPath :: Platform -> FilePath -> FilePath
cudaLibraryPath (Platform arch os) installPath = installPath </> libpath
cudaLibraryPaths :: Platform -> FilePath -> [FilePath]
cudaLibraryPaths (Platform arch os) installPath = (</>) <$> [installPath] <*> libpath
where
libpath =
case (os, arch) of
(Windows, I386) -> "lib/Win32"
(Windows, X86_64) -> "lib/x64"
(OSX, _) -> "lib" -- MacOS does not distinguish 32- vs. 64-bit paths
(_, X86_64) -> "lib64" -- treat all others similarly
_ -> "lib"
(Windows, I386) -> ["lib/Win32"]
(Windows, X86_64) -> ["lib/x64"]
(OSX, _) -> ["lib"] -- MacOS does not distinguish 32- vs. 64-bit paths
(_, X86_64) -> ["lib64", "lib"] -- Prefer lib64, but the nixpkgs distriubtion of cudatools moves files to lib. - AM
_ -> ["lib"]


-- On Windows and OSX we use different libraries depending on whether we are
Expand All @@ -233,6 +233,7 @@ cudaLibraries :: Platform -> [String]
cudaLibraries (Platform _ os) =
case os of
OSX -> ["cudadevrt", "cudart_static"]
Linux -> ["cudadevrt"]
_ -> ["cudart", "cuda"]

cudaGHCiLibraries
Expand Down Expand Up @@ -261,7 +262,9 @@ cudaGhciLibrariesWindows
-> [FilePath]
-> IO [FilePath]
cudaGhciLibrariesWindows platform installPath libraries = do
candidates <- mapM (importLibraryToDLLFileName platform) [ cudaLibraryPath platform installPath </> lib <.> "lib" | lib <- libraries ]
let pathRoots = cudaLibraryPaths platform installPath
let toLibPath path lib = path </> lib <.> "lib"
candidates <- mapM (importLibraryToDLLFileName platform) (toLibPath <$> pathRoots <*> libraries)
return [ dropExtension dll | Just dll <- candidates ]


Expand Down
4 changes: 4 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [ pkgs.git pkgs.ghc pkgs.cabal-install ];
}