Skip to content

Commit 9127cc1

Browse files
committed
Working on testing aarch64-linux noci
1 parent b9caa85 commit 9127cc1

10 files changed

Lines changed: 120 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,63 @@ jobs:
195195
"$TEST_ROOT/" \
196196
"$DEST"
197197
fi
198+
199+
# aarch64-linux test using QEMU binfmt emulation on the x86_64-linux runner
200+
# Requires: boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; on the NixOS runner
201+
test-aarch64-linux:
202+
name: "bash (aarch64-linux via emulation)"
203+
runs-on:
204+
- self-hosted
205+
- Linux
206+
steps:
207+
- uses: actions/checkout@v4
208+
with:
209+
submodules: recursive
210+
211+
- name: Build tests
212+
if: "!contains(github.event.head_commit.message, 'noci')"
213+
run: |
214+
cd tests
215+
216+
export NIX_PATH=nixpkgs=$(nix run .#nixpkgsPath)
217+
218+
export PATH=$(nix build --no-link .#stack --json | jq -r '.[0].outputs.out')/bin:$PATH
219+
export PATH=$(nix build --no-link .#direnv --json | jq -r '.[0].outputs.out')/bin:$PATH
220+
echo "Got path: $PATH"
221+
222+
direnv allow
223+
direnv exec . stack build --nix --no-nix-pure
224+
225+
- name: Run tests (aarch64-linux)
226+
if: "!contains(github.event.head_commit.message, 'noci')"
227+
run: |
228+
cd tests
229+
230+
export TEST_ROOT=$(pwd)/test_root_aarch64
231+
echo "Got TEST_ROOT: $TEST_ROOT"
232+
echo TEST_ROOT="$TEST_ROOT" >> $GITHUB_ENV
233+
234+
export NIX_PATH=nixpkgs=$(nix run .#nixpkgsPath)
235+
export PATH=$(nix build --no-link .#stack --json | jq -r '.[0].outputs.out')/bin:$PATH
236+
237+
stack run --nix --no-nix-pure -- \
238+
--target-system aarch64-linux \
239+
--print \
240+
--fixed-root "$TEST_ROOT" \
241+
--markdown-summary "$GITHUB_STEP_SUMMARY" \
242+
--bash
243+
244+
- name: Upload test artifacts
245+
if: always()
246+
continue-on-error: true
247+
shell: bash
248+
run: |
249+
DEST="tester@desktop1:/home/tester/all_test_runs/languages_${{github.workflow}}_${{github.run_number}}/bash-aarch64-linux"
250+
echo "DEST: $DEST"
251+
if [[ -n "$TEST_ROOT" ]]; then
252+
rsync \
253+
-e "ssh -F /secrets/ci_ssh_config" \
254+
-azW --mkpath \
255+
"$TEST_ROOT/" \
256+
"$DEST"
257+
fi

tests/app/Spec/Tests.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tests :: forall context. (
2525
, Typeable context
2626
) => SpecFree context IO ()
2727
tests =
28+
introduceTargetSystem $
2829
introduceJupyterRunner $
2930
introduceJustBubblewrap $
3031
introduceBootstrapNixpkgs $

tests/app/Spec/Tests/Haskell/Diagnostics.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ etaExpandCode = [__i|module Foo where
8787
|]
8888

8989
main :: IO ()
90-
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions $
90+
main = runSandwichWithCommandLineArgs' Sandwich.defaultOptions specialOptions $
91+
introduceTargetSystem $
9192
introduceNixEnvironment [kernelSpec ghcPackage] [] "Haskell" $
9293
introduceJustBubblewrap $
9394
tests ghcPackage HaskellCommon.lsName

tests/app/Spec/Tests/Searchers.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tests = describe "Searchers" $ do
1313
it "searcher has some results" $ testSearcherHasNonemptyResults "packageSearch"
1414

1515
main :: IO ()
16-
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions $
16+
main = runSandwichWithCommandLineArgs' Sandwich.defaultOptions specialOptions $
17+
introduceTargetSystem $
1718
introduceBootstrapNixpkgs $
1819
tests

tests/app/Spec/Tests/SettingsSchemas.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ itemsLackingField byPackage field = catMaybes [
4747
_ -> Just ([i|#{packageName}.#{targetName}|] :: Text)
4848

4949
main :: IO ()
50-
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions $
50+
main = runSandwichWithCommandLineArgs' Sandwich.defaultOptions specialOptions $
51+
introduceTargetSystem $
5152
introduceBootstrapNixpkgs $
5253
tests

tests/app/Spec/Tests/Shells/Zsh.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Spec.Tests.Shells.Zsh (tests) where
55
import Data.String.Interpolate
66
import Data.Text
77
import Test.Sandwich as Sandwich
8+
import TestLib.JupyterRunnerContext (introduceTargetSystem)
89
import TestLib.NixEnvironmentContext
910
import TestLib.Types
1011

@@ -14,7 +15,7 @@ otherConfig = [
1415
"shells.zsh.enable = true;"
1516
]
1617

17-
tests :: TopSpec
18+
tests :: NixEnvSpec
1819
tests = describe "ZSH" $ introduceNixEnvironment [] otherConfig "ZSH environment" $ do
1920
it "can run a command" $ do
2021
nixEnv <- getContext nixEnvironment
@@ -23,4 +24,5 @@ tests = describe "ZSH" $ introduceNixEnvironment [] otherConfig "ZSH environment
2324
pending
2425

2526
main :: IO ()
26-
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
27+
main = runSandwichWithCommandLineArgs' Sandwich.defaultOptions specialOptions $
28+
introduceTargetSystem tests

tests/app/Spec/Tests/Spellchecker.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Test.Sandwich.Waits (waitUntil)
1919
import TestLib.JupyterRunnerContext
2020
import TestLib.LSP
2121
import TestLib.NixEnvironmentContext
22+
import TestLib.Types
2223
import UnliftIO.Directory
2324

2425

@@ -27,7 +28,7 @@ otherConfig = [
2728
"language-servers.spellchecker.enable = true;"
2829
]
2930

30-
tests :: TopSpec
31+
tests :: NixEnvSpec
3132
tests = describe "Spellchecker" $ introduceNixEnvironment [] otherConfig "Spellchecker env" $ introduceJustBubblewrap $ do
3233
it "Gets diagnostics and a working code action" $ do
3334
doSession'' "test.md" "spellchecker" [i|\# This is mispelled|] [] $ \(Helpers.LspSessionInfo {..}) -> do
@@ -66,4 +67,5 @@ getTitle (InL x) = x ^. title
6667
getTitle (InR x) = x ^. title
6768

6869
main :: IO ()
69-
main = runSandwichWithCommandLineArgs Sandwich.defaultOptions tests
70+
main = runSandwichWithCommandLineArgs' Sandwich.defaultOptions specialOptions $
71+
introduceTargetSystem tests

tests/src/TestLib/JupyterRunnerContext.hs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ import UnliftIO.Directory
3131
import UnliftIO.Process
3232

3333

34+
introduceTargetSystem :: (
35+
HasBaseContext context, HasCommandLineOptions context SpecialOptions, MonadIO m, MonadMask m, MonadUnliftIO m, MonadBaseControl IO m
36+
) => SpecFree (LabelValue "targetSystem" (Maybe String) :> context) m () -> SpecFree context m ()
37+
introduceTargetSystem = introduceWith [i|Target system|] targetSystem $ \action -> do
38+
opts <- getCommandLineOptions
39+
let ts = optTargetSystem (optUserOptions opts)
40+
void $ action ts
41+
3442
introduceJupyterRunner :: (
3543
HasBaseContext context, MonadIO m, MonadMask m, MonadUnliftIO m, MonadBaseControl IO m
3644
) => SpecFree (LabelValue "jupyterRunner" FilePath :> context) m () -> SpecFree context m ()
@@ -53,6 +61,26 @@ introduceBootstrapNixpkgs = introduceWith [i|Jupyter runner|] bootstrapNixpkgs $
5361
out <- readCreateProcessWithLogging ((proc "nix" ["run", ".#nixpkgsPath"]) { cwd = Just (rootDir </> "tests") }) ""
5462
void $ action (T.unpack $ T.strip $ T.pack out)
5563

64+
-- | Use bubblewrap unless we're cross-compiling (target system differs from host)
65+
introduceBubblewrap :: (
66+
HasBaseContext context, HasTargetSystem context, MonadIO m, MonadMask m, MonadUnliftIO m, MonadBaseControl IO m
67+
) => SpecFree (LabelValue "maybeBubblewrap" (Maybe FilePath) :> context) m () -> SpecFree context m ()
68+
introduceBubblewrap = introduceWith [i|bwrap|] maybeBubblewrap $ \action -> do
69+
maybeTargetSys <- getContext targetSystem
70+
case maybeTargetSys of
71+
Just _ -> do
72+
-- Skip bubblewrap for cross-architecture tests to avoid closure issues
73+
info [i|Skipping bubblewrap due to cross-architecture target system|]
74+
void $ action Nothing
75+
Nothing -> do
76+
#ifdef darwin_HOST_OS
77+
void $ action Nothing
78+
#else
79+
liftIO (findExecutable "bwrap") >>= \case
80+
Nothing -> expectationFailure [i|The tests currently require bubblewrap to be present.|]
81+
Just path -> void $ action (Just path)
82+
#endif
83+
5684
-- | TODO: pipe through a command-line argument to control whether bwrap is used?
5785
introduceJustBubblewrap :: (
5886
HasBaseContext context, MonadIO m, MonadMask m, MonadUnliftIO m, MonadBaseControl IO m
@@ -352,7 +380,8 @@ notebookWithCode kernel code = A.object [
352380

353381
jupyterMain :: LanguageSpec -> IO ()
354382
jupyterMain tests = runSandwichWithCommandLineArgs' Sandwich.defaultOptions specialOptions $
383+
introduceTargetSystem $
355384
introduceJupyterRunner $
356-
introduceJustBubblewrap $
385+
introduceBubblewrap $
357386
introduceBootstrapNixpkgs
358387
tests

tests/src/TestLib/NixEnvironmentContext.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ import UnliftIO.Temporary
2828

2929

3030
introduceNixEnvironment :: (
31-
HasBaseContext context, MonadIO m, MonadMask m, MonadUnliftIO m, MonadBaseControl IO m
31+
HasBaseContext context, HasTargetSystem context, MonadIO m, MonadMask m, MonadUnliftIO m, MonadBaseControl IO m
3232
)
3333
=> [NixKernelSpec]
3434
-> [Text]
3535
-> Text
3636
-> SpecFree (LabelValue "nixEnvironment" FilePath :> context) m ()
3737
-> SpecFree context m ()
3838
introduceNixEnvironment kernels otherConfig label = introduceWith' (defaultNodeOptions {nodeOptionsVisibilityThreshold = 60}) [i|#{label}|] nixEnvironment $ \action -> do
39+
maybeTargetSys <- getContext targetSystem
3940
rootDir <- findFirstParentMatching (\x -> doesPathExist (x </> ".git"))
4041

4142
metadata :: A.Object <- bracket (openFile "/dev/null" WriteMode) hClose $ \devNullHandle -> do
@@ -74,6 +75,7 @@ introduceNixEnvironment kernels otherConfig label = introduceWith' (defaultNodeO
7475
x -> expectationFailure [i|Unhandled src spec type: #{x}|]
7576

7677
built <- withTempDirectory dir "test-nix-build" $ \((</> "link") -> linkPath) -> do
78+
let systemArgs = maybe [] (\sys -> ["--system", sys]) maybeTargetSys
7779
let args = ["build"
7880
, "--quiet"
7981
, "--no-link"
@@ -84,6 +86,7 @@ introduceNixEnvironment kernels otherConfig label = introduceWith' (defaultNodeO
8486
, "--expr", T.unpack rendered
8587
, "-o", linkPath
8688
]
89+
++ systemArgs
8790
info [i|nix #{L.unwords args}|]
8891
createProcessWithLogging (proc "nix" args)
8992
>>= waitForProcess >>= (`shouldBe` ExitSuccess)

tests/src/TestLib/Types.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ import TestLib.NixTypes
1818

1919
data SpecialOptions = SpecialOptions {
2020
optTestParallelism :: Int
21+
, optTargetSystem :: Maybe String
2122
}
2223

2324
specialOptions :: Parser SpecialOptions
2425
specialOptions = SpecialOptions
2526
<$> option auto (long "test-parallelism" <> short 'n' <> showDefault <> help "Test parallelism" <> value 4 <> metavar "INT")
27+
<*> optional (strOption (long "target-system" <> help "Target system for nix builds (e.g., aarch64-linux)" <> metavar "SYSTEM"))
2628

2729
-- * Nix
2830

@@ -53,6 +55,10 @@ lockedToNixSrcSpec name (LockedGithub {..}) = NixSrcFetchFromGithub {
5355

5456
-- * Labels
5557

58+
targetSystem :: Label "targetSystem" (Maybe String)
59+
targetSystem = Label
60+
type HasTargetSystem context = HasLabel context "targetSystem" (Maybe String)
61+
5662
nixEnvironment :: Label "nixEnvironment" FilePath
5763
nixEnvironment = Label
5864
type HasNixEnvironment context = HasLabel context "nixEnvironment" FilePath
@@ -76,8 +82,12 @@ type SomeLanguageSpec context = (
7682
, HasJupyterRunner context
7783
, HasMaybeBubblewrap context
7884
, HasBootstrapNixpkgs context
85+
, HasTargetSystem context
7986
)
8087

8188
type LanguageSpec = forall context. SomeLanguageSpec context => SpecFree context IO ()
8289

83-
type SimpleSpec = forall context. (HasBaseContext context, HasBootstrapNixpkgs context) => SpecFree context IO ()
90+
type SimpleSpec = forall context. (HasBaseContext context, HasBootstrapNixpkgs context, HasTargetSystem context) => SpecFree context IO ()
91+
92+
-- | Spec type for tests that only need nix environment building capability
93+
type NixEnvSpec = forall context. (HasBaseContext context, HasTargetSystem context) => SpecFree context IO ()

0 commit comments

Comments
 (0)