Skip to content

Commit

Permalink
hadrian: Generate HSC2HS_EXTRAS variable in bindist installation
Browse files Browse the repository at this point in the history
We must generate the hsc2hs wrapper at bindist installation time since
it must contain `--lflag` and `--cflag` arguments which depend upon the
installation path.

The solution here is to substitute these variables in the configure
script (see mk/hsc2hs.in). This is then copied over a dummy wrapper in
the install rules.

Fixes #24050.
  • Loading branch information
bgamari authored and Marge Bot committed Feb 21, 2024
1 parent d04f384 commit efcbad2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions distrib/configure.ac.in
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ FP_SETTINGS
AC_CONFIG_FILES([config.mk])
AC_CONFIG_FILES([default.host.target])
AC_CONFIG_FILES([default.target])
AC_CONFIG_FILES([mk/hsc2hs])
AC_OUTPUT

# We get caught by
Expand Down
7 changes: 6 additions & 1 deletion hadrian/bindist/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,18 @@ install_man:

export SHELL
.PHONY: install_wrappers
install_wrappers: install_bin_libdir
install_wrappers: install_bin_libdir install_hsc2hs_wrapper
@echo "Installing wrapper scripts"
$(INSTALL_DIR) "$(DESTDIR)$(WrapperBinsDir)"
for p in `cd wrappers; $(FIND) . ! -type d`; do \
mk/install_script.sh "$$p" "$(DESTDIR)/$(WrapperBinsDir)/$$p" "$(WrapperBinsDir)" "$(ActualBinsDir)" "$(ActualBinsDir)/$$p" "$(ActualLibsDir)" "$(docdir)" "$(includedir)"; \
done

.PHONY: install_hsc2hs_wrapper
install_hsc2hs_wrapper:
@echo Copying hsc2hs wrapper
cp mk/hsc2hs wrappers/hsc2hs-ghc-$(ProjectVersion)

PKG_CONFS = $(shell find "$(DESTDIR)$(ActualLibsDir)/package.conf.d" -name '*.conf' | sed "s: :\0xxx\0:g")
.PHONY: update_package_db
update_package_db: install_bin install_lib
Expand Down
14 changes: 2 additions & 12 deletions hadrian/src/Rules/BinaryDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import Target
import Utilities
import qualified System.Directory.Extra as IO
import Data.Either
import GHC.Toolchain (ccProgram, tgtCCompiler, ccLinkProgram, tgtCCompilerLink)
import GHC.Toolchain.Program (prgFlags)
import qualified Data.Set as Set
import Oracles.Flavour

Expand Down Expand Up @@ -400,6 +398,7 @@ bindistInstallFiles =
, "mk" -/- "project.mk"
, "mk" -/- "relpath.sh"
, "mk" -/- "system-cxx-std-lib-1.0.conf.in"
, "mk" -/- "hsc2hs.in"
, "mk" -/- "install_script.sh"
, "README", "INSTALL" ]

Expand Down Expand Up @@ -464,17 +463,8 @@ haddockWrapper = pure $ "exec \"$executablename\" -B\"$libdir\" -l\"$libdir\" ${
commonWrapper :: Action String
commonWrapper = pure $ "exec \"$executablename\" ${1+\"$@\"}\n"

-- echo 'HSC2HS_EXTRA="$(addprefix --cflag=,$(CONF_CC_OPTS_STAGE1)) $(addprefix --lflag=,$(CONF_GCC_LINKER_OPTS_STAGE1))"' >> "$(WRAPPER)"
hsc2hsWrapper :: Action String
hsc2hsWrapper = do
ccArgs <- map ("--cflag=" <>) . prgFlags . ccProgram . tgtCCompiler <$> targetStage Stage1
linkFlags <- map ("--lflag=" <>) . prgFlags . ccLinkProgram . tgtCCompilerLink <$> targetStage Stage1
wrapper <- drop 4 . lines <$> liftIO (readFile "utils/hsc2hs/hsc2hs.wrapper")
return $ unlines
( "HSC2HS_EXTRA=\"" <> unwords (ccArgs ++ linkFlags) <> "\""
: "tflag=\"--template=$libdir/template-hsc.h\""
: "Iflag=\"-I$includedir/\""
: wrapper )
hsc2hsWrapper = return "Copied from mk/hsc2hs"

runGhcWrapper :: Action String
runGhcWrapper = pure $ "exec \"$executablename\" -f \"$exedir/ghc\" ${1+\"$@\"}\n"
Expand Down
41 changes: 41 additions & 0 deletions mk/hsc2hs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
HSC2HS_C="@SettingsCCompilerFlags@"

HSC2HS_L="@SettingsCCompilerLinkFlags@"

tflag="--template=$libdir/template-hsc.h"
Iflag="-I$includedir/include/"

for f in ${HSC2HS_C}; do
cflags="${cflags} --cflag=$f"
done

for f in ${HSC2HS_L}; do
lflags="${lflags} --lflag=$f"
done

HSC2HS_EXTRA="$cflags $lflags"

read_response() {
response_file=$1
if [ -f "$response_file" ]; then
while read -r arg; do
case "$arg" in
-t*) tflag=;;
--template=*) tflag=;;
@*) read_response "${arg#"@"}" ;;
--) break;;
esac
done < "$response_file"
fi
}

for arg do
case "$arg" in
-t*) tflag=;;
--template=*) tflag=;;
@*) read_response "${arg#"@"}" ;;
--) break;;
esac
done

exec "$executablename" ${tflag:+"$tflag"} $HSC2HS_EXTRA ${1+"$@"} "$Iflag"

0 comments on commit efcbad2

Please sign in to comment.