Skip to content
Open
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
7 changes: 4 additions & 3 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
# TODO: Remove --ignore-glob for ghc-supported-languages.hs when this module compiles
- --ignore-glob=Cabal-tests/tests/misc/ghc-supported-languages.hs
- --ignore-glob=cabal-testsuite/PackageTests/BuildWays/q/app/Main.hs
- --ignore-glob=cabal-testsuite/PackageTests/CppOptions/CppOpts/Main.hs
- --ignore-glob=cabal-testsuite/PackageTests/CMain/10168/src/Lib.hs
- --ignore-glob=cabal-testsuite/PackageTests/CmmSources/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/CmmSourcesDyn/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/CmmSourcesExe/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/Cmm/CmmSources/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/Cmm/CmmSourcesDyn/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/Cmm/CmmSourcesExe/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/NewBuild/CmdRun/Script/script.hs
- --ignore-glob=cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptLiterate/script.lhs
- --ignore-glob=cabal-testsuite/PackageTests/Regression/T5309/lib/Bio/Character/Exportable/Class.hs
Expand Down
15 changes: 15 additions & 0 deletions cabal-testsuite/PackageTests/CppOptions/CppOpts/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{-# LANGUAGE CPP #-}

module Main where

#ifndef __TESTOPT_CPP__
#error "Did not get required __TESTOPT_CPP__ from cpp-options"
#endif

main :: IO ()
main = do
-- The value 44 comes from __TESTOPT_CPP__ - see the cabal file.
let secret = __TESTOPT_CPP__ :: Int
if (secret == 44)
then putStrLn ("The secret is " ++ show secret)
else error ("Expected value 44, got " ++ show secret)
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/CppOptions/CppOpts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CppOpts

This test case asserts that cabal passes `cpp-options` to the C preprocessor when compiling Haskell source files that use the `CPP` language extension.
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/CppOptions/CppOpts/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- cpp-opts-0.1 (exe:cpp-opts-exe) (first run)
Configuring executable 'cpp-opts-exe' for cpp-opts-0.1...
Preprocessing executable 'cpp-opts-exe' for cpp-opts-0.1...
Building executable 'cpp-opts-exe' for cpp-opts-0.1...
# cpp-opts cpp-opts-exe
The secret is 44
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/CppOptions/CppOpts/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Test.Cabal.Prelude
main = cabalTest $ do
cabal "v2-build" ["cpp-opts-exe"]
withPlan $ runPlanExe "cpp-opts" "cpp-opts-exe" []
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/CppOptions/CppOpts/cpp-opts.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 2.2
name: cpp-opts
version: 0.1
build-type: Simple

executable cpp-opts-exe
main-is: Main.hs
build-depends: base
default-language: Haskell2010
cpp-options: -D__TESTOPT_CPP__=44
16 changes: 16 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsAsm/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{-# LANGUAGE ForeignFunctionInterface #-}

module Main where

import Foreign.C (CInt (..))

foreign import ccall "asmlib.h meaning_of_life_asm"
meaning_of_life_asm :: IO CInt

main :: IO ()
main = do
secret <- meaning_of_life_asm
-- The value 33 comes from meaning_of_life_val - see asm-options in the cabal file.
if (secret == 33)
then putStrLn ("The secret is " ++ show secret)
else error ("Expected value 33, got " ++ show secret)
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsAsm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ForeignOptsAsm

This test case asserts that cabal passes `asm-options` to the assembler when compiling assembly source files.

The test uses `asm-options: -Wa,--defsym,meaning_of_life_val=33` which routes through GHC's `-opta` flag to `gcc`, which then passes `--defsym meaning_of_life_val=33` to the actual GNU assembler. The assembly source file references `meaning_of_life_val` as an immediate operand; if the define is not passed, the assembler will fail with an undefined symbol error.

This test is skipped on macOS (which uses Apple's assembler, not GNU as) and on non-x86_64/aarch64 architectures.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef ASMLIB_H
#define ASMLIB_H

int meaning_of_life_asm();

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.text
.globl meaning_of_life_asm
.type meaning_of_life_asm, @function
// meaning_of_life_val must be defined via --defsym from asm-options.
// If asm-options are not passed, the assembler will fail here.
meaning_of_life_asm:
mov w0, #meaning_of_life_val
ret
.size meaning_of_life_asm, .-meaning_of_life_asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.text
.globl meaning_of_life_asm
.type meaning_of_life_asm, @function
# meaning_of_life_val must be defined via --defsym from asm-options.
# If asm-options are not passed, the assembler will fail here.
meaning_of_life_asm:
movl $meaning_of_life_val, %eax
ret
.size meaning_of_life_asm, .-meaning_of_life_asm
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsAsm/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- foreign-opts-asm-0.1 (exe:foreign-opts-asm-exe) (first run)
Configuring executable 'foreign-opts-asm-exe' for foreign-opts-asm-0.1...
Preprocessing executable 'foreign-opts-asm-exe' for foreign-opts-asm-0.1...
Building executable 'foreign-opts-asm-exe' for foreign-opts-asm-0.1...
# foreign-opts-asm foreign-opts-asm-exe
The secret is 33
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsAsm/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Test.Cabal.Prelude
import Distribution.System (Arch (X86_64, AArch64), buildArch)

main = do
skipIfOSX "Apple assembler does not support --defsym"
skipIfWindows "TODO: investigate Windows assembly support"
skipUnlessIO "needs x86_64 or aarch64" (buildArch `elem` [X86_64, AArch64])
cabalTest $ do
cabal "v2-build" ["foreign-opts-asm-exe"]
withPlan $ runPlanExe "foreign-opts-asm" "foreign-opts-asm-exe" []
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cabal-version: 3.0
name: foreign-opts-asm
version: 0.1
build-type: Simple

executable foreign-opts-asm-exe
main-is: Main.hs
build-depends: base
default-language: Haskell2010
include-dirs: abits
if arch(x86_64)
asm-sources: abits/asmlib_x86_64.s
elif arch(aarch64)
asm-sources: abits/asmlib_aarch64.s
-- The value 33 is passed to the assembler via -Wa,--defsym (which routes
-- through gcc into the actual assembler) and used as an immediate operand
-- in the assembly source.
asm-options: -Wa,--defsym,meaning_of_life_val=33
18 changes: 18 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-# LANGUAGE ForeignFunctionInterface #-}

module Main where

import Foreign.C (CInt (..))

-- With ld-options: -Wl,--wrap=meaning_of_life_ld_real, the linker redirects
-- this call to __wrap_meaning_of_life_ld_real, which returns 55.
foreign import ccall "ldlib.h meaning_of_life_ld_real"
meaning_of_life_ld_real :: IO CInt

main :: IO ()
main = do
secret <- meaning_of_life_ld_real
-- The value 55 comes from __wrap_meaning_of_life_ld_real - see ld-options in the cabal file.
if (secret == 55)
then putStrLn ("The secret is " ++ show secret)
else error ("Expected value 55, got " ++ show secret)
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ForeignOptsLd

This test case asserts that cabal passes `ld-options` to the linker.

The test uses `ld-options: -Wl,--wrap=meaning_of_life_ld_real` which instructs the GNU linker to redirect all calls to `meaning_of_life_ld_real` to `__wrap_meaning_of_life_ld_real` instead. The real function returns 0; the wrapper function returns 55. If `ld-options` were not passed, the real function would be called and the test would fail with an unexpected value.

This test is skipped on macOS (which uses Apple's linker, not GNU ld) and on Windows.
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- foreign-opts-ld-0.1 (exe:foreign-opts-ld-exe) (first run)
Configuring executable 'foreign-opts-ld-exe' for foreign-opts-ld-0.1...
Preprocessing executable 'foreign-opts-ld-exe' for foreign-opts-ld-0.1...
Building executable 'foreign-opts-ld-exe' for foreign-opts-ld-0.1...
# foreign-opts-ld foreign-opts-ld-exe
The secret is 55
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Test.Cabal.Prelude

main = do
skipIfOSX "Apple linker does not support --wrap"
skipIfWindows "Windows linker does not support --wrap"
cabalTest $ do
cabal "v2-build" ["foreign-opts-ld-exe"]
withPlan $ runPlanExe "foreign-opts-ld" "foreign-opts-ld-exe" []
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/cbits/ldlib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "ldlib.h"

/* The "real" implementation - returns 0, the wrong value.
* With ld-options: -Wl,--wrap=meaning_of_life_ld_real, the linker redirects
* all calls to this function to __wrap_meaning_of_life_ld_real below. */
int meaning_of_life_ld_real() {
return 0;
}

/* The wrapper that the linker substitutes in place of the real function.
* Returns 55 - see ld-options in the cabal file. */
int __wrap_meaning_of_life_ld_real() {
return 55;
}
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/cbits/ldlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef LDLIB_H
#define LDLIB_H

/* The "real" function; with --wrap, calls to this are redirected by the linker. */
int meaning_of_life_ld_real();

/* The wrapper that the linker calls instead of the real function. */
int __wrap_meaning_of_life_ld_real();

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cabal-version: 2.2
name: foreign-opts-ld
version: 0.1
build-type: Simple

executable foreign-opts-ld-exe
main-is: Main.hs
build-depends: base
default-language: Haskell2010
include-dirs: cbits
c-sources: cbits/ldlib.c
-- Redirect calls to meaning_of_life_ld_real to __wrap_meaning_of_life_ld_real.
-- If ld-options are not passed the real function (returning 0) is called instead
-- of the wrapper (returning 55), and the test fails at runtime.
ld-options: -Wl,--wrap=meaning_of_life_ld_real
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/JS/JSPPOptions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# JSPPOptions

This asserts that cabal passes `jspp-options` to the JavaScript-preprocessor.
Loading