Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C Command sample fails to build with CMake #63

Open
rido-min opened this issue Sep 8, 2023 · 5 comments
Open

C Command sample fails to build with CMake #63

rido-min opened this issue Sep 8, 2023 · 5 comments
Assignees

Comments

@rido-min
Copy link
Contributor

rido-min commented Sep 8, 2023

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

  • create a new codespace from this repo
  • select C command configuration

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
Copy link
Member

vaavva commented Sep 8, 2023

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

@vaavva vaavva closed this as completed Sep 8, 2023
@rido-min
Copy link
Contributor Author

rido-min commented Sep 8, 2023

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

@rido-min rido-min reopened this Sep 8, 2023
@vaavva
Copy link
Member

vaavva commented Sep 8, 2023

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
Copy link
Contributor Author

rido-min commented Sep 8, 2023

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
Copy link
Member

vaavva commented Sep 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants