It can be applied either in the exporting country or in the US; in the case of those "first wave" Enfields, I watched workers at (then) Interarmco stamp it on rows and rows of rifles in the bonded warehouse. (FWIW, those guys were minimum wage workers, not gun experts, so sometimes you see Savage or Long Branch Nr. 4's stamped "ENGLAND".)
I got a PM asking what I meant by "bond", so I will take the opportunity to clear that up also. Just about all countries with ports allow the use of "bonded warehouses." These are warehouses that are physically on the soil of the country, but are considered to be legally outside the country. The owner of the warehouse has put up a stiff payment ("bond") as insurance against any goods from that warehouse coming into the country without the proper controls and payment of duties.
The advantage is that a company can use a bonded warehouse for transshipment; for example, goods from England can be stored in the U.S. while waiting shipment to Brazil without concern about U.S. duties or import laws, since legally the goods never enter the U.S. Another advantage is that a COO stamp, or an import mark, which has to be applied before goods can enter the U.S. can be applied "in bond". There is a special benefit for liquor importers, since they can store their product in bond, in bulk, and not pay any duty until it is broken down into retail packaging and released for sale, hence the term "bottled in bond" occasionally seen on liquor bottles.