diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 542fabf0..143d0227 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ env: JAVA_OPTS: "-Xmx4G" JVM_OPTS: "-Xmx4G" SBT_OPTS: "-Xmx4G" + LLVM_VERSION: 14 jobs: macos_build: @@ -18,7 +19,6 @@ jobs: fail-fast: true runs-on: macos-11 env: - SN_RELEASE: fast LLVM_VERSION: 14 LLVM_BIN: /usr/local/opt/llvm@14/bin steps: @@ -35,6 +35,15 @@ jobs: - name: Install LLVM run: brew install llvm@$LLVM_VERSION + - name: Sets env vars for release + run: | + echo "SN_RELEASE=fast" >> $GITHUB_ENV + if: startsWith(github.ref, 'refs/tags/v') || (github.ref == 'refs/heads/main') + + - name: Sets env vars for LLVM + run: | + echo "LLVM_BIN=/usr/local/opt/llvm@$LLVM_VERSION/bin" >> $GITHUB_ENV + - name: CI and build the binary run: sbt ci 'buildBinary sn-bindgen-x86_64-apple-darwin' @@ -44,31 +53,84 @@ jobs: path: bin/sn-bindgen-* name: binaries if-no-files-found: error + + macos_arm_build: + name: MacOS (Arm64) + strategy: + fail-fast: true + runs-on: macos-aarch64 + if: startsWith(github.ref, 'refs/tags/v') + continue-on-error: true + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + cache: 'sbt' + + - name: Install LLVM + run: brew install llvm@$LLVM_VERSION + + - name: Install SBT + run: brew install sbt + + - name: Sets env vars for release + run: | + echo "SN_RELEASE=fast" >> $GITHUB_ENV + + - name: Sets env vars for LLVM + run: | + echo "LLVM_BIN=/opt/homebrew/opt/llvm@$LLVM_VERSION/bin" >> $GITHUB_ENV + + - name: CI and build the binary + run: sbt ci 'buildBinary sn-bindgen-aarch64-apple-darwin' + + - name: Upload artifacts + uses: actions/upload-artifact@master + with: + path: bin/sn-bindgen-* + name: binaries + if-no-files-found: error linux_build: - name: Linux - runs-on: ubuntu-20.04 - env: - FORCE_COLOR: 1 - steps: - - uses: earthly/actions/setup-earthly@v1 - with: - version: v0.7.2 + name: Linux + runs-on: ubuntu-20.04 + steps: + - uses: earthly/actions/setup-earthly@v1 + with: + version: v0.7.2 - - uses: actions/checkout@v3 - with: - fetch-depth: 0 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Intel build - run: earthly --ci --platform linux/amd64 --output +bindgen --BINARY_NAME="sn-bindgen-x86_64-pc-linux" + - name: Setup Unix-like + run: ./build/setup_unix.sh - - name: Upload Intel artifacts - uses: actions/upload-artifact@master - with: - path: bin/sn-bindgen-* - name: binaries - if-no-files-found: error + - name: Sets env vars for release + run: | + echo "SN_RELEASE=fast" >> $GITHUB_ENV + + - name: Sets env vars for LLVM + run: | + echo "LLVM_BIN=/usr/lib/llvm-$LLVM_VERSION/bin" >> $GITHUB_ENV + - name: CI and build the binary + run: sbt ci 'buildBinary sn-bindgen-x86_64-pc-linux' + + - name: Build site + run: sbt buildWebsite + + - name: Upload Intel artifacts + uses: actions/upload-artifact@master + with: + path: bin/sn-bindgen-* + name: binaries + if-no-files-found: error linux_arm64_build: name: Linux (Arm64) @@ -108,7 +170,6 @@ jobs: fail-fast: false runs-on: windows-2019 env: - SN_RELEASE: fast LLVM_BIN: 'C:\Program Files\LLVM\bin' LLVM_VERSION: "14.0.6" steps: @@ -138,11 +199,17 @@ jobs: - run: clang -v shell: cmd - - name: Install clang + - name: Sets env vars for release + run: | + echo "SN_RELEASE=fast" >> $env:GITHUB_ENV + if: startsWith(github.ref, 'refs/tags/v') || (github.ref == 'refs/heads/main') + shell: pwsh + + - name: Install clang and SBT shell: pwsh run: | choco install llvm --version="$Env:LLVM_VERSION" --allow-downgrade - choco install sbt --version=1.8.0 + choco install sbt --version=1.9.7 clang --version - name: SBT remote cache @@ -169,7 +236,7 @@ jobs: if-no-files-found: error release: - needs: [linux_build, linux_arm64_build, windows_build, macos_build] + needs: [linux_build, linux_arm64_build, windows_build, macos_build, macos_arm_build] name: Release runs-on: ubuntu-20.04 env: @@ -204,6 +271,7 @@ jobs: ./cs resolve com.indoorvivants:bindgen-interface_3:$(cat version) ./cs resolve com.indoorvivants:bindgen-interface_2.12:$(cat version) ./cs fetch com.indoorvivants:bindgen_native0.4_3:$(cat version) --classifier osx-x86_64 --artifact-type jar + ./cs fetch com.indoorvivants:bindgen_native0.4_3:$(cat version) --classifier osx-aarch64 --artifact-type jar ./cs fetch com.indoorvivants:bindgen_native0.4_3:$(cat version) --classifier linux-x86_64 --artifact-type jar ./cs fetch com.indoorvivants:bindgen_native0.4_3:$(cat version) --classifier linux-aarch64 --artifact-type jar ./cs fetch com.indoorvivants:bindgen_native0.4_3:$(cat version) --classifier windows-x86_64 --artifact-type jar diff --git a/Earthfile b/Earthfile deleted file mode 100644 index 3812574d..00000000 --- a/Earthfile +++ /dev/null @@ -1,34 +0,0 @@ -VERSION 0.7 - - -dependencies-base: - FROM eclipse-temurin:17-focal - COPY build /scripts - RUN /scripts/setup-debian.sh 14 - WORKDIR /sources - - - # SBT dependencies - COPY build.sbt /sources - COPY project/*.sbt /sources/project/ - COPY project/*.scala /sources/project/ - COPY project/build.properties /sources/project/ - RUN sbt update - - SAVE IMAGE --push sn-bindgen-deps-base:14 - -bindgen: - FROM +dependencies-base - ARG BUILD_COMMAND="ci; buildBinary" - ARG BINARY_NAME="bindgen" - - ENV LLVM_BIN=/usr/lib/llvm-14/bin - ENV CC=/usr/lib/llvm-14/bin/clang - ENV CXX=/usr/lib/llvm-14/bin/clang++ - ENV SN_RELEASE "fast" - ENV CI "true" - - COPY . /sources - RUN sbt "${BUILD_COMMAND}" - - SAVE ARTIFACT bin/bindgen AS LOCAL bin/$BINARY_NAME diff --git a/modules/bindgen/src/main/scala/ClangDetector.scala b/modules/bindgen/src/main/scala/ClangDetector.scala index 4552e559..a54d286b 100644 --- a/modules/bindgen/src/main/scala/ClangDetector.scala +++ b/modules/bindgen/src/main/scala/ClangDetector.scala @@ -7,6 +7,7 @@ import com.indoorvivants.detective.Platform import Platform.OS.* import java.lang.ProcessBuilder.Redirect import scala.sys.process.ProcessLogger +import scala.util.Try case class ClangInfo( includePaths: List[String] @@ -49,7 +50,11 @@ object ClangDetector: end process def detect(path: Path, args: String*): Either[ProcessResult, ClangInfo] = - val tempFolder = Files.createTempDirectory("sn-bindgen-clang") + val tempFolder = LazyList + .fill(5)(Try(Files.createTempDirectory("sn-bindgen-clang"))) + .dropWhile(_.isFailure) + .head + .get val destination = tempFolder.resolve("output.o").toString val tempC = Files.createTempFile(tempFolder, "test", ".c").toString() diff --git a/project/plugins.sbt b/project/plugins.sbt index 974a13e7..0e7684f7 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -9,7 +9,7 @@ addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") addSbtPlugin( - "com.indoorvivants" % "subatomic-plugin" % "0.0.7+111-b6459692-SNAPSHOT" + "com.indoorvivants" % "subatomic-plugin" % "0.0.7+162-f9b59ad1-SNAPSHOT" ) addSbtPlugin(