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

Specify cmake arguments from file like idf.py (VSC-1488) #1309

Closed
mbastida123 opened this issue Sep 13, 2024 · 14 comments
Closed

Specify cmake arguments from file like idf.py (VSC-1488) #1309

mbastida123 opened this issue Sep 13, 2024 · 14 comments
Labels
Feature / Enhancement Request Request for Feature/ Enhancement

Comments

@mbastida123
Copy link

Hi, I don't know if this is already possible. I'm crosposting from espressif/esp-idf#12257

I have created a file config.txt:
-B builds/build1 -DSDKCONFIG=builds/build1 /sdkconfig -DSDKCONFIG_DEFAULTS=zconfig/sdkconfig.prod_common

Following the multi-config example I can idf.py @config.txt build

However, what if I wanted to integrate this into the vscode extension?
The extension doesn't use idf.py and instead invokes cmake directly. So adding @config.txt to "idf.cmakeCompilerArgs" is not an option.

@mbastida123 mbastida123 added the Feature / Enhancement Request Request for Feature/ Enhancement label Sep 13, 2024
@mbastida123 mbastida123 changed the title [Feature Request]: Specify cmake arguments from file like idf.py Specify cmake arguments from file like idf.py Sep 13, 2024
@github-actions github-actions bot changed the title Specify cmake arguments from file like idf.py Specify cmake arguments from file like idf.py (VSC-1488) Sep 13, 2024
@brianignacio5
Copy link
Collaborator

We have extension settings to achieve this use case. There is idf.buildPath to define the build path, idf.sdkconfigDefaults to define SDKCONFIG_DEFAULTS and idf.cmakeCompilerArgs for additional CMake arguments. Look at the settings documentation https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/SETTINGS.md

I believe you are trying to use the multi_config example. We have a tutorial for what we call project configuration which allows you to use multiple configuration in a single ESP-IDF project, please take a look https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/project_configuration.md

@mbastida123
Copy link
Author

We have extension settings to achieve this use case. There is idf.buildPath to define the build path, idf.sdkconfigDefaults to define SDKCONFIG_DEFAULTS and idf.cmakeCompilerArgs for additional CMake arguments. Look at the settings documentation https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/SETTINGS.md

I believe you are trying to use the multi_config example. We have a tutorial for what we call project configuration which allows you to use multiple configuration in a single ESP-IDF project, please take a look https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/project_configuration.md

Hi @brianignacio5

I was aware of all the examples. In fact, that's what we were using until now.

However, due to the complexity of our multiple sdkconfig.defaults we want to automate the assignation of each sdkconfig.defaults for each build. And to avoid touching the settings.json from a script I had seen the option to pass cmd arguments directly via file. But from your explanation I understand this is not possible with cmake. However, it is possible with idf.py

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Sep 18, 2024

If you want to use idf.py and this config.txt file, you can just open an IDF terminal with ESP-IDF: Open ESP-IDF Terminal command and run the idf.py @config.txt build. You can also just put this command to the idf.customTask: "idf.py @config.txt build"in settings.json and use the ESP-IDF: Execute Custom Task to run it (There is an icon in status bar for execute custom task too)

If you want to use extension commands, you can define multiple profiles (with ESP-IDF: Project Configuration Editor) and when you select a profile and build the effect is the same. It takes a bit of writing but it achieves the same use case.

You can create a profile in Project Configuration Editor UI, each profile can define its own SDKCONFIG_DEFAULTS value. When you select a profile and build, it will use the SDKCONFIG_DEFAULTS from the selected profile. So it is indeed possible with CMake to achieve multiple sdkconfig defaults, this is covered in the project_configuration tutorial I shared before.

Does this information help your use case ?

@mbastida123
Copy link
Author

mbastida123 commented Sep 18, 2024

If you want to use idf.py and this config.txt file, you can just open an IDF terminal with ESP-IDF: Open ESP-IDF Terminal command and run the idf.py @config.txt build. You can also just put this command to the idf.customTask: "idf.py @config.txt build"in settings.json and use the ESP-IDF: Execute Custom Task to run it (There is an icon in status bar for execute custom task too)

If you want to use extension commands, you can define multiple profiles (with ESP-IDF: Project Configuration Editor) and when you select a profile and build the effect is the same. It takes a bit of writing but it achieves the same use case.

