Skip to content

Commit

Permalink
Define the right RTS config in the Windows dyn wrapper programs
Browse files Browse the repository at this point in the history
This is particularly important as without it validate fails, as it
tries to pass RTS options to haddock, and with the default RTS config
those options aren't permitted.
  • Loading branch information
Ian Lynagh committed May 14, 2013
1 parent 2c9cb4d commit 192c7b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions driver/utils/dynwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Need to concatenate this file with something that defines:
LPTSTR path_dirs[];
LPTSTR progDll;
LPTSTR rtsDll;
int rtsOpts;
*/

#include <stdarg.h>
Expand Down Expand Up @@ -161,7 +162,7 @@ int main(int argc, char *argv[]) {
LPTSTR oldPath;

StgClosure *main_p;
RtsConfig *rts_config_p;
RtsConfig rts_config;
hs_main_t hs_main_p;

// MSDN says: An environment variable has a maximum size limit of
Expand Down Expand Up @@ -189,9 +190,10 @@ int main(int argc, char *argv[]) {
hRtsDll = GetNonNullModuleHandle(rtsDll);

hs_main_p = GetNonNullProcAddress(hRtsDll, "hs_main");
rts_config_p = GetNonNullProcAddress(hRtsDll, "defaultRtsConfig");
main_p = GetNonNullProcAddress(hProgDll, "ZCMain_main_closure");
rts_config.rts_opts_enabled = rtsOpts;
rts_config.rts_opts = NULL;

return hs_main_p(argc, argv, main_p, *rts_config_p);
return hs_main_p(argc, argv, main_p, rts_config);
}

17 changes: 17 additions & 0 deletions rules/build-prog.mk
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,32 @@ endif

ifeq "$$($1_$2_PROG_NEEDS_C_WRAPPER)" "YES"

$1_$2_RTS_OPTS_FLAG = $$(lastword $$(filter -rtsopts -rtsopts=all -rtsopts=some -rtsopts=none -no-rtsopts,$$($1_$2_$$($1_$2_PROGRAM_WAY)_ALL_HC_OPTS)))
ifeq "$$($1_$2_RTS_OPTS_FLAG)" "-rtsopts"
$1_$2_RTS_OPTS = RtsOptsAll
else ifeq "$$($1_$2_RTS_OPTS_FLAG)" "-rtsopts=all"
$1_$2_RTS_OPTS = RtsOptsAll
else ifeq "$$($1_$2_RTS_OPTS_FLAG)" "-rtsopts=some"
$1_$2_RTS_OPTS = RtsOptsSafeOnly
else ifeq "$$($1_$2_RTS_OPTS_FLAG)" "-rtsopts=none"
$1_$2_RTS_OPTS = RtsOptsNone
else ifeq "$$($1_$2_RTS_OPTS_FLAG)" "-no-rtsopts"
$1_$2_RTS_OPTS = RtsOptsNone
else
$1_$2_RTS_OPTS = RtsOptsSafeOnly
endif

$1/$2/build/tmp/$$($1_$2_PROG)-inplace-wrapper.c: driver/utils/dynwrapper.c | $$$$(dir $$$$@)/.
$$(call removeFiles,$$@)
echo '#include <Windows.h>' >> $$@
echo '#include "Rts.h"' >> $$@
echo 'LPTSTR path_dirs[] = {' >> $$@
$$(foreach d,$$($1_$2_DEP_LIB_REL_DIRS),$$(call make-command,echo ' TEXT("$$d")$$(comma)' >> $$@))
echo ' TEXT("$1/$2/build/tmp/"),' >> $$@
echo ' NULL};' >> $$@
echo 'LPTSTR progDll = TEXT("../../$1/$2/build/tmp/$$($1_$2_PROG).dll");' >> $$@
echo 'LPTSTR rtsDll = TEXT("$$($$(WINDOWS_DYN_PROG_RTS))");' >> $$@
echo 'int rtsOpts = $$($1_$2_RTS_OPTS);' >> $$@
cat driver/utils/dynwrapper.c >> $$@

$1/$2/build/tmp/$$($1_$2_PROG) : $1/$2/build/tmp/$$($1_$2_PROG)-inplace-wrapper.c $1/$2/build/tmp/$$($1_$2_PROG).dll | $$$$(dir $$$$@)/.
Expand Down

0 comments on commit 192c7b7

Please sign in to comment.