Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux arm build #1465

Merged
merged 101 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
b3a3a2d
Temporary cancel build step while I figure out some stuff.
csasarak Aug 23, 2024
a979d35
Empty container?
csasarak Aug 23, 2024
29af443
Confirm JS actions are disallowed.
csasarak Aug 23, 2024
dd37d20
They are disallowed.
csasarak Aug 23, 2024
b93c27d
Run single step in container.
csasarak Aug 23, 2024
84073b0
Was it really running IN the container?
csasarak Aug 23, 2024
3a8b46a
Run script.
csasarak Aug 23, 2024
0ee1260
need to get the path right.
csasarak Aug 23, 2024
2031b4d
Basic cargo builds with a target and setup.
csasarak Aug 23, 2024
0bc6ab8
Setup cargo target.
csasarak Aug 23, 2024
13de166
Check if we're on Linux correctly.
csasarak Aug 23, 2024
5c215ee
Fix toolchain
csasarak Aug 23, 2024
314d32f
Is jemalloc the culprit?
csasarak Aug 23, 2024
bed8ec6
Do I need build-essential?
csasarak Aug 23, 2024
e0b7845
Forget target for now, try build.
csasarak Aug 23, 2024
ec86b31
cache key calculation
csasarak Aug 26, 2024
10dfcce
Syntax fix.
csasarak Aug 26, 2024
bd18c74
Correct cache key conditional
csasarak Aug 26, 2024
1007790
Use build.sh for everything.
csasarak Aug 26, 2024
56009d9
Fix conditional
csasarak Aug 26, 2024
2b9f43e
Make cache-key computable
csasarak Aug 26, 2024
2894565
set -x and address some shellcheck issues.
csasarak Aug 26, 2024
c25b034
Update vendor_download.sh to download arm assets.
csasarak Aug 26, 2024
1e23596
Guard script arguments. Remove some old commentary.
csasarak Aug 26, 2024
aadc302
My guards worked too well...
csasarak Aug 26, 2024
6776237
Run git config update just before build.
csasarak Aug 26, 2024
bd2497f
Change release verification to include arm
csasarak Aug 26, 2024
eae3ab5
Only unit-tests.
csasarak Aug 26, 2024
071d0a9
Spec fix for building with arm.
csasarak Aug 27, 2024
120b8bb
aarch target.
csasarak Aug 27, 2024
78daf08
hail mary rust build
csasarak Aug 27, 2024
461b6a2
One more target.
csasarak Aug 27, 2024
b27c925
Does installing musl-dev work?
csasarak Aug 27, 2024
b51f469
use sudo?
csasarak Aug 27, 2024
ec81b5b
Try moving rust build into script.
csasarak Aug 27, 2024
37e210f
More scripts.
csasarak Aug 27, 2024
c1b3c38
syntax error.
csasarak Aug 27, 2024
7c92287
Try with cc arg
csasarak Aug 27, 2024
85d4520
revert me
csasarak Aug 27, 2024
d47a2e4
Corrections.
csasarak Aug 27, 2024
3b51e67
env vars
csasarak Aug 27, 2024
3e0b474
Revert "Try with cc arg"
csasarak Aug 27, 2024
fb866a8
Try cross.
csasarak Aug 27, 2024
0c7d709
Revert "Try cross."
csasarak Aug 27, 2024
abfcc56
try using build-arm.sh
csasarak Aug 27, 2024
0c12e3e
Non-interactive rustup.
csasarak Aug 27, 2024
6994d46
Enable the environment.
csasarak Aug 27, 2024
aa00ccc
Switch to lib-snippets. Configure link flags for Cargo.
csasarak Aug 28, 2024
3e02887
path fix I hope
csasarak Aug 28, 2024
d0d7804
Propagate project files correctly.
csasarak Aug 28, 2024
c467213
conditionalize extra-source-files.
csasarak Aug 28, 2024
0b58c2e
Print some env info.
csasarak Aug 28, 2024
8dfaddf
Always save the cabal cache.
csasarak Aug 28, 2024
f36d346
Commentary.
csasarak Aug 28, 2024
ae58975
Fix cargo test. more debug output
csasarak Aug 28, 2024
e0ed1bc
temporarily disable cabal install check.
csasarak Aug 28, 2024
62f5f7f
Help embeddedbinaries be findable when cabal is not running in root dir.
csasarak Aug 28, 2024
a29b0c2
Temporarily disable diagnose.
csasarak Aug 28, 2024
c56b7ce
Bring back cabal install check.
csasarak Aug 28, 2024
883ade8
Revert "Bring back cabal install check."
csasarak Aug 29, 2024
674a81f
Cache key perms.
csasarak Aug 29, 2024
3688701
Permissions.
csasarak Aug 29, 2024
82460b1
Try cleaning up.
csasarak Aug 29, 2024
6ae0ab0
Print home where cabal stuff goes.
csasarak Aug 29, 2024
c012cff
echo paths
csasarak Aug 29, 2024
2379f28
store-dir
csasarak Aug 29, 2024
7ff8995
Revert "store-dir"
csasarak Aug 29, 2024
9d239b1
Logic for LinuxARM cabal store.
csasarak Aug 29, 2024
fb346e2
MOre cabal store junk
csasarak Aug 29, 2024
db0bec1
Dummy cache test.
csasarak Aug 29, 2024
8927901
Try adding an additional rust-cache directory.
csasarak Aug 29, 2024
1a680bf
Re-enable other matrix builds.
csasarak Aug 29, 2024
d410985
Restore integration tests.
csasarak Aug 29, 2024
19dbc00
Update create release.
csasarak Aug 29, 2024
1e34a3b
Try putting the cabal install check back.
csasarak Aug 29, 2024
3a643d9
Remove extra ls
csasarak Aug 29, 2024
b2a8277
Revert "Try putting the cabal install check back."
csasarak Aug 29, 2024
32ef99b
Bring back non linux arm cargo tests and diagnose checks.
csasarak Aug 29, 2024
973b3ab
Install nextest.
csasarak Aug 29, 2024
f434b27
Don't need extra tooling on linux arm
csasarak Aug 29, 2024
4f4fafb
Fix condition.
csasarak Aug 29, 2024
04f6020
Cabal install check condition.
csasarak Aug 29, 2024
05ff967
Cache OS.
csasarak Aug 29, 2024
12efeed
Sha256 sum everything.
csasarak Aug 30, 2024
8104d1b
A little cleanup.
csasarak Aug 30, 2024
1103ed1
Fix quoting.
csasarak Aug 30, 2024
18b4c39
Insert arm generated bundles.
csasarak Aug 30, 2024
0895ff2
Add support for linux/arm64 to install-latest.sh
csasarak Sep 3, 2024
15c30fc
Only shasum fossa binaries.
csasarak Sep 3, 2024
ce556e1
Fix arch_version check so it doesn't trigger on macos.
csasarak Sep 3, 2024
d4f71e5
Attempt to re-enable jemalloc on linux x86_64.
csasarak Sep 3, 2024
a2625fb
Remove dead code.
csasarak Sep 4, 2024
75149fa
Merge branch 'master' into linux-arm-build
csasarak Sep 4, 2024
7313c56
Revert conditional extra-source-files.
csasarak Sep 4, 2024
1ab6b8f
Final cleanup.
csasarak Sep 4, 2024
759e845
Update changelog.
csasarak Sep 4, 2024
70026e0
jemalloc linux arm?
csasarak Sep 6, 2024
91c57a6
Better integrate jemalloc on arm.
csasarak Sep 6, 2024
5faa34c
Fix duplicated tests.
csasarak Sep 6, 2024
39a4b24
Use /runner/. $HOME is not set correctly.
csasarak Sep 6, 2024
e21c239
Fix script oops.
csasarak Sep 7, 2024
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
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.aarch64-unknown-linux-musl]
rustflags = ["-C", "link-arg=-lgcc"]
192 changes: 104 additions & 88 deletions .github/workflows/build-all.yml

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions .github/workflows/scripts/build-arm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env sh

