Skip to content

Minimal TH test for windows DLL #2208

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

Merged
merged 2 commits into from
Jun 4, 2024
Merged
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
6 changes: 3 additions & 3 deletions flake.lock

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

4 changes: 2 additions & 2 deletions overlays/mingw_w64.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ let
# Not sure why this `unset` helps. It might avoids some kind of overflow issue. We see `wine` fail to start when building `cardano-wallet-cli` test `unit`.
unset pkgsHostTargetAsString
unset LINK_DLL_FOLDERS
WINEDLLOVERRIDES="winemac.drv=d" WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag WINEPREFIX=$TMP ${wine}/bin/wine64 $REMOTE_ISERV/${interpreter.exeName} tmp $PORT $ISERV_ARGS &
WINEDLLOVERRIDES="winemac.drv=d" WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag WINEPREFIX=$TMP ${wine}/bin/wine64 $REMOTE_ISERV/${interpreter.exeName} tmp $PORT --no-load-call $ISERV_ARGS &
(>&2 echo "---| ${interpreter.exeName} should have started on $PORT")
RISERV_PID="$!"
ISERV_TARGET=WINE ${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT" $PROXY_ARGS
ISERV_TARGET=WINE ${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT" --no-load-call $PROXY_ARGS
(>&2 echo "---> killing ${interpreter.exeName}...")
kill $RISERV_PID
'';
Expand Down
1 change: 1 addition & 0 deletions test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ let
githash = haskell-nix.callPackage ./githash { inherit compiler-nix-name evalPackages; testSrc = testSrcWithGitDir; };
c-ffi = callTest ./c-ffi { inherit util; };
th-dlls = callTest ./th-dlls { inherit util; };
th-dlls-minimal = callTest ./th-dlls-minimal { inherit util; };
external-static-plugin = callTest ./external-static-plugin {};
exe-dlls = callTest ./exe-dlls { inherit util; };
exe-lib-dlls = callTest ./exe-lib-dlls { inherit util; };
Expand Down
9 changes: 9 additions & 0 deletions test/th-dlls-minimal/apps/Main.hs
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|]
3 changes: 3 additions & 0 deletions test/th-dlls-minimal/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
./.
./test-lib
43 changes: 43 additions & 0 deletions test/th-dlls-minimal/default.nix
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;
}
8 changes: 8 additions & 0 deletions test/th-dlls-minimal/src/Lib.hs
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))
16 changes: 16 additions & 0 deletions test/th-dlls-minimal/test-clib/Makefile
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

5 changes: 5 additions & 0 deletions test/th-dlls-minimal/test-clib/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int f()
{
return 42;
}

11 changes: 11 additions & 0 deletions test/th-dlls-minimal/test-lib/src/MyLib.hs
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
15 changes: 15 additions & 0 deletions test/th-dlls-minimal/test-lib/test-lib.cabal
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: [email protected]
build-type: Simple

library
build-depends: base
exposed-modules: MyLib
hs-source-dirs: src
extra-libraries: test-clib
default-language: Haskell2010

21 changes: 21 additions & 0 deletions test/th-dlls-minimal/th-dlls-minimal.cabal
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: [email protected]
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