In the One Piece world, you can give a devil fruit power to weapons (things) by destroying it with that weapon. It seems one can also give haki to weapon, how can they do that? Kuja tribe member Marguerite is the first to be seen doing that. (Chapter 516)
Only Color of Armaments can be given to a weapon. Since weapon is non-living, Color of Observation and Conqueror's Haki cannot be provided. Weapons can be thought of like an extension of one's limbs (although not mentioned in OP, this is usually the case in most manga). Color of Armaments provides an extra layer of hard protection from external injury to one's body. With sufficient practice, it can be used as weapon to attack. Since weapons are an extension of one's body, weapons are given armament protection to make them more lethal.
Also, Rayleigh did mention that Color of Armaments can be imbued with a weapon for more impact. But how it is done has not been explained properly.
It's not much more than SpOT's answer, but I'll added the sources.
It's never clearly explained. Rayleigh and Mihawk only mention the overall concept of extending reinforcement Haki to weapons to Luffy and Zorry respectively (Chapter 597 and 779):
After his fight with Pica, Zorry remembers a conversion with Mihawk:
However this idea in manga is not new, and it reminds of how in hunterXhunter Nen can be extended to a weapon if you think about that weapon being an extension of your body (notice Killua mentions "reinforcement"; Chapter 140):