set -e
set -x

if [ $# -lt 2 ] ; then
echo "Usage: ./build-arm.sh <RUNNER OS> <PROJECT FILE>"
exit 1
fi

RUNNER_OS=$1
PROJECT_FILE=$2

# Install rust tooling
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
. "/home/runner/.cargo/env"

rustc -V
cargo -V

# Build Rust binaries
cargo build --release

cargo test --release

# Validate that diagnose runs
cargo run --release --bin diagnose -- walk --trace-spans none --trace-level info

# Now do Haskell things
./.github/workflows/scripts/build.sh "$RUNNER_OS" "$PROJECT_FILE"
36 changes: 36 additions & 0 deletions .github/workflows/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env sh

set -e
set -x

if [ $# -lt 2 ] ; then
echo "Usage: ./build.sh <RUNNER OS> <PROJECT FILE>"
exit 1
fi

RUNNER_OS=$1
PROJECT_FILE=$2

make build-test-data

# Does this need to run in the container?
# It normally runs outside.
git config --global --add safe.directory "$GITHUB_WORKSPACE"

# With dist-newstyle caches:
# Cabal mainly knows to recompile based on changes to files.
# Tagging in git doesn't reliably change a file in a fixed location that cabal/GHC can track to indicate that there's a new tag.
# For our release process, we merge to master, which builds (and may store a dist-newstyle cache), then push a release tag.
# During the tag build, cabal/GHC may not realize that they have to rebuild the Version.hs file because the tag is invisible to it.
# This line adds a comment to our version source file to prompt cabal/GHC to rebuild Version.hs.
echo "{- $GITHUB_RUN_ID -}" >> src/App/Version.hs
cabal update
cabal build --project-file="$PROJECT_FILE" all
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting rid of the second attempt at a build that we used to do, like this:

$RUN_CMD || $RUN_CMD

Just double-checking that this is not something we want to keep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. Honestly I don't think I've ever seen the issue in the comment before - I think it's a holdover from a while ago. We can always add it back in in the future if needed. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me. No need to leave it in if we don't need it, and it's easy to add back

cabal test --project-file="$PROJECT_FILE" unit-tests

# Todo: Bring this back.
# Test cabal-install.
# This check ensures that QuickImport can use spectrometer as a library.
# if [ "$RUNNER_OS" = 'Linux' ] ; then
# cabal install --overwrite-policy=always --project-file="$PROJECT_FILE" --ghc-options="-Wwarn"
# fi
34 changes: 34 additions & 0 deletions .github/workflows/scripts/compute_cache_key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env sh

set -e
set -x

if [ $# -lt 2 ] ; then
echo "Usage: ./compute_cache_key <RUNNER OS> <PROJECT FILE>"
exit 1
fi

RUNNER_OS=$1
PROJECT_FILE=$2

cabal --project-file="$PROJECT_FILE" update
cabal --project-file="$PROJECT_FILE" build --dry-run
jq '."install-plan"[]."id"' < dist-newstyle/cache/plan.json | sort > /tmp/cabal-cache-key
echo "Install plan:"
cat /tmp/cabal-cache-key

if [ "$RUNNER_OS" = "macOS" ]; then
PLAN_SUM=$(shasum -a256 /tmp/cabal-cache-key)
else
PLAN_SUM=$(sha256sum /tmp/cabal-cache-key)
fi

CABAL_CACHE_KEY="$(echo "$PLAN_SUM" | awk '{print $1}')"
export CABAL_CACHE_KEY
echo "Cabal cache key: $CABAL_CACHE_KEY"
echo "cabal-cache-key=$CABAL_CACHE_KEY" >> "$GITHUB_OUTPUT"

echo "Home dotfiles in container: $(ls -al ~/.*)"

# Cleanup. Restoring this cache seems to fail if the directory already exists.
rm -rf dist-newstyle
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ resolver = "2"
[profile.release]
lto = "fat"
strip = true

# There is additional configuration in .cargo/config.toml.
# It is used for building on aarch64-unknown-linux-musl.
# More context on the split here: https://github.com/rust-lang/cargo/issues/12738
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# FOSSA CLI Changelog

## 3.9.32

- Platform Support: Add a binary for ARM64 Linux environments. ([#1465](https://github.com/fossas/fossa-cli/pull/1465))

## 3.9.31

- Resolve an issue parsing toml configuration files. ([#1459](https://github.com/fossas/fossa-cli/pull/1459))
Expand Down
2 changes: 1 addition & 1 deletion extlib/millhone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tikv-jemallocator = { version = "0.5.4", optional = true }
clap = { version = "4.3.21", features = ["derive", "env", "cargo"] }
stable-eyre = "0.2.2"
srclib = { version = "*", git = "https://github.com/fossas/foundation-libs" }
snippets = { version = "0.1.3", git = "https://github.com/fossas/foundation-libs", features = ["lang-all"] }
snippets = { version = "0.1.3", tag = "v0.1.3", git = "https://github.com/fossas/lib-snippets", features = ["lang-all"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just something we missed updating previously? It doesn't seem related to this PR

Copy link
Contributor Author

@csasarak csasarak Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't related directly. When I was trying to get the rust deps to build I was having trouble and for one of the issues I had I tried updating this library because I thought I might have to make some changes to it. I just kept this bit since it didn't seem to be hurting anything. If you feel strongly about it I can delete.

traceconf = { git = "https://github.com/fossas/foundation-libs", version = "1.1.0" }
serde = { version = "1.0.183", features = ["derive"] }
thiserror = "1.0.46"
Expand Down
13 changes: 12 additions & 1 deletion install-latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ is_supported_platform() {
darwin/amd64) found=0 ;;
darwin/arm64) found=0 ;;
linux/amd64) found=0 ;;
linux/arm64) found=0 ;;
esac
return $found
}
Expand Down Expand Up @@ -119,7 +120,16 @@ adjust_arch() {
# adjust archive name based on ARCH
true
}

arch_version_check() {
# TODO: Make this version correct before merging.
if [ "${OS}/${ARCH}" = "linux/arm64" ] && version_less_than "${VERSION}" '3.9.32'
then
echo "There is no linux/arm64 binary for version $VERSION."
echo "Please select a version that is at least version 3.9.32"
exit 1
fi
true
}
cat /dev/null <<EOF
------------------------------------------------------------------------
https://github.com/client9/shlib - portable posix shell functions
Expand Down Expand Up @@ -482,6 +492,7 @@ adjust_os

adjust_arch

arch_version_check

NAME=$(get_binary_name)
TARBALL=${NAME}.${FORMAT}
Expand Down
14 changes: 10 additions & 4 deletions src/Data/FileEmbed/Extra.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module Data.FileEmbed.Extra (
embedFile',
embedFileIfExists,
) where
)
where

import Control.Exception (try)
import Control.Monad (when)
import Data.FileEmbed (embedFile)
import Data.FileEmbed (embedFile, makeRelativeToProject)
import Data.Foldable (traverse_)
import Data.Maybe (isJust)
import Language.Haskell.TH (reportWarning, runIO)
import Language.Haskell.TH.Syntax (Exp (LitE), Lit (..), Q)
import Path (parseRelFile)
import Path (parseAbsFile)
import Path.IO (doesFileExist)
import System.Directory (getCurrentDirectory, listDirectory)
import System.Environment (lookupEnv)
Expand All @@ -19,7 +20,12 @@ import System.FilePath (isRelative, splitPath, takeDirectory)
embedFileIfExists :: FilePath -> Q Exp
embedFileIfExists inputPath = do
skipEmbedEnvVar <- runIO $ lookupEnv "FOSSA_SKIP_EMBED_FILE_IN_HLS"
case (skipEmbedEnvVar, parseRelFile inputPath) of
-- During some commands (like cabal install) the working directory may not
-- be the same as the root of this project.
-- makeRelativeToProject takes a relative path and roots it in the highest directory
-- a .cabal file is found and returns an absolute path.
inputPath' <- makeRelativeToProject inputPath
case (skipEmbedEnvVar, parseAbsFile inputPath') of
(Just _, _) -> do
pure (LitE $ StringL "")
(_, Just path) -> do
Expand Down
10 changes: 6 additions & 4 deletions test/App/Fossa/PathDependencySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Control.Algebra (Has)
import Control.Effect.FossaApiClient (FossaApiClientF (..), PackageRevision (PackageRevision))
import Data.Flag (toFlag)
import Data.Set qualified as Set
import Data.String.Conversion (toText)
import Data.Text (Text)
import DepTypes (
DepEnvironment (EnvTesting),
Expand Down Expand Up @@ -41,10 +42,11 @@ absPathOfSpec = describe "absPathOfSpec" $ do
mkPathSpec cwd "../" isAbsDir
mkPathSpec cwd "./" isAbsDir

mkPathSpec cwd "../fossa-cli" isAbsDir
mkPathSpec cwd "../fossa-cli/" isAbsDir
mkPathSpec cwd "../fossa-cli/test" isAbsDir
mkPathSpec cwd "../fossa-cli/test/" isAbsDir
let currentPathRel = "../" <> (toText . toFilePath . dirname $ cwd)
mkPathSpec cwd currentPathRel isAbsDir
mkPathSpec cwd currentPathRel isAbsDir
csasarak marked this conversation as resolved.
Show resolved Hide resolved
mkPathSpec cwd (currentPathRel <> "/test") isAbsDir
mkPathSpec cwd (currentPathRel <> "/test") isAbsDir

mkPathSpec cwd "./test" isAbsDir
mkPathSpec cwd "./test/" isAbsDir
Expand Down
17 changes: 13 additions & 4 deletions vendor_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@ case "$(uname -s)" in
;;

Linux)
ASSET_POSTFIX="linux"
THEMIS_ASSET_POSTFIX="linux-amd64"
LERNIE_ASSET_POSTFIX="x86_64-linux"
;;
case "$(uname -m)" in
aarch64)
ASSET_POSTFIX="linux"
THEMIS_ASSET_POSTFIX="linux-arm64"
LERNIE_ASSET_POSTFIX="aarch64-linux"
;;

*)
ASSET_POSTFIX="linux"
THEMIS_ASSET_POSTFIX="linux-amd64"
LERNIE_ASSET_POSTFIX="x86_64-linux"
;;
esac
;;
*)
echo "Warn: Assuming $(uname -s) is Windows"
ASSET_POSTFIX="windows.exe"
Expand Down
Loading