Skip to content

Commit

Permalink
Add Vendored Libdbus Support
Browse files Browse the repository at this point in the history
  • Loading branch information
landhb committed Dec 27, 2022
1 parent 7031b79 commit f40c4fb
Show file tree
Hide file tree
Showing 8 changed files with 494 additions and 2 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/dbus-rs-github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,68 @@ env:
CARGO_TERM_COLOR: always

jobs:
# Taken from rust-lang/libz-sys CI/CD example.
#
# This job downloads and stores `cross` as an artifact, so that it can be
# redownloaded across all of the jobs.
install-cross:
runs-on: ubuntu-latest
steps:
- uses: XAMPPRocky/get-github-release@v1
id: cross
with:
owner: rust-embedded
repo: cross
matches: ${{ matrix.platform }}
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v2
with:
name: cross-${{ matrix.platform }}
path: ${{ steps.cross.outputs.install_path }}
strategy:
matrix:
platform: [linux-musl]

# Cross compile vendored libdbus for multiple architectures.
#
# Cannot run the full dbus test suite since the cross docker image doesn't
# have dbus-daemon running.
libdbus-sys-linux:
runs-on: ubuntu-latest
needs: install-cross
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Download Cross
uses: actions/download-artifact@v1
with:
name: cross-linux-musl
path: /tmp
- run: rustup toolchain install ${{ matrix.channel }}
- run: chmod +x /tmp/cross
- name: Build
run: /tmp/cross build --package dbus --features vendored --target ${{ matrix.target }}
- name: Run tests
run: /tmp/cross test --package libdbus-sys --features vendored --target ${{ matrix.target }}
strategy:
fail-fast: false
matrix:
channel: [stable]
target:
- mips64-unknown-linux-muslabi64
- mips-unknown-linux-musl
- aarch64-unknown-linux-musl
- arm-unknown-linux-musleabihf
- i686-unknown-linux-musl
- x86_64-unknown-linux-musl
- x86_64-unknown-linux-gnu

build:

runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libdbus-sys/vendor/dbus"]
path = libdbus-sys/vendor/dbus
url = https://github.com/freedesktop/dbus.git
1 change: 1 addition & 0 deletions dbus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tempfile = "3"

[features]
no-string-validation = []
vendored = ["libdbus-sys/vendored"]
futures = ["futures-util", "futures-channel"]
# Not ready yet
# native-channel = ["futures-executor", "futures-util/io", "dbus-native-channel"]
Expand Down
9 changes: 8 additions & 1 deletion libdbus-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ categories = ["os::unix-apis", "external-ffi-bindings"]
build = "build.rs"
links = "dbus"

[features]
# By default use pkg-config to locate the local libdbus installation
default = ["pkg-config"]
# Provide vendoring as an option, which will compile libdbus from source for the target
vendored = ["cc"]

[build-dependencies]
pkg-config = "0.3"
pkg-config = {version = "0.3", optional = true}
cc = {version = "1.0.78", optional = true }

[package.metadata.pkg-config]
dbus-1 = "1.6"
Expand Down
15 changes: 14 additions & 1 deletion libdbus-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
extern crate pkg_config;
use std::error::Error;

#[cfg(feature = "vendored")]
mod build_vendored;

fn main() -> Result<(), Box<dyn Error>> {
// Invalidate the built crate whenever these files change
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=build_vendored.rs");

fn main() {
// See https://github.com/joshtriplett/metadeps/issues/9 for why we don't use
// metadeps here, but instead keep this manually in sync with Cargo.toml.
#[cfg(not(feature = "vendored"))]
if let Err(e) = pkg_config::Config::new().atleast_version("1.6").probe("dbus-1") {
eprintln!("pkg_config failed: {}", e);
eprintln!(
Expand All @@ -15,4 +24,8 @@ fn main() {
);
panic!();
}

#[cfg(feature = "vendored")]
build_vendored::build_libdbus()?;
Ok(())
}

0 comments on commit f40c4fb

Please sign in to comment.