  During the evolution of diffuse clouds to molecular clouds, gas-phase
molecules freeze out on surfaces of small dust particles to form ices. On dust
surfaces, water is the main constituent of the icy mantle in which a complex
chemistry is taking place. We aim to study the formation pathways and the
composition of the ices throughout the evolution of diffuse clouds. For this
purpose, we use time-dependent rate equations to calculate the molecular
abundances in both gas phase and on solid surfaces (onto dust grains). We fully
consider the gas-dust interplay by including the details of freeze-out,
chemical and thermal desorption, as well as the most important photo-processes
on grain surfaces. The difference in binding energies of chemical species on
bare and icy surfaces is also incorporated into our equations. Using the
numerical code FLASH, we perform a hydrodynamical simulation of a
gravitationally bound diffuse cloud and follow its contraction. We find that
while the dust grains are still bare, water formation is enhanced by grain
surface chemistry which is subsequently released into the gas phase, enriching
the molecular medium. The CO molecules, on the other hand, tend to freeze out
gradually on bare grains. This causes CO to be well mixed and strongly present
within the first ice layer. Once one monolayer of water ice has formed, the
binding energy of the grain surface changes significantly and an immediate and
strong depletion of gas-phase water and CO molecules occur. While hydrogenation
converts solid CO into formaldehyde (H$_2$CO) and methanol (CH$_3$OH), water
ice becomes the main constituent of the icy grains. Inside molecular clumps
formaldehyde is more abundant than water and methanol in the gas phase owing
its presence in part to chemical desorption.
