Skip to content

Commit

Permalink
test: Add an example build script usage crate
Browse files Browse the repository at this point in the history
Add a example / test crate named `example-build-script`
to the project workspace.

Pull in and link a simple Rust binary to several Conan dependencies:

- openssl
- libxml2
- zlib

Test that the example Rust binary links and runs correctly.
  • Loading branch information
ravenexp committed Oct 13, 2023
1 parent 2964c88 commit 41be4b5
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
run: conan profile detect
- name: Run tests
run: cargo test --verbose
- name: Test build the example crates
run: cargo build --all
- name: Test run the build script example
run: cargo run -p example-build-script
fmt:
name: Check code formatting
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ runtests:
stage: test
script:
- cargo test --verbose
- cargo build --all
- cargo run -p example-build-script
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ readme = "README.md"

[dependencies]
serde_json = "1.0"

[workspace]
members = [ "example-build-script" ]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ fn main() {
The Conan executable is assumed to be named `conan` unless
the `CONAN` environment variable is set to override.

An example Rust crate using `conan2-rs` to link Conan dependencies
can also be found in the project repository.

## Advanced usage

Using custom Conan profiles with names derived from the Cargo target information:
Expand Down
8 changes: 8 additions & 0 deletions example-build-script/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "example-build-script"
description = "A working example of using Conan dependencies with conan2-rs"
version = "0.1.0"
edition = "2021"

[build-dependencies]
conan2 = { path = "../" }
5 changes: 5 additions & 0 deletions example-build-script/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use conan2::ConanInstall;

fn main() {
ConanInstall::new().build("missing").run().parse().emit();
}
4 changes: 4 additions & 0 deletions example-build-script/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[requires]
zlib/1.3
libxml2/2.11.4
openssl/3.1.3
43 changes: 43 additions & 0 deletions example-build-script/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::ffi::{c_int, c_uint, c_ulong, c_void};

extern "C" {
/// zlib
fn adler32(adler: c_ulong, buf: *const c_void, len: c_uint) -> c_ulong;

/// libxml2
fn xmlCheckVersion(version: c_int);

/// libiconv
fn iconv_open(tocode: *const u8, fromcode: *const u8) -> *const c_void;

/// libcharset
fn locale_charset() -> *const u8;

/// libcrypto
fn EVP_MD_CTX_new() -> *const c_void;

/// libssl
fn OPENSSL_init_ssl(opts: u64, buf: *const c_void) -> c_int;
}

fn main() {
unsafe {
// zlib
adler32(0, std::ptr::null(), 0);

// libxml2
xmlCheckVersion(2_00_00);

// libiconv
iconv_open(b"a".as_ptr(), b"b".as_ptr());

// libcharset
locale_charset();

// libcrypto
EVP_MD_CTX_new();

// libssl
OPENSSL_init_ssl(0, std::ptr::null());
};
}

0 comments on commit 41be4b5

Please sign in to comment.