From f7a58827f2e9fc916e223d0a5d06f5113dda39e1 Mon Sep 17 00:00:00 2001 From: Joe Hendrix Date: Sun, 22 Oct 2023 19:54:34 -0700 Subject: [PATCH] Enable build --- .github/workflows/build.yaml | 38 ++++++++++++++++++++++++++++++++++++ Libuv.lean => LibUV.lean | 0 {Libuv => LibUV}/Basic.lean | 0 lakefile.lean | 30 ++++++++++++++++++++-------- 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/build.yaml rename Libuv.lean => LibUV.lean (100%) rename {Libuv => LibUV}/Basic.lean (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..2733c89 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,38 @@ +on: [push, pull_request] + +name: ci + +jobs: + build: + name: Build + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ubuntu-latest + steps: + - name: install elan + run: | + set -o pipefail + curl -sSfL https://github.com/leanprover/elan/releases/download/v1.4.2/elan-x86_64-unknown-linux-gnu.tar.gz | tar xz + ./elan-init -y --default-toolchain none + echo "$HOME/.elan/bin" >> $GITHUB_PATH + - uses: actions/checkout@v4 + - name: Install libuv (ubuntu) + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends libuv1-dev clang + sudo update-alternatives --set cc /usr/bin/clang + if: matrix.os == 'ubuntu-latest' + - name: Set up Homebrew + uses: Homebrew/actions/setup-homebrew@master + if: matrix.os == 'macos-latest' + - name: Install libuv (osx) + run: brew install libuv pkg-config + if: matrix.os == 'macos-latest' + - name: Lake build + run: | + which cc + ls -l $(which cc) + + lake build --verbose \ No newline at end of file diff --git a/Libuv.lean b/LibUV.lean similarity index 100% rename from Libuv.lean rename to LibUV.lean diff --git a/Libuv/Basic.lean b/LibUV/Basic.lean similarity index 100% rename from Libuv/Basic.lean rename to LibUV/Basic.lean diff --git a/lakefile.lean b/lakefile.lean index 6b56a58..a82de75 100644 --- a/lakefile.lean +++ b/lakefile.lean @@ -8,14 +8,28 @@ package LibUV where module_data alloy.c.o : BuildJob FilePath +def flushError (msg : String) : IO Unit := do + let stderr ← IO.getStdout + stderr.putStr msg + stderr.flush + + +def fatalError (msg : String) (u : UInt8) : IO α := do + flushError msg + IO.Process.exit u + def runPkgConfig (args : Array String) : IO (Array String) := do - let out ← IO.Process.output { cmd := "pkg-config", args } - if out.exitCode ≠ 0 then - let stderr ← IO.getStderr - stderr.putStr s!"Cannot run pkg-config" - stderr.flush - IO.Process.exit 1 - return out.stdout.splitOn.toArray.map String.trimRight + let mout ← (Option.some <$> (IO.Process.output { cmd := "pkg-config", args })).tryCatch (fun _ => pure none) + match mout with + | Option.none => + flushError "Cannot run pkg-config" + pure #[] + | Option.some out => + if out.exitCode = 0 then + return out.stdout.splitOn.toArray.map String.trimRight + else + flushError "pkg-config failed" + pure #[] def pkgConfigCFlags (lib : String) : IO (Array String) := runPkgConfig #["--cflags", lib] def pkgConfigLibs (lib : String) : IO (Array String) := runPkgConfig #["--libs", lib] @@ -24,5 +38,5 @@ def pkgConfigLibs (lib : String) : IO (Array String) := runPkgConfig #["--libs", lean_lib LibUV where precompileModules := true nativeFacets := #[Module.oFacet, `alloy.c.o] - moreLeancArgs := run_io (pkgConfigCFlags "libuv") + moreLeancArgs := #["-fPIC"] ++ run_io (pkgConfigCFlags "libuv") moreLinkArgs := run_io (pkgConfigLibs "libuv") \ No newline at end of file