Objective: How do I seal up the gap between brick and the studs of the walls of a sunroom when making an addition to a house?

Which of the following solutions is more sound in terms of naive physics reasoning?
Spray insulation foam between the brick and the stud also to seal up the gap completely.