Skip to content

Commit

Permalink
use stable rust
Browse files Browse the repository at this point in the history
use gradle to copy artifacts
  • Loading branch information
TarekkMA authored and david-allison committed May 7, 2021
1 parent c452024 commit 7db01e2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/robolectric_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ jobs:
- name: Install Rust
uses: actions-rs/[email protected]
with:
toolchain: nightly # nightly is currently required for Robolectric Testing
toolchain: stable
override: true
components: rustfmt, clippy

# actions-rs only accepts "target" (although a "targets" param to be added in v2). We need 7 targets.
- name: Install Rust Targets
Expand Down
46 changes: 40 additions & 6 deletions rsdroid-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ def getInputDir() {
return canonicalPath
}

def getAssetsDir() {
return "${project.sourceSets.main.java.srcDirs[0]}/../../../assets";
}

def getTargetDir() {
return getInputDir() + "/target"
}

def toWindowsCommandLine(String command) {
def path = "${project.sourceSets.main.java.srcDirs[0]}/../../../assets"
def path = getAssetsDir()
def canonicalAssetsPath = new File(path).getCanonicalPath()
if (!new File(canonicalAssetsPath).exists()) {
throw new FileNotFoundException("could not find output path: ${canonicalAssetsPath}")
Expand All @@ -80,7 +88,7 @@ def toCommandLine(Platform targetPlatform) {
useCross = false
}

def standardArg = "${useCross ? "cross" : "cargo"} +nightly build --release -Z unstable-options --features no-android"
def standardArg = "${useCross ? "cross" : "cargo"} build --release --features no-android --verbose"
def assetsPath = new File("${project.sourceSets.main.java.srcDirs[0]}/../../../assets").getCanonicalPath()

String assetsSubPath = "/rsdroid-testing/assets"
Expand All @@ -91,14 +99,11 @@ def toCommandLine(Platform targetPlatform) {
"/mnt/" + f.absolutePath[0].toLowerCase() + f.absolutePath.substring(1).replace(":\\", "\\").replace("\\", "/")

println "Outputting to: ${path}"
def outDir = "--out-dir ${path}"
def outDir = ""
System.out.println(assetsPath)
def mainArg = standardArg + " " + outDir
if (useCross) {
mainArg = "DONT_RUSTFMT=1 " + mainArg //FIXME: try to mount $CARGO_HOME/bin and add it to path using cross

//instruct cross to mount the output directory
mainArg = "OUT_DIR=${path} " + mainArg
}
switch (targetPlatform) {
case Platform.LINUX: return toWindowsCommandLine("CC=\$ANKIDROID_LINUX_CC ${mainArg} --target x86_64-unknown-linux-gnu")
Expand Down Expand Up @@ -147,10 +152,37 @@ task preBuildLinux(type: Exec) {
commandLine(toCommandLine(Platform.LINUX))
}

task copyLinuxOutput(type: Copy) {
dependsOn preBuildLinux
File linuxDir = new File(targetDir, "x86_64-unknown-linux-gnu/release/")
from linuxDir
include "*.so"
into assetsDir
}

task copyMacOutput(type: Copy) {
dependsOn preBuildMac
File macosDir = new File(targetDir, "x86_64-apple-darwin/release/")
from macosDir
include "*.dylib"
into assetsDir
}

task copyWindowsOutput(type: Copy) {
dependsOn preBuildWindows
File windowsDir = new File(targetDir, "x86_64-pc-windows-gnu/release/")
from windowsDir
include "*.dll"
include "*.dll.a"
into assetsDir
}


// TODO: check for cargo
// check for targets: x86_64-apple-darwin, x86_64-pc-windows-gnu, TODO: Linux

processResources.dependsOn preBuildWindows
processResources.dependsOn copyWindowsOutput
// To fix: "toolchain 'nightly-x86_64-unknown-linux-gnu' is not installed"
// execute in bash: rustup toolchain install nightly-x86_64-unknown-linux-gnu
// "linker `x86_64-unknown-linux-gnu-gcc` not found"
Expand All @@ -159,12 +191,14 @@ processResources.dependsOn preBuildWindows
// rustup target add x86_64-pc-windows-gnu --toolchain nightly
// brew install mingw-w64 && x86_64-w64-mingw32-gcc -v
processResources.dependsOn preBuildLinux
processResources.dependsOn copyLinuxOutput

if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
// due to restrictions on downloading the MacOS SDK, we can only build for MacOS on MacOS
// > Install a reasonable number of copies of the Apple Software on Apple-branded computers
// https://www.apple.com/legal/sla/docs/xcode.pdf
processResources.dependsOn preBuildMac
processResources.dependsOn copyMacOutput
}

signing {
Expand Down

0 comments on commit 7db01e2

Please sign in to comment.