Azure-Samples / MqttApplicationSamples

Samples implementing common PubSub patterns for Edge and Cloud Brokers
MIT License
23 stars 25 forks source link

C Command sample fails to build with CMake #63

Open rido-min opened 1 year ago

rido-min commented 1 year ago

This issue is for a: (mark with an x)

- [ X] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Any log messages given by the failure

[cmake] CMake Error at scenarios/command/c/CMakeLists.txt:14 (add_executable):
[cmake]   Cannot find source file:
[cmake] 
[cmake]     /workspaces/MqttApplicationSamples/scenarios/command/c/protobuf/google/protobuf/timestamp.pb-c.c
[cmake] 
[cmake]   Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
[cmake]   .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
[cmake]   .f95 .f03 .hip .ispc
[cmake] 
[cmake] 
[cmake] CMake Error at scenarios/command/c/CMakeLists.txt:14 (add_executable):
[cmake]   No SOURCES given to target: command_server
[cmake] 
[cmake] 
[cmake] CMake Error at scenarios/command/c/CMakeLists.txt:22 (add_executable):
[cmake]   No SOURCES given to target: command_client
[cmake] 
[cmake] 
[cmake] CMake Generate step failed.  Build files cannot be regenerated correctly.
[proc] The command: /home/codespace/.local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DPRESET_PATH=/workspaces/MqttApplicationSamples/scenarios/command/c -S/workspaces/MqttApplicationSamples -B/workspaces/MqttApplicationSamples/scenarios/command/c/build -G Ninja exited with code: 1

Expected/desired behavior

The sample builds successfully

Language

C

OS and Version?

Codespaces

Mention any other details that might be useful

Other targets build correctly


Thanks! We'll be in touch soon.

vaavva commented 1 year ago

Not a bug - C instructions on the command sample need to be followed before running the sample: https://github.com/Azure-Samples/MqttApplicationSamples/tree/main/scenarios/command#c

To generate the c files to handle the protobuf payload, install protobuf-c-compiler and libprotobuf-dev. Note that you only need these to generate the files, running the sample only requires the libprotobuf-c-dev package.

sudo apt-get install protobuf-c-compiler libprotobuf-dev

Then, to generate the files, run:

# from the root folder
protoc-c --c_out=./scenarios/command/c/protobuf --proto_path=./scenarios/command/c/protobuf unlock_command.proto google/protobuf/timestamp.proto
rido-min commented 1 year ago

well, this happens to me when opening the repo in VSCode (with codespaces), before even reading the READMEs.

Can we update devContainer with the apt-get packages ?

wondering if CMake allows to add a pre-build task to invoke proto automagically

vaavva commented 1 year ago

Customers will need to read the readme's to set up all of their environment variables anyways before running it, so I don't think it's an issue for them to need to read things there before running the samples.

We could update the devContainer (the postCreateCommand.sh) to install those packages - I think we had decided before not to since they're only needed on the C command sample and only for the single time they generate the files, but I'm not opposed to adding them for ease of use in codespaces.

We wouldn't want cmake to invoke the proto creation automatically because it doesn't need to be done every build, but we could have the generation happen in postCreateCommand.sh script if you'd prefer (similar to the cert generation)! Again, this adds more steps to this script that are specific to only the C Command sample, but it would make this compile right after the initialization.

rido-min commented 1 year ago

agree.. this is a side effect of VSCode trying to setup everything when opening the folder.. sigh..

we are already installing C-only-dependencies in the postCreateCommand, such as ninja, and lib-dev, so I dont see any issue adding more dependencies.

Is there a way to tell CMake to generate the files only if those are not there? worst case, generating always does not seem too bad.. I would not generate those in postCreateCommand though.

vaavva commented 1 year ago

I don't think there's a way to generate it in cmake, and the customer should be aware of the step since they might need to generate more or different files if they're using a different protobuf payload