Peel onions and garlic. Cut or slice the onions into rings. Chop garlic finely. Wash the rosemary, dab dry, remove the needles and chop finely.
Heat the oil in a large pot. Fry the onions and garlic over a low heat for about 10 minutes while stirring until soft and glassy, without browning. Approx. 2⁄3 Braise the rosemary briefly.
Sprinkle flour over the onions and sauté lightly. Deglaze with wine and 1 l water, bring to the boil and stir in stock. Season soup with salt, pepper and 1 pinch of sugar and simmer covered for about 20 minutes.
In the meantime, preheat the oven (electric cooker: 225 °C/circulating air: 200 °C/gas: see manufacturer). Line a baking tray with baking paper. Cut the baguette into 12 thin slices and place them on the baking tray. Grate cheese finely.
Mix with the remaining rosemary. Spread on the baguette slices. Bake in a hot oven for 5-7 minutes. Flavour the soup again and serve. Spread the baguette on top and serve immediately.