11use change_detection:: ChangeDetection ;
2- use static_files:: NpmBuild ;
3- use std:: { env, path:: Path } ;
2+ use static_files:: { resource_dir, NpmBuild } ;
3+ use std:: env;
4+ use std:: path:: Path ;
45
56// These are touched during the build, so it would re-build every time if we
67// don't exclude them from change detection:
@@ -10,30 +11,45 @@ const EXCLUDE_LIST: [&str; 3] = [
1011 "../../web-ui/.next" ,
1112] ;
1213
14+ /// The build script has two modes:
15+ ///
16+ /// - if `WEBUI_BUILD_DIR` we use that to serve in the manager
17+ /// - otherwise we build the web-ui from web-ui and serve it from the manager
18+ ///
19+ /// The first mode is useful in CI builds to cache the website build so it
20+ /// doesn't get built many times due to changing rustc flags.
1321fn main ( ) {
14- ChangeDetection :: exclude ( |path : & Path | {
15- EXCLUDE_LIST
22+ if let Ok ( webui_out_folder) = env:: var ( "WEBUI_BUILD_DIR" ) {
23+ ChangeDetection :: path ( & webui_out_folder) . path ( "build.rs" ) . generate ( ) ;
24+ println ! ( "cargo:rerun-if-changed=build.rs" ) ;
25+ resource_dir ( webui_out_folder)
26+ . build ( )
27+ . expect ( "Could not use WEBUI_BUILD_DIR as a website location" )
28+ } else {
29+ ChangeDetection :: exclude ( |path : & Path | {
30+ EXCLUDE_LIST
1631 . iter ( )
1732 . any ( |exclude| path. to_str ( ) . unwrap ( ) . starts_with ( exclude) )
1833 // Also exclude web-ui folder itself because we mutate things inside
1934 // of it
2035 || path. to_str ( ) . unwrap ( ) == "../../web-ui/"
21- } )
22- . path ( "../../web-ui/" )
23- . path ( "build.rs" )
24- . generate ( ) ;
25- println ! ( "cargo:rerun-if-env-changed=NEXT_PUBLIC_MUIX_PRO_KEY" ) ;
36+ } )
37+ . path ( "../../web-ui/" )
38+ . path ( "build.rs" )
39+ . generate ( ) ;
40+ println ! ( "cargo:rerun-if-env-changed=NEXT_PUBLIC_MUIX_PRO_KEY" ) ;
2641
27- NpmBuild :: new ( "../../web-ui" )
28- . executable ( "yarn" )
29- . install ( )
30- . expect ( "Could not run `yarn install`. Follow set-up instructions in web-ui/README.md" )
31- . run ( "build" )
32- . expect ( "Could not run `yarn build`. Run it manually in web-ui/ to debug." )
33- . run ( "export-to-out" )
34- . expect ( "Could not run `yarn export-to-out`. Run it manually in web-ui/ to debug." )
35- . target ( env:: var ( "OUT_DIR" ) . unwrap ( ) )
36- . to_resource_dir ( )
37- . build ( )
38- . unwrap ( ) ;
42+ NpmBuild :: new ( "../../web-ui" )
43+ . executable ( "yarn" )
44+ . install ( )
45+ . expect ( "Could not run `yarn install`. Follow set-up instructions in web-ui/README.md" )
46+ . run ( "build" )
47+ . expect ( "Could not run `yarn build`. Run it manually in web-ui/ to debug." )
48+ . run ( "export-to-out" )
49+ . expect ( "Could not run `yarn export-to-out`. Run it manually in web-ui/ to debug." )
50+ . target ( env:: var ( "OUT_DIR" ) . unwrap ( ) )
51+ . to_resource_dir ( )
52+ . build ( )
53+ . unwrap ( ) ;
54+ }
3955}
0 commit comments