You can create a profile in Project Configuration Editor UI, each profile can define its own SDKCONFIG_DEFAULTS value. When you select a profile and build, it will use the SDKCONFIG_DEFAULTS from the selected profile. So it is indeed possible with CMake to achieve multiple sdkconfig defaults, this is covered in the project_configuration tutorial I shared before.

Does this information help your use case ?

The fact that the extension suports profiles is interesting. The configuration is editable on a file? Where is it located? Other than the UI editor I mean.

I ask this because we are mutliple developers and we would like to all have the same build profiles somewhere.

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Sep 18, 2024

Yes it is saved as a json file in the project directory (/path/to/esp-project/esp_idf_project_configuration.json) when you saved from the Project Configuration Editor UI. The file is also read when you open the former UI so it could be pushed into GitHub for example.

Each profile can define multiple settings as described in the shared documentation. Here is a schema of the profile object file:

{
"profileName": {
    build: {
      compileArgs: string[];
      ninjaArgs: string[];
      buildDirectoryPath: string;
      sdkconfigDefaults: string[];
      sdkconfigFilePath: string;
    };
    env: { [key: string]: string };
    flashBaudRate: string;
    idfTarget: string;
    monitorBaudRate: string;
    openOCD: {
      debugLevel: number;
      configs: string[];
      args: string[];
    };
    tasks: {
      preBuild: string;
      preFlash: string;
      postBuild: string;
      postFlash: string;
    };
  }
}

The currently selected profile is not saved in the file and only saved as a workspace state.

@brianignacio5
Copy link
Collaborator

I will suggest not using sdkconfigFilePath until #1252 is merged since we made fixes to the SDK Configuration Editor when using multiple configuration for single project.

@mbastida123
Copy link
Author

THank you @brianignacio5 ! it's all clear now.

I will wait for the merge to use sdkconfigFilePath.

Final question: Is there any place on the lower bar where you can see change the configuration profile as well as see which configuration profile are you currently on? The later one is the most important. Something like we see with the IDF version would be really nice:
image

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Sep 18, 2024

Yes there is an icon showing the currently selected profile and when you click you quickly change between profiles (a dropdown with all profiles option will be shown).

If you want to test it now, you can use the extension vsix installer from the pull request

@mbastida123
Copy link
Author

Yes there is an icon showing the currently selected profile and when you click you quickly change between profiles (a dropdown with all profiles option will be shown).

If you want to test it now, you can use the extension vsix installer from the pull request

I have installed the vsix. I don't know if there's a way to tell that the vsix has been applied though.

Anyway, where's the icon?
image

BTW, the sdkconfigFilePath seems to work fine. I don't know what was wrong before though.

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Sep 18, 2024

After you define the profiles with the UI, use ESP-IDF: Select Project Configuration command to select a profile.

See if the name is shown in the status command.

@mbastida123
Copy link
Author

After you define the profiles with the UI, use ESP-IDF: Select Project Configuration command to select a profile.

See if the name is shown in the status command.

Don't know why but now it is showing even though before I did the same steps as now.

Related question: Is this system integrated with idf.py?
I want to have a CI/CD pipeline that builds all the profiles. I would use idf.py for that. But does idf.py also accept this system or I have to parse the json manually if I want to use idf.py?

@brianignacio5
Copy link
Collaborator

CI/CD is not intended for this feature, since it is a vscode extension feature. For that case I would suggest to go with the idf.py @config.txt build approach.

I believe that converting from the json to a .txt file is easy (and could be automated too). We could add a command to convert the currently select profile to such .txt if desired, but probably in CI/CD you might want to have these .txt as part as the repository.

@mbastida123
Copy link
Author

CI/CD is not intended for this feature, since it is a vscode extension feature. For that case I would suggest to go with the idf.py @config.txt build approach.

I believe that converting from the json to a .txt file is easy (and could be automated too). We could add a command to convert the currently select profile to such .txt if desired, but probably in CI/CD you might want to have these .txt as part as the repository.

Makes sense, thank you!

Excelent work on the extension.

@brianignacio5
Copy link
Collaborator

If you find the extension useful. Please leave us a review in the Visual Studio Code Marketplace

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

No branches or pull requests

2 participants