Skip to content

Commit

Permalink
Fix docs.rs build
Browse files Browse the repository at this point in the history
  • Loading branch information
hwittenborn committed Jun 4, 2023
1 parent 41ed530 commit 2b1c263
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
45 changes: 21 additions & 24 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "husk"
version = "0.1.1"
version = "0.1.2"
authors = ["Hunter Wittenborn <hunter@hunterwittenborn.com>"]
edition = "2021"
description = "Rust bindings for the mvdan.cc/sh Golang library"
Expand Down
16 changes: 14 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
use std::{env, process::Command};
use std::path::PathBuf;
use std::{env, fs, process::Command};

fn main() {
println!("cargo:rerun-if-changed=src/go");
env::set_current_dir("src/go").unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = PathBuf::from(&out_dir);

// The docs.rs builder blocks network access, which would require vendoring everything. I don't
// want to go through that hassle right now, so just generate a dummy file to allow the docs to
// build.
if env::var("DOCS_RS").is_ok() {
fs::write(out_path.join("bindings.rs"), "").unwrap();
return;
}

let status = Command::new("go")
.args(["build", "-buildmode=c-archive", "-o"])
Expand Down Expand Up @@ -38,5 +48,7 @@ fn main() {
.allowlist_function("HuskSyntaxValidName")
.generate()
.unwrap();
bindings.write_to_file("src/bindings.rs").unwrap();
bindings
.write_to_file(out_path.join("bindings.rs"))
.unwrap();
}
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! This crate provides bindings to the [`mvdan.cc/sh` Golang library](https://pkg.go.dev/mvdan.cc/sh).
mod bindings;
pub mod shell;
pub mod syntax;
pub mod util;

mod bindings {
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}

0 comments on commit 2b1c263

Please sign in to comment.