-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal TH test for windows DLL (#2208)
* Minimal TH test for windows DLL * Use `--no-load-call` for windows cross compilation TH proxy & interpreter
- Loading branch information
1 parent
218d5a8
commit de29feb
Showing
12 changed files
with
137 additions
and
5 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Main where | ||
|
||
import Language.Haskell.TH | ||
|
||
main :: IO () | ||
main = putStrLn "Hello, Haskell!" | ||
|
||
[d|y = 0|] |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
packages: | ||
./. | ||
./test-lib |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Test building TH code that needs DLLs when cross compiling for windows | ||
{ stdenv, lib, util, project', haskellLib, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages, buildPackages }: | ||
|
||
with lib; | ||
|
||
let | ||
project = externalInterpreter: project' { | ||
inherit compiler-nix-name evalPackages; | ||
src = testSrc "th-dlls-minimal"; | ||
cabalProjectLocal = builtins.readFile ../cabal.project.local; | ||
modules = [ | ||
({pkgs, ...}: { | ||
packages.test-lib.components.library.libs = mkForce [ | ||
(pkgs.stdenv.mkDerivation { | ||
name = "test-clib"; | ||
version = "1.0"; | ||
src = testSrc "th-dlls-minimal/test-clib"; | ||
}) | ||
]; | ||
}) | ||
({pkgs, ...}: lib.optionalAttrs externalInterpreter { | ||
packages.th-dlls-minimal.components.library.ghcOptions = [ "-fexternal-interpreter" ]; | ||
})]; | ||
}; | ||
|
||
packages = (project false).hsPkgs; | ||
packages-ei = (project true).hsPkgs; | ||
|
||
in recurseIntoAttrs { | ||
# This test is just for windows currently (the full th-dlls test runs on other platforms) | ||
meta.disabled = !stdenv.hostPlatform.isWindows; | ||
|
||
ifdInputs = { | ||
inherit (project true) plan-nix; | ||
}; | ||
|
||
build = packages.th-dlls-minimal.components.library; | ||
build-profiled = packages.th-dlls-minimal.components.library.profiled; | ||
just-template-haskell = packages.th-dlls-minimal.components.exes.just-template-haskell; | ||
build-ei = packages-ei.th-dlls-minimal.components.library; | ||
build-profiled-ei = packages-ei.th-dlls-minimal.components.library.profiled; | ||
just-template-haskell-ei = packages-ei.th-dlls-minimal.components.exes.just-template-haskell; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Lib where | ||
|
||
import Control.Monad.IO.Class (liftIO) | ||
import Language.Haskell.TH.Syntax (Exp(..), Lit(..)) | ||
import MyLib (someFunc) | ||
|
||
a = $(liftIO (LitE . IntegerL . fromIntegral <$> someFunc)) |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
test.o: test.c | ||
$(CC) -o test.o -c test.c | ||
|
||
test.a: test.o | ||
$(AR) -rs test-clib.a test.o | ||
|
||
test.dll: test.o | ||
$(CC) -o test-clib.dll -shared test.o | ||
|
||
.PHONY: install | ||
install: test.a test.dll | ||
mkdir $(out)/bin | ||
mkdir $(out)/lib | ||
mv test-clib.dll $(out)/bin | ||
mv test-clib.a $(out)/lib | ||
|
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int f() | ||
{ | ||
return 42; | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{-# LANGUAGE ForeignFunctionInterface #-} | ||
module MyLib (someFunc) where | ||
|
||
import Foreign.C.Types (CInt(..)) | ||
|
||
foreign import ccall "f" c_f :: IO CInt | ||
|
||
someFunc :: IO CInt | ||
someFunc = do | ||
putStrLn "someFunc called" | ||
c_f |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cabal-version: >=1.10 | ||
name: test-lib | ||
version: 0.1.0.0 | ||
license: PublicDomain | ||
author: Hamish Mackenzie | ||
maintainer: Hamish.K.Mackenzie@gmail.com | ||
build-type: Simple | ||
|
||
library | ||
build-depends: base | ||
exposed-modules: MyLib | ||
hs-source-dirs: src | ||
extra-libraries: test-clib | ||
default-language: Haskell2010 | ||
|
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cabal-version: >=1.10 | ||
name: th-dlls-minimal | ||
version: 0.1.0.0 | ||
license: PublicDomain | ||
author: Hamish Mackenzie | ||
maintainer: Hamish.K.Mackenzie@gmail.com | ||
build-type: Simple | ||
|
||
library | ||
build-depends: base | ||
, template-haskell | ||
, test-lib | ||
exposed-modules: Lib | ||
hs-source-dirs: src | ||
default-language: Haskell2010 | ||
|
||
executable just-template-haskell | ||
build-depends: base, template-haskell | ||
hs-source-dirs: apps | ||
default-language: Haskell2010 | ||
main-is: Main.hs |