Skip to content

Commit e59e034

Browse files
authored
Merge pull request #56 from stepfunc/feature/ci-update
Update CI
2 parents a880643 + 7921f5d commit e59e034

File tree

8 files changed

+254
-192
lines changed

8 files changed

+254
-192
lines changed

.github/workflows/ci.yml

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
- master
66
pull_request:
77
jobs:
8+
# Run the unit tests on Windows and Linux
89
test:
910
strategy:
1011
fail-fast: false
@@ -43,6 +44,7 @@ jobs:
4344
uses: actions-rs/cargo@v1
4445
with:
4546
command: test
47+
# Check formatting and run clippy lints
4648
linting:
4749
strategy:
4850
fail-fast: false
@@ -71,13 +73,14 @@ jobs:
7173
with:
7274
command: clippy
7375
args: -- -D warnings
76+
# Build bindings on Windows x64 and Linux x64
7477
bindings:
7578
strategy:
7679
fail-fast: false
7780
matrix:
7881
os:
79-
- ubuntu-latest
80-
- windows-latest
82+
- ubuntu-latest # 64-bit Linux (kernel 2.6.32+, glibc 2.11+) (x86_64-unknown-linux-gnu)
83+
- windows-latest # 64-bit MSVC (Windows 7+) (x86_64-pc-windows-msvc)
8184
runs-on: ${{ matrix.os }}
8285
steps:
8386
- name: Checkout
@@ -122,18 +125,69 @@ jobs:
122125
with:
123126
command: run
124127
args: --release --bin foo-bindings -- --java
125-
- name: Upload compiled C bindings
128+
- name: Upload compiled C bindings (Windows)
129+
if: ${{ runner.os == 'Windows' }}
130+
uses: actions/upload-artifact@v2
131+
with:
132+
name: ffi-modules
133+
path: tests/bindings/c/generated/x86_64-pc-windows-msvc/lib
134+
- name: Upload compiled C bindings (Linux)
135+
if: ${{ runner.os == 'Linux' }}
126136
uses: actions/upload-artifact@v2
127137
with:
128138
name: ffi-modules
129-
path: tests/bindings/c/generated/lib
139+
path: tests/bindings/c/generated/x86_64-unknown-linux-gnu/lib
130140
- name: Upload compiled Java bindings
131141
uses: actions/upload-artifact@v2
132142
with:
133143
name: ffi-modules
134144
path: tests/bindings/java/foo/src/main/resources
145+
# Cross-compilation for ARM devices and produce C bindings
146+
cross:
147+
strategy:
148+
fail-fast: false
149+
matrix:
150+
target:
151+
- arm-unknown-linux-gnueabi # ARMv6 Linux (kernel 3.2, glibc 2.17)
152+
- arm-unknown-linux-gnueabihf # ARMv6 Linux, hardfloat (kernel 3.2, glibc 2.17)
153+
- armv7-unknown-linux-gnueabihf # ARMv7 Linux, hardfloat (kernel 3.2, glibc 2.17)
154+
- aarch64-unknown-linux-gnu # ARM64 Linux (kernel 4.2, glibc 2.17+)
155+
runs-on: ubuntu-latest
156+
steps:
157+
- name: Checkout
158+
uses: actions/checkout@v1
159+
- name: Install Rust
160+
uses: actions-rs/toolchain@v1
161+
with:
162+
profile: minimal
163+
toolchain: stable
164+
target: ${{ matrix.target }}
165+
override: true
166+
- name: Update dependencies
167+
uses: actions-rs/cargo@v1
168+
with:
169+
use-cross: true
170+
command: update
171+
- name: Build
172+
uses: actions-rs/cargo@v1
173+
with:
174+
use-cross: true
175+
command: build
176+
args: --release --target ${{ matrix.target }}
177+
- name: C bindings
178+
uses: actions-rs/cargo@v1
179+
with:
180+
use-cross: true
181+
command: run
182+
args: --release --target ${{ matrix.target }} --bin foo-bindings -- --c --no-tests
183+
- name: Upload compiled C bindings
184+
uses: actions/upload-artifact@v2
185+
with:
186+
name: ffi-modules
187+
path: tests/bindings/c/generated/${{ matrix.target }}/lib
188+
# Package all the generated bindings
135189
packaging:
136-
needs: bindings
190+
needs: [bindings, cross]
137191
runs-on: ubuntu-latest
138192
steps:
139193
- name: Checkout

