diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 8588d0d..f0d062e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -30,9 +30,54 @@ jobs: outputs: matrix: ${{ steps.setup-matrix.outputs.matrix }} + samples: + # The type of runner that the job will run on + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + sample: + - samples/app + - samples/library + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE for the job. + - uses: actions/checkout@v2 + + - name: Setup Rust + run: | + rustup toolchain install stable + rustup target add x86_64-linux-android + rustup target add x86_64-unknown-linux-gnu + rustup target add aarch64-linux-android + + - name: Setup Java 11 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 11 + cache: 'gradle' + + - name: ${{ matrix.sample }} + run: | + ./gradlew -p ${{ matrix.sample }} :assembleDebug --info --warning-mode all + android_unversioned_tests: # The type of runner that the job will run on - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest steps: # Checks-out your repository under $GITHUB_WORKSPACE for the job. @@ -65,11 +110,15 @@ jobs: needs: [generate_versions] # , sanity_check] # The type of runner that the job will run on - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest androidTestTask: ${{ fromJson(needs.generate_versions.outputs.matrix) }} # Steps represent a sequence of tasks that will be executed as part of the job @@ -77,15 +126,6 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - # # Sets up the NDK required by AGP 3.6.x - # - name: Setup NDK - # run: sudo $ANDROID_HOME/tools/bin/sdkmanager 'ndk;20.0.5594570' - - # - name: Install Rustup - # run: | - # curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none - # echo "$HOME/.cargo/bin" >> $GITHUB_PATH - - name: Setup Rust run: | rustup toolchain install stable diff --git a/README.md b/README.md index ed6779d..085556a 100644 --- a/README.md +++ b/README.md @@ -496,7 +496,28 @@ $ ls -al build/local-repo/org/mozilla/rust-android-gradle/org.mozilla.rust-andro build/local-repo/org/mozilla/rust-android-gradle/org.mozilla.rust-android-gradle.gradle.plugin/0.4.0/org.mozilla.rust-android-gradle.gradle.plugin-0.4.0.pom ``` -# Testing Local changes +## Sample projects + +The easiest way to get started is to run the sample projects. The sample projects have dependency +substitutions configured so that changes made to `plugin/` are reflected in the sample projects +immediately. + +``` +$ ./gradlew -p samples/library :assembleDebug +... +$ file samples/library/build/outputs/aar/library-debug.aar +samples/library/build/outputs/aar/library-debug.aar: Zip archive data, at least v1.0 to extract +``` + +``` +$ ./gradlew -p samples/app :assembleDebug +... +$ file samples/app/build/outputs/apk/debug/app-debug.apk +samples/app/build/outputs/apk/debug/app-debug.apk: Zip archive data, at least v?[0] to extract +``` + +## Testing Local changes + An easy way to locally test changes made in this plugin is to simply add this to your project's `settings.gradle`: ```gradle @@ -545,17 +566,6 @@ Publishing artifact build/publish-generated-resources/pom.xml Activating plugin org.mozilla.rust-android-gradle.rust-android version 0.8.1 ``` -## Sample projects - -To run the sample projects: - -``` -$ ./gradlew -p samples/library :assembleDebug -... -$ ls -al samples/library/build/outputs/aar/library-debug.aar --rw-r--r-- 1 nalexander staff 8926315 18 Sep 10:22 samples/library/build/outputs/aar/library-debug.aar -``` - ## Real projects To test in a real project, use the local Maven repository in your `build.gradle`, like: diff --git a/plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy b/plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy index 2c8791e..0a470d8 100644 --- a/plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy +++ b/plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy @@ -27,6 +27,14 @@ class NdkVersionTest extends AbstractTest { .build() .writeProject() + // To ease debugging. + temporaryFolder.root.eachFileRecurse { + System.err.println("before> ${it}") + if (it.path.endsWith(".gradle")) { + System.err.println(it.text) + } + } + when: BuildResult buildResult = withGradleVersion(TestVersions.latestSupportedGradleVersionFor(androidVersion).version) .withProjectDir(temporaryFolder.root) @@ -36,7 +44,7 @@ class NdkVersionTest extends AbstractTest { // To ease debugging. temporaryFolder.root.eachFileRecurse { - println(it) + System.err.println("after> ${it}") } then: diff --git a/plugin/src/test/groovy/com/nishtahir/SimpleCargoProject.groovy b/plugin/src/test/groovy/com/nishtahir/SimpleCargoProject.groovy index a66f8f8..14475d1 100644 --- a/plugin/src/test/groovy/com/nishtahir/SimpleCargoProject.groovy +++ b/plugin/src/test/groovy/com/nishtahir/SimpleCargoProject.groovy @@ -41,15 +41,22 @@ class SimpleCargoProject { } def writeProject() { - def cargoModule = this.class.classLoader.getResource("rust/Cargo.toml").path - cargoModule = new File(cargoModule).parent + def cargoModuleFile = new File(this.class.classLoader.getResource("rust/Cargo.toml").path).parentFile + def targetDirectoryFile = new File(cargoModuleFile.parentFile, "target") + + // On Windows, path components are backslash-separated. We need to + // express the path as Groovy source, which means backslashes need to be + // escaped. The easiest way is to replace backslashes with forward + // slashes. + def module = cargoModuleFile.path.replace("\\", "/") + def targetDirectory = targetDirectoryFile.path.replace("\\", "/") def targetStrings = targets.collect({"\"${it}\"" }).join(", ") file('app/build.gradle') << """ cargo { - module = "${cargoModule}" - targetDirectory = "${cargoModule}/../target" + module = "${module}" + targetDirectory = "${targetDirectory}" targets = [${targetStrings}] libname = "rust" } @@ -57,8 +64,8 @@ class SimpleCargoProject { file('library/build.gradle') << """ cargo { - module = "${cargoModule}" - targetDirectory = "${cargoModule}/../target" + module = "${module}" + targetDirectory = "${targetDirectory}" targets = [${targetStrings}] libname = "rust" } diff --git a/samples/app/build.gradle b/samples/app/build.gradle index 3fba945..8c30046 100644 --- a/samples/app/build.gradle +++ b/samples/app/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.agp_version = '4.1.0' + ext.agp_version = '7.0.0' repositories { google() maven { @@ -17,6 +17,8 @@ apply plugin: 'org.mozilla.rust-android-gradle.rust-android' android { compileSdkVersion 27 + ndkVersion "23.1.7779620" + defaultConfig { applicationId "com.nishtahir.androidrust" minSdkVersion 21 @@ -31,17 +33,17 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - ndkVersion "20.1.5948944" } cargo { module = "../rust" - targets = ["arm", "x86", "x86_64", "arm64"] + targets = ["x86_64", "arm64"] libname = "rust" } repositories { google() + mavenCentral() } dependencies { diff --git a/samples/library/build.gradle b/samples/library/build.gradle index c77218f..41c42b7 100644 --- a/samples/library/build.gradle +++ b/samples/library/build.gradle @@ -1,4 +1,5 @@ buildscript { + ext.agp_version = '7.0.0' repositories { google() maven { @@ -16,6 +17,7 @@ apply plugin: 'org.mozilla.rust-android-gradle.rust-android' android { compileSdkVersion 27 + ndkVersion "23.1.7779620" defaultConfig { minSdkVersion 21 @@ -24,7 +26,6 @@ android { versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { release { @@ -36,7 +37,7 @@ android { cargo { module = "../rust" - targets = ["arm", "x86", "x86_64", "arm64"] + targets = ["x86_64", "arm64"] libname = "rust" features { @@ -52,6 +53,7 @@ cargo { repositories { google() + mavenCentral() } dependencies {