Skip to content

Commit

Permalink
write packages version into binary
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-ayf committed May 22, 2024
1 parent 5d15b00 commit 2eff5d0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ audiopus = "=0.3.0-rc.0"

[build-dependencies]
napi-build = "2.0.1"
cargo-lock = "9.0.0"

[profile.release]
lto = true
21 changes: 21 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
extern crate cargo_lock;
extern crate napi_build;

use cargo_lock::Lockfile;
use std::collections::HashMap;

fn main() {
version();
napi_build::setup();
}

fn version() {
println!("cargo:rerun-if-changed=Cargo.lock");

let lock: Lockfile = include_str!("Cargo.lock").parse().unwrap();
let packages: HashMap<_, _> = lock.packages.iter().map(|p| (p.name.as_str(), p)).collect();

println!(
"cargo:rustc-env=JPREPROCESS_VERSION={}",
packages.get("jpreprocess").unwrap().version
);
println!(
"cargo:rustc-env=JBONSAI_VERSION={}",
packages.get("jbonsai").unwrap().version
);
}
8 changes: 7 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export { EncoderType, Channels, Application } from "./native";
export {
JPREPROCESS_VERSION,
JBONSAI_VERSION,
EncoderType,
Channels,
Application,
} from "./native";
export type {
EncoderConfig,
SynthesisOption,
Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// @ts-check

const {
JPREPROCESS_VERSION,
JBONSAI_VERSION,
EncoderType,
Channels,
Application,
Syrinx: SyrinxInner,
} = require(`./native`);
const { Readable } = require("node:stream");

exports.JPREPROCESS_VERSION = JPREPROCESS_VERSION;
exports.JBONSAI_VERSION = JBONSAI_VERSION;
exports.EncoderType = EncoderType;
exports.Channels = Channels;
exports.Application = Application;
Expand Down
2 changes: 2 additions & 0 deletions lib/native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

/* auto-generated by NAPI-RS */

export const JPREPROCESS_VERSION: string
export const JBONSAI_VERSION: string
/** Which encoder to use. */
export enum EncoderType {
/**
Expand Down
12 changes: 1 addition & 11 deletions lib/native.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
const { filename } = require("./filename");
const {
EncoderType,
Channels,
Application,
Syrinx,
} = require(`../${filename}`);

module.exports.EncoderType = EncoderType;
module.exports.Channels = Channels;
module.exports.Application = Application;
module.exports.Syrinx = Syrinx;
module.exports = require(`../${filename}`);
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ use synthesis_option::SynthesisOption;
#[macro_use]
extern crate napi_derive;

#[napi]
pub const JPREPROCESS_VERSION: &str = env!("JPREPROCESS_VERSION");
#[napi]
pub const JBONSAI_VERSION: &str = env!("JBONSAI_VERSION");

mod encoder;
mod synthesis_option;

Expand Down

0 comments on commit 2eff5d0

Please sign in to comment.