This question is a tough one. As an analogy, many people uses the common spreadsheet program Excel, as well as Python to produce the content of their papers. They ask for help not to friends but to random strangers on the internet (for example on Stack Overflow (SO) ).
However, Doug klunder the original creator of the "pre-"Excel Doug Klunder nor the latest implementer of Excel Charles Simonyi are co-author of papers. And also the many contributors from SO and similar sites are not co-authors of the paper. Guido Van Rossum of Python fame may be cited every now and then, but he is not co-author of the python based papers, not even if he contributed to them (answering FAQ, answering to blog posts, fixing bugs, etcetc.)
In short and in general: if your friend is just building the code for you, in my view he deserves a lot of gratitude, but not the co-autorship. However, YMMV depending on your field.
Even more general: your friend is doing his job (programming) for free for you. If they want something in exchange, they are practically lending you some money (in form of their work).
If, on the other hand, you give them first authorship and later realize it is too much, you will always have the feeling of having given (lend) him too much, so you will expect a subsatntial pay back.
Do you know the saying
If You Want to Lose a Friend, Loan Them Money
?
you are walking that thin line ... either you give up on asking your friend for so much help, or he accept doing that as a pro-bono help to you, without messing up with "sizing" the right reward.