We show that the dynamics of kinetically constrained models of glass formers takes place at a firstorder coexistence line between active and inactive dynamical phases. We prove this by computing the large-deviation functions of suitable space-time observables, such as the number of configuration changes in a trajectory. We present analytic results for dynamic facilitated models in a mean-field approximation, and numerical results for the Fredrickson-Andersen model, the East model, and constrained lattice gases, in various dimensions. This dynamical first-order transition is generic in kinetically constrained models, and we expect it to be present in systems with fully jammed states. An increasingly accepted view is that the phenomenology associated with the glass transition [1] requires a purely dynamic analysis, and does not arise from an underlying static transition (see however [2]). Indeed, it has been suggested that the glass transition manifests a firstorder phase transition in space and time between active and inactive phases [3]. Here we apply Ruelle's thermodynamic formalism [4,5] to show that this suggestion is indeed correct, for a specific class of stochastic models. The existence of active and inactive regions of spacetime, separated by sharp interfaces, is dynamic heterogeneity, a central feature of glass forming systems [6]. This phenomenon, in which the dynamics becomes increasingly spatially correlated at low temperatures, arises naturally [7] in models based on the idea of dynamic facilitation, such as spin-facilitated models [8,9], constrained lattice gases [10,11] and other kinetically constrained models (KCMs) [12]. Fig. 1 illustrates the discontinuities in space-time order parameters at the dynamical transition in one such model, together with the singularity in a space-time free energy, as a function of a control parameter to be discussed shortly.The thermodynamic formalism of Ruelle and coworkers was developed in the context of deterministic dynamical systems [4]. While traditional thermodynamics is used to study fluctuations associated with configurations of a system, Ruelle's formalism yields information about its trajectories (or histories). The formalism relies on the construction of a dynamical partition function, analogous to the canonical partition function of thermodynamics. The energy of the system is replaced by the dynamical action (the negative of the logarithm of the probability of a given history); the entropy of the system by the Kolmogorov-Sinai entropy [13], and the temperature by an intrinsic field conjugate to the action. This formalism has been exploited recently to describe the chaotic properties of continuous-time Markov processes [5].In this work, we define the dynamical partition sum [4, where the sum is over histories from time 0 to time t; the probability of a history is Prob(history); andK(history) is the number of configuration changes in that history. K(history) is a direct measure of the activity in a history: an active trajectory has many changes of configur...