Skip to content

Commit

Permalink
Build & run flatc using cargo to avoid OS package dependencies
Browse files Browse the repository at this point in the history
  * Use the flatc crate to get a specific flatc version built via
    cargo itself.
  * Remove github action OS package installs
  • Loading branch information
rdaum committed Oct 12, 2024
1 parent 638b68e commit 74244b5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/rust-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: cmake python3-dev swig flatbuffers-compilers
packages: cmake python3-dev swig
version: 1.1
- uses: actions/checkout@v4
with:
Expand All @@ -25,7 +25,7 @@ jobs:
steps:
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: cmake python3-dev swig flatbuffers-compilers
packages: cmake python3-dev swig
version: 1.1
- uses: actions/checkout@v4
with:
Expand All @@ -39,9 +39,9 @@ jobs:
build_default_macos:
runs-on: macos-latest
steps:
- name: Get CMake
uses: symbitic/install-cmake@master
- uses: aisightgmbh/actions-install-flatc@v1
- uses: tecolicom/actions-use-homebrew-tools@v1
with:
tools: cmake
- uses: actions/checkout@v4
with:
submodules: 'true'
Expand All @@ -55,7 +55,7 @@ jobs:
steps:
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: cmake python3-dev swig flatbuffers-compilers
packages: cmake python3-dev swig
version: 1.1
- uses: actions/checkout@v4
with:
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ daumtils = { git = "https://github.com/rdaum/daumtils.git", version = "0.2.0" }
decorum = "0.3" # For ordering & comparing our floats
encoding_rs = "0.8.34"
enum-primitive-derive = "0.3"
flatbuffers = "24.3.25"
flatc-rust = "0.2.0"
flatbuffers = "23.5.26"
flatc = "0.2.2+23.5.26"
flexbuffers = "2.0.0"
im = "15.1"
inventory = "0.3.15"
Expand Down
2 changes: 1 addition & 1 deletion crates/values/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ list_impl_buffer = []
default = []

[build-dependencies]
flatc-rust.workspace = true
flatc.workspace = true
35 changes: 27 additions & 8 deletions crates/values/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,33 @@
// this program. If not, see <https://www.gnu.org/licenses/>.
//

use std::path::Path;

fn main() {
println!("cargo:rerun-if-changed=schema/values.fbs");
flatc_rust::run(flatc_rust::Args {
inputs: &[Path::new("schema/values.fbs")],
out_dir: Path::new("../target/flatbuffers/"),
..Default::default()
})
.expect("flatc");

// Find the flatc binary.
let flatc_path = flatc::flatc();

// Emit the version # by executing the binary with --version
let version = std::process::Command::new(flatc_path)
.arg("--version")
.output()
.expect("failed to get flatc version")
.stdout;

println!(
"cargo:warning=Compiling flatbuffers with {}",
String::from_utf8(version).unwrap()
);

// Invoke flatc to generate Rust code
std::process::Command::new(flatc_path)
// Rust output
.arg("-r")
// My output directory
.arg("-o")
.arg("../target/flatbuffers/")
// My schema
.arg("schema/values.fbs")
.output()
.expect("failed to run flatc");
}

0 comments on commit 74244b5

Please sign in to comment.