What is the easiest way to do development for ubus and its dependencies?

I am looking for a simple way to quickly use libubus in some early development. I am mostly looking to experiment around and I need a way to use libubus in cgo without building an entire OpenWRT image. Ideally I just want to get a version of libubus that I can link against to build the binary for testing in a virtual environment. In the OpenWRT Wiki I see that you can build a single package but I don't know how to just select ubus.

I think that if you do make package/ubus/compile it will build libubus as a dependency of the ubus package.

$ make package/ubus/compile
make[2]: Entering directory '/home/efahlgren/openwrt/openwrt/scripts/config'
make[2]: 'conf' is up to date.
make[2]: Leaving directory '/home/efahlgren/openwrt/openwrt/scripts/config'
 make[1] package/ubus/compile
 make[2] -C package/utils/lua host-compile
 make[2] -C package/system/apk host-compile
 make[2] -C package/libs/toolchain compile
 make[2] -C package/libs/libjson-c compile
 make[2] -C package/utils/lua compile
 make[2] -C package/libs/libubox compile
 make[2] -C package/system/ubus compile


$ ll build_dir/target-x86_64_musl/ubus-2025.01.02~afa57cce/libubus.so*
Permissions Size User      Date Modified    Git Name
lrwxrwxrwx@    - efahlgren 2025-01-13 09:13  -I build_dir/target-x86_64_musl/ubus-2025.01.02~afa57cce/libubus.so -> libubus.so.20250102
.rwxr-xr-x@ 207k efahlgren 2025-01-13 09:13  -I build_dir/target-x86_64_musl/ubus-2025.01.02~afa57cce/libubus.so.20250102

I get a build error saying openwrt/staging_dir/toolchain-x86_64_gcc-12.3.0_musl/lib/ld-musl-.so': No such file or directory. I think I need to build musl first but I don't know how to build musl without building everything else. Am I understanding this error correctly?

Yeah, looks like the toolchain hasn't been built yet. I usually just do a plain make without arguments, let it build everything once. After that all the host and device tools should be in place so you can do the package-specific make package/... without having to do a full build (until you either change targets or git pull something with a toolchain update, of course).

make will build a OpenWRT image. I was hoping to avoid doing that as it is a waste of resources. However, it probably is just easier to build the default image.

Thanks

There may be a way to bypass doing the whole thing, maybe one of the targets like prepare or prereq does the tools? I just tried both and I'm not sure what they do, since my build environment is already fully populated. Give them a try and see what happens, I guess...

1 Like