ci-script/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ fn main() {
66
"cargo:rustc-env=TARGET_DIR={}",
77
get_target_directory().unwrap().to_string_lossy()
88
);
9+
println!(
10+
"cargo:rustc-env=TARGET_TRIPLE={}",
11+
get_target_triple().unwrap()
12+
);
913
println!("cargo:rustc-env=PROFILE={}", var("PROFILE").unwrap());
1014
}
1115

1216
fn get_target_directory() -> Option<PathBuf> {
1317
let path = PathBuf::from(var("OUT_DIR").ok()?);
1418
Some(path.parent()?.parent()?.parent()?.to_owned())
1519
}
20+
21+
fn get_target_triple() -> Option<String> {
22+
var("TARGET").ok()
23+
}

ci-script/src/lib.rs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,27 @@ fn run_builder<'a, B: BindingBuilder<'a>>(
8282
) -> B {
8383
let mut platforms = PlatformLocations::new();
8484
if let Some(package_src) = package_src {
85-
let platform_path = [package_src, Platform::Win64.to_string()]
86-
.iter()
87-
.collect::<PathBuf>();
88-
if platform_path.is_dir() {
89-
platforms.add(Platform::Win64, platform_path);
90-
}
91-
92-
let platform_path = [package_src, Platform::Linux.to_string()]
93-
.iter()
94-
.collect::<PathBuf>();
95-
if platform_path.is_dir() {
96-
platforms.add(Platform::Linux, platform_path);
97-
}
85+
let mut check_platform = |platform: Platform| {
86+
let platform_path = [package_src, platform.to_string()]
87+
.iter()
88+
.collect::<PathBuf>();
89+
if platform_path.is_dir() {
90+
platforms.add(platform, platform_path);
91+
}
92+
};
9893

99-
let platform_path = [package_src, Platform::LinuxMusl.to_string()]
100-
.iter()
101-
.collect::<PathBuf>();
102-
if platform_path.is_dir() {
103-
platforms.add(Platform::LinuxMusl, platform_path);
104-
}
94+
check_platform(Platform::WinX64Msvc);
95+
check_platform(Platform::LinuxX64Gnu);
96+
check_platform(Platform::LinuxX64Musl);
97+
check_platform(Platform::LinuxArm6Gnueabi);
98+
check_platform(Platform::LinuxArm6GnueabiHf);
99+
check_platform(Platform::LinuxArm7GnueabiHf);
100+
check_platform(Platform::LinuxArm8Gnu);
105101
} else {
106-
platforms.add(Platform::current(), ffi_path());
102+
platforms.add(
103+
Platform::from_target_triple(env!("TARGET_TRIPLE")).expect("Unsupported platform"),
104+
ffi_path(),
105+
);
107106
}
108107

109108
if platforms.is_empty() {
@@ -124,11 +123,9 @@ fn run_builder<'a, B: BindingBuilder<'a>>(
124123

125124
builder.generate(package);
126125

127-
if !package {
126+
if !package && run_tests {
128127
builder.build();
129-
if run_tests {
130-
builder.test();
131-
}
128+
builder.test();
132129
} else {
133130
builder.package();
134131
}
@@ -161,13 +158,10 @@ struct CBindingBuilder<'a> {
161158

162159
impl<'a> CBindingBuilder<'a> {
163160
fn build_doxygen(&self) {
164-
let mut platforms = PlatformLocations::new();
165-
platforms.add(Platform::current(), ffi_path());
166-
167161
let config = c_oo_bindgen::CBindgenConfig {
168162
output_dir: self.output_dir(),
169163
ffi_name: self.settings.ffi_name.to_owned(),
170-
platforms,
164+
platforms: self.platforms.clone(),
171165
};
172166

173167
c_oo_bindgen::generate_doxygen(&self.settings.library, &config)
@@ -206,9 +200,6 @@ impl<'a> BindingBuilder<'a> for CBindingBuilder<'a> {
206200
}
207201

208202
fn generate(&mut self, _is_packaging: bool) {
209-
let mut platforms = PlatformLocations::new();
210-
platforms.add(Platform::current(), ffi_path());
211-
212203
let config = c_oo_bindgen::CBindgenConfig {
213204
output_dir: self.output_dir(),
214205
ffi_name: self.settings.ffi_name.to_owned(),
@@ -255,7 +246,7 @@ impl<'a> BindingBuilder<'a> for CBindingBuilder<'a> {
255246
}
256247

257248
fn package(&mut self) {
258-
// Already done in build
249+
// Already done in generate
259250
}
260251
}
261252

0 commit comments

Comments
 (0)