0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-20 12:02:18 +02:00

ffi: Fold signal_ffi.h generation into the Rust build

We're going to need nightly Rust for other things anyway, so we may as
well drop the extra Makefile and just require Cargo.

Also, delete the pkg-config file now that we no longer need to access
libsignal_ffi from arbitrary locations.
This commit is contained in:
Jordan Rose 2020-10-16 11:13:51 -07:00
parent 0c996fe221
commit 2fb87a0ab4
4 changed files with 29 additions and 38 deletions

View File

@ -14,3 +14,6 @@ rand = "0.7.3"
libc = "0.2"
num-traits = "0.2"
num-derive = "0.3"
[build-dependencies]
cbindgen = "0.14"

View File

@ -1,35 +0,0 @@
CONFIG ?= debug
TARGET_DIR := target/$(CARGO_BUILD_TARGET)/$(CONFIG)
ifeq ($(CONFIG),debug)
CARGO_CONFIG_FLAG :=
else ifeq ($(CONFIG),release)
CARGO_CONFIG_FLAG := --release
else
$(error CONFIG can be "debug" or "release" (defaults to "debug"))
endif
default: rust cbindgen pkg-config
clean:
cargo clean
rust: src/*.rs Cargo.toml
cargo build $(CARGO_CONFIG_FLAG)
cbindgen: $(TARGET_DIR)/signal_ffi.h
target/%/signal_ffi.h: signal_ffi.h
cp $^ $@
signal_ffi.h: src/*.rs Cargo.toml cbindgen.toml
unset CARGO_BUILD_TARGET && rustup run nightly cbindgen -o $@
pkg-config: $(TARGET_DIR)/signal_ffi.pc
target/%/signal_ffi.pc: signal_ffi.pc
cp $^ $@
.PHONY: default clean rust cbindgen pkg-config

26
rust/bridge/ffi/build.rs Normal file
View File

@ -0,0 +1,26 @@
//
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-3.0-only
//
extern crate cbindgen;
use std::env;
use std::path::Path;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
// Walk up from OUT_DIR to find where to put signal_ffi.h.
// Cargo doesn't officially support this, but we'll know if it breaks.
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir);
assert!(out_path.ancestors().nth(2).unwrap().ends_with("build"));
let header_path = out_path.ancestors().nth(3).unwrap().join("signal_ffi.h");
cbindgen::generate(crate_dir)
.unwrap()
.write_to_file(header_path);
}

View File

@ -1,3 +0,0 @@
Name: signal_ffi
Cflags: -I${pcfiledir}
Libs: -L${pcfiledir} -lsignal_ffi