Skip to content

Commit

Permalink
Merge pull request #817 from philipcraig/github-actions
Browse files Browse the repository at this point in the history
github actions build and test on major architectures
  • Loading branch information
adetaylor authored Feb 22, 2022
2 parents 954888f + d732627 commit a7c8b65
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 109 deletions.
146 changes: 146 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: CI

on:
push:
branches: [main]
pull_request:
schedule: [cron: "40 1 * * *"]

jobs:
test:
name: ${{matrix.name || format('Rust {0}', matrix.rust)}}-test
runs-on: ${{matrix.os || 'ubuntu'}}-latest
strategy:
fail-fast: false
matrix:
include:
- rust: nightly
- rust: beta
- rust: stable
- name: macOS
rust: nightly
os: macos
- name: Windows (gnu)
rust: nightly-x86_64-pc-windows-gnu
os: windows
- name: Windows (msvc)
rust: nightly-x86_64-pc-windows-msvc
os: windows
flags: /EHsc
env:
CARGO_TERM_COLOR: always
CXXFLAGS: ${{matrix.flags}}
RUSTFLAGS: --cfg deny_warnings -Dwarnings
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
components: rustfmt
# For operating systems that have it packaged, install creduce
- name: Install creduce (Linux)
if: matrix.os == ''
run: sudo apt-get install creduce
- name: Install creduce (MacOS)
if: matrix.os == 'macOS'
run: brew install creduce
- name: Set LIBCLANG_PATH (Windows)
# Windows github action doesn't set the path for clang, so set it
# See https://github.com/rust-lang/rust-bindgen/issues/1797
if: matrix.os == 'windows'
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
- name: Exclude failing targets and tests
# no creduce on Windows, so exclude tests needing creduce there
run: |
echo RUSTFLAGS=$RUSTFLAGS >> $GITHUB_ENV
echo ::set-output name=exclude::${{runner.os == 'Windows' && '--exclude autocxx-reduce --exclude autocxx-gen' || ''}}
env:
# non-linux failures https://github.com/google/autocxx/issues/819
# beta failing tests https://github.com/google/autocxx/issues/818
RUSTFLAGS: ${{matrix.name == 'Windows (msvc)' && '--cfg skip_windows_msvc_failing_tests' || ''}} ${{matrix.name == 'Windows (gnu)' && '--cfg skip_windows_gnu_failing_tests' || ''}} ${{matrix.rust == 'beta' && '--cfg skip_beta_failing_tests' || ''}}
id: testsuite
shell: bash
- run: cargo test --workspace ${{steps.testsuite.outputs.exclude}}

examples:
name: ${{matrix.name || format('Rust {0}', matrix.rust)}}-examples
runs-on: ${{matrix.os || 'ubuntu'}}-latest
strategy:
fail-fast: false
matrix:
include:
- rust: nightly
- rust: beta
- rust: stable
- name: macOS
rust: nightly
os: macos
- name: Windows (gnu)
rust: nightly-x86_64-pc-windows-gnu
os: windows
- name: Windows (msvc)
rust: nightly-x86_64-pc-windows-msvc
os: windows
flags: /EHsc
env:
CARGO_TERM_COLOR: always
CXXFLAGS: ${{matrix.flags}}
RUSTFLAGS: --cfg deny_warnings -Dwarnings
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
components: rustfmt
- name: Set LIBCLANG_PATH (Windows)
# Windows github action doesn't set the path for clang, so set it
# See https://github.com/rust-lang/rust-bindgen/issues/1797
if: matrix.os == 'windows'
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
- name: Build s2 example
working-directory: ./examples/s2
# s2 doesn't link on Windows
if: matrix.os != 'windows'
run: cargo build
- name: Build steam example
working-directory: ./examples/steam-mini
run: cargo build
- name: Build subclass example
working-directory: ./examples/subclass
run: cargo build
- name: Build pod example
working-directory: ./examples/pod
run: cargo build
- name: Build chromium render-frame-host example
working-directory: ./examples/chromium-fake-render-frame-host
# chromium-fake-render-frame-host doesn't link on Windows
if: matrix.os != 'windows'
run: cargo build
- name: Build non-trivial-type-on-stack example
working-directory: ./examples/non-trivial-type-on-stack
run: cargo build

clippy:
name: Clippy
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@clippy
- run: cargo clippy --workspace --tests -- -Dclippy::all

outdated:
name: Outdated
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v2
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --exit-code 1
20 changes: 0 additions & 20 deletions .github/workflows/clippy.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/examples.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/rust.yml

This file was deleted.

