Skip to content

Commit

Permalink
Add missing Windows templates (#10)
Browse files Browse the repository at this point in the history
Compiling jiffy on Windows doesn't work because
of two missing templates for the default environment.

Ported these settings from the rebar3 port compiler [1].

[1] https://github.com/blt/port_compiler/blob/935c20744b6f0adf8e6ea92e3da939aae2064b0f/src/pc_port_env.erl
  • Loading branch information
big-r81 authored Jun 5, 2024
1 parent 58c311b commit 7b084c7
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/rebar_port_compiler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,22 @@ target_type1(".dll") -> drv;
target_type1("") -> exe;
target_type1(".exe") -> exe.


erl_interface_dir(Subdir) ->
case code:lib_dir(erl_interface, Subdir) of
case filename:join(code:lib_dir(erl_interface), Subdir) of
{error, bad_name} ->
throw({error, {erl_interface,Subdir,"code:lib_dir(erl_interface)"
"is unable to find the erl_interface library."}});
Dir -> Dir
end.

default_env() ->
ErlInterfaceIncludeDir = erl_interface_dir(include),
ErlInterfaceHeader = filename:join(ErlInterfaceIncludeDir, "erl_interface.h"),
ErlInterfaceLibs = case filelib:is_file(ErlInterfaceHeader) of
true -> ["erl_interface", "ei"];
false -> ["ei"]
end,
Arch = os:getenv("REBAR_TARGET_ARCH"),
Vsn = os:getenv("REBAR_TARGET_ARCH_VSN"),
[
Expand All @@ -650,9 +657,9 @@ default_env() ->
{"DRV_CC_TEMPLATE",
"$CC -c $CFLAGS $DRV_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"},
{"DRV_LINK_TEMPLATE",
"$CC $PORT_IN_FILES $LDFLAGS $DRV_LDFLAGS -o $PORT_OUT_FILE"},
"$CC $PORT_IN_FILES $LDFLAGS $LDLIBS $DRV_LDFLAGS -o $PORT_OUT_FILE"},
{"DRV_LINK_CXX_TEMPLATE",
"$CXX $PORT_IN_FILES $LDFLAGS $DRV_LDFLAGS -o $PORT_OUT_FILE"},
"$CXX $PORT_IN_FILES $LDFLAGS $LDLIBS $DRV_LDFLAGS -o $PORT_OUT_FILE"},
{"EXE_CXX_TEMPLATE",
"$CXX -c $CXXFLAGS $EXE_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"},
{"EXE_CC_TEMPLATE",
Expand All @@ -668,12 +675,13 @@ default_env() ->

{"ERL_CFLAGS", lists:concat(
[
" -I\"", erl_interface_dir(include),
" -I\"", ErlInterfaceIncludeDir,
"\" -I\"", filename:join(erts_dir(), "include"),
"\" "
])},
{"ERL_EI_LIBDIR", lists:concat(["\"", erl_interface_dir(lib), "\""])},
{"ERL_LDFLAGS" , " -L$ERL_EI_LIBDIR -lei"},
{"ERL_LDFLAGS" , lists:concat([" -L$ERL_EI_LIBDIR"] ++
[" -l"++EiLib || EiLib <- ErlInterfaceLibs])},
{"ERLANG_ARCH" , rebar_utils:wordsize()},
{"ERLANG_TARGET", rebar_utils:get_arch()},

Expand Down Expand Up @@ -712,16 +720,21 @@ default_env() ->
"$CC /c $CFLAGS $DRV_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"},
{"win32", "DRV_LINK_TEMPLATE",
"$LINKER $PORT_IN_FILES $LDFLAGS $DRV_LDFLAGS /OUT:$PORT_OUT_FILE"},
{"win32", "DRV_LINK_CXX_TEMPLATE",
"$LINKER $PORT_IN_FILES $LDFLAGS $DRV_LDFLAGS /OUT:$PORT_OUT_FILE"},
%% DRV_* and EXE_* Templates are identical
{"win32", "EXE_CXX_TEMPLATE",
"$CXX /c $CXXFLAGS $EXE_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"},
{"win32", "EXE_CC_TEMPLATE",
"$CC /c $CFLAGS $EXE_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"},
{"win32", "EXE_LINK_TEMPLATE",
"$LINKER $PORT_IN_FILES $LDFLAGS $EXE_LDFLAGS /OUT:$PORT_OUT_FILE"},
{"win32", "EXE_LINK_CXX_TEMPLATE",
"$LINKER $PORT_IN_FILES $LDFLAGS $EXE_LDFLAGS /OUT:$PORT_OUT_FILE"},
%% ERL_CFLAGS are ok as -I even though strictly it should be /I
{"win32", "ERL_LDFLAGS",
" /LIBPATH:$ERL_EI_LIBDIR ei.lib"},
lists:concat([" /LIBPATH:$ERL_EI_LIBDIR "] ++
[EiLib++".lib " || EiLib <- ErlInterfaceLibs])},
{"win32", "DRV_CFLAGS", "/Zi /Wall $ERL_CFLAGS"},
{"win32", "DRV_LDFLAGS", "/DLL $ERL_LDFLAGS"}
].
Expand Down

0 comments on commit 7b084c7

Please sign in to comment.