async fn build_global_state(&self, exporting: bool) -> Result<TemplateState, ServerError> {
        let gsc = &self.global_state_creator;

        if exporting && (gsc.uses_request_state() || gsc.can_amalgamate_states()) {
            return Err(ExportError::GlobalStateNotExportable.into());
        }

        let global_state = if gsc.uses_build_state() {
            // Generate the global state and write it to a file
            let global_state = gsc.get_build_state().await?;
            self.immutable_store
                .write(
                    // We put the locale at the end to prevent confusion with any pages
                    "static/global_state.json",
                    &global_state.state.to_string(),
                )
                .await?;
            global_state
        } else {
            // If there's no build-time handler, we'll give an empty state. This will
            // be very unexpected if the user is generating at request-time, since all
            // the pages they have at build-time will be unable to access the global state.
            // We could either completely disable build-time rendering when there's
            // request-time global state generation, or we could give the user smart
            // errors and let them manage this problem themselves by gating their
            // usage of global state at build-time, since `.try_get_global_state()`
            // will give a clear `Ok(None)` at build-time. For speed, the latter
            // approach has been chosen.
            //
            // This is one of the biggest 'gotchas' in Perseus, and is clearly documented!
            TemplateState::empty()
        };
        Ok(global_state)
    }
Builds the global state, returning the state generated. This will also
write the global state to the immutable store (there is no such
thing as revalidation for global state, and it is *extremely*
unlikely that there ever will be).
packages/perseus/src/turbine/build.rs