Metabolism consists of anabolic and catabolic processes. Anabolism is the building of chemical compounds from smaller building blocks. In the case of photosynthesis, anabolism refers to the synthesis of the sugar glucose from carbon dioxide (CO2), while the breakdown of sugar is a type of catabolism. Anabolism requires a source of energy. In the case of photosynthesis, the energy is light from the sun.
Compared to sugars such as glucose, CO2 is an "oxidized" chemical compound. The carbon atom of CO2 has less of a hold on its electrons as compared to the carbon atoms in a sugar, which thus is considered to be more "reduced." The more reduced a compound, the more strongly its carbon atoms hold electrons; the more oxidized a compound, the more weakly its carbon atoms hold electrons. Another way of thinking about this is that the electrons are drawn away from carbon atoms by more "electrophillic" atoms such as nitrogen, and especially oxygen. Thus, reduction is the gain of electrons, while oxidation is the loss of electrons, and it is the electrons which carry and hold the energy within biological compounds. Consequently, a compound that is more reduced holds more chemical energy as compared to a compound that is more oxidized. It is through the production of high energy electrons that light energy is captured in a form that can be used later for the anabolism of glucose.
During the light reactions of photosynthesis, light from the sun is captured through a series of reactions involving the chemical chlorophyll. This results in the synthesis of two high-energy chemical compounds: ATP and NADPH, the latter whose chemical energy is held by electrons which can be transferred easily to other compounds. This set of reactions requires water (H2O) from which oxygen is released during the process.
In the dark reactions, which can take place either in the presence of light or in the dark, energy from ATP and NADPH is used to bond---or "fix"---CO2 to a 5-carbon sugar, resulting in 6-carbon sugar, glucose. This "carbon fixation" is known as the Calvin Cycle.
Because a low-energy compound, CO2, is fixed to another carbon-containing compound, resulting in a compound of higher energy, the Calvin Cycle is an anabolic process. Since the energy for this comes from high-energy compounds produced during the light reactions, the energy source for the anabolism of sugar is the sun.