Skip to content

Commit

Permalink
Fix build.rs Swagger UI dist location
Browse files Browse the repository at this point in the history
  • Loading branch information
juhaku committed Feb 14, 2022
1 parent b181928 commit 389ef4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::process::Command;
use std::{
env::{self, VarError},
process::Command,
};

const SWAGGER_UI_DIST_ZIP: &str = "swagger-ui-4.5.0";

Expand All @@ -9,10 +12,16 @@ fn main() {
SWAGGER_UI_DIST_ZIP
);

let target_dir = env::var("CARGO_TARGET_DIR")
.or_else(|_| env::var("CARGO_BUILD_TARGET_DIR"))
.or_else(|_| -> Result<String, VarError> { Ok("target".to_string()) })
.unwrap();
println!("cargo:rustc-env=UTOIPA_SWAGGER_DIR={}", &target_dir);

Command::new("unzip")
.arg(&format!("res/{}.zip", SWAGGER_UI_DIST_ZIP))
.arg(&format!("{}/dist/**", SWAGGER_UI_DIST_ZIP))
.args(&["-d", "target"])
.args(&["-d", &target_dir])
.status()
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/swagger_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::openapi::OpenApi;

#[doc(hidden)]
#[derive(RustEmbed)]
#[folder = "target/$UTOIPA_SWAGGER_UI_VERSION/dist/"]
#[folder = "$UTOIPA_SWAGGER_DIR/$UTOIPA_SWAGGER_UI_VERSION/dist/"]
pub struct SwaggerUiDist;

#[non_exhaustive]
Expand Down

0 comments on commit 389ef4f

Please sign in to comment.