14 changes: 5 additions & 9 deletions engine/src/parse_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn parse_file_contents(source: syn::File, auto_allowlist: bool) -> Result<Parsed
.unwrap_or(false) =>
{
Segment::Autocxx(
crate::IncludeCppEngine::new_from_syn(mac.mac.clone())
crate::IncludeCppEngine::new_from_syn(mac.mac)
.map_err(ParseError::AutocxxCodegenError)?,
)
}
Expand Down Expand Up @@ -273,9 +273,7 @@ pub trait CppBuildable {
impl ParsedFile {
/// Get all the autocxxes in this parsed file.
pub fn get_rs_buildables(&self) -> impl Iterator<Item = &IncludeCppEngine> {
fn do_get_rs_buildables(
segments: &Vec<Segment>,
) -> impl Iterator<Item = &IncludeCppEngine> {
fn do_get_rs_buildables(segments: &[Segment]) -> impl Iterator<Item = &IncludeCppEngine> {
segments
.iter()
.flat_map(|s| -> Box<dyn Iterator<Item = &IncludeCppEngine>> {
Expand All @@ -292,9 +290,7 @@ impl ParsedFile {

/// Get all items which can result in C++ code
pub fn get_cpp_buildables(&self) -> impl Iterator<Item = &dyn CppBuildable> {
fn do_get_cpp_buildables(
segments: &Vec<Segment>,
) -> impl Iterator<Item = &dyn CppBuildable> {
fn do_get_cpp_buildables(segments: &[Segment]) -> impl Iterator<Item = &dyn CppBuildable> {
segments
.iter()
.flat_map(|s| -> Box<dyn Iterator<Item = &dyn CppBuildable>> {
Expand All @@ -316,7 +312,7 @@ impl ParsedFile {

fn get_autocxxes_mut(&mut self) -> impl Iterator<Item = &mut IncludeCppEngine> {
fn do_get_autocxxes_mut(
segments: &mut Vec<Segment>,
segments: &mut [Segment],
) -> impl Iterator<Item = &mut IncludeCppEngine> {
segments
.iter_mut()
Expand All @@ -333,7 +329,7 @@ impl ParsedFile {
}

pub fn include_dirs(&self) -> impl Iterator<Item = &PathBuf> {
fn do_get_include_dirs(segments: &Vec<Segment>) -> impl Iterator<Item = &PathBuf> {
fn do_get_include_dirs(segments: &[Segment]) -> impl Iterator<Item = &PathBuf> {
segments
.iter()
.flat_map(|s| -> Box<dyn Iterator<Item = &PathBuf>> {
Expand Down
3 changes: 2 additions & 1 deletion examples/chromium-fake-render-frame-host/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
fn main() {
let path = std::path::PathBuf::from("src");
let mut b = autocxx_build::Builder::new("src/main.rs", &[&path]).expect_build();
b.flag_if_supported("-std=c++17")
b.flag_if_supported("-std=c++17") // clang
.flag_if_supported("/std:c++17") // msvc
.file("src/fake-chromium-src.cc")
.compile("autocxx-fake-render-frame-host-example");
println!("cargo:rerun-if-changed=src/main.rs");
Expand Down
3 changes: 0 additions & 3 deletions gen/cmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(test)]
mod cmd_test;

use autocxx_engine::parse_file;
use clap::{crate_authors, crate_version, App, Arg, ArgGroup};
use proc_macro2::TokenStream;
Expand Down
5 changes: 3 additions & 2 deletions gen/cmd/src/cmd_test.rs → gen/cmd/tests/cmd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use tempdir::TempDir;

static MAIN_RS: &str = include_str!("../../../demo/src/main.rs");
static INPUT_H: &str = include_str!("../../../demo/src/input.h");
static BLANK: &str = "// Blank autocxx placeholder";

#[test]
fn test_help() -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -158,7 +159,7 @@ fn assert_contentful(outdir: &TempDir, fname: &str) {
panic!("File {} didn't exist", p.to_string_lossy());
}
assert!(
p.metadata().unwrap().len() > super::BLANK.len().try_into().unwrap(),
p.metadata().unwrap().len() > BLANK.len().try_into().unwrap(),
"File {} is empty",
fname
);
Expand All @@ -170,7 +171,7 @@ fn assert_not_contentful(outdir: &TempDir, fname: &str) {
panic!("File {} didn't exist", p.to_string_lossy());
}
assert!(
p.metadata().unwrap().len() <= super::BLANK.len().try_into().unwrap(),
p.metadata().unwrap().len() <= BLANK.len().try_into().unwrap(),
"File {} is not empty",
fname
);
Expand Down
6 changes: 6 additions & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "autocxx-integration-tests"
version = "0.1.0"
autotests = false
edition = "2021"

[dev-dependencies]
Expand All @@ -27,3 +28,8 @@ itertools = "0.10"
version = "1.0.39"
features = [ "full" ]
#features = [ "full", "extra-traits" ]

[[test]]
name = "integration_tests"
path = "tests/lib.rs"
harness = true
Loading

0 comments on commit a7c8b65

Please sign in to comment.