Note: most likely you need GadgetFS, not Raw Gadget. See the differences here.
USB Raw Gadget is a kernel module that allows to emulate USB devices from userspace. This repository contains instructions and examples for using Raw Gadget.
The module is currently under review for upstream inclusion, so the interface it provides for the userspace might change.
Building kernel modules requires kernel headers.
On desktop Ubuntu you can get them by installing
On Raspberry Pi Zero follow these instructions.