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

Tools for Integrating Gamer with VS Code #382

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

technic960183
Copy link
Contributor

@technic960183 technic960183 commented Dec 4, 2024

These files help user to setup an environment to work on Gamer in Visual Studio Code.

  • README.md: Contains instructions of setup and usages.
  • c_cpp_properties.json: Contains the IntelliSense configuration.
  • gamercpp.natvis: Contains the visualization configuration for debugger.
  • launch.json: Contains the debug configuration.
  • tasks.json: Contains the build configuration.
  • extract_macros.py: Script to extract the macros from the Makefile.log to c_cpp_properties.json.
  • copy_to_vscode.sh: Script to copy the files to .vscode/ directory and set up the working path.

Note:
Now gamercpp.natvis contain Timer_t only. This can let us check that the NATVIS works correctly. We could add more type of structures and classes in the future.

@hyschive hyschive requested a review from vivi235711 December 21, 2024 06:58
@hyschive hyschive added enhancement tool Useful analysis and visualization tools new feature and removed enhancement labels Dec 21, 2024
Copy link
Contributor

@vivi235711 vivi235711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I've tested the setup on both my MacBook Air (M1) and spock. The run on spock works without any issues when OpenMP is disabled. However, on the Mac with the new architecture, they only support LLVM instead of GDB, leading to differences in implementation.

To make it work on the Mac, here's what I did:
Install llvm for lldm-mi:

brew install llvm
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc
echo 'export LDFLAGS="-L/usr/local/opt/llvm/lib"' >> ~/.zshrc
echo 'export CPPFLAGS="-I/usr/local/opt/llvm/include"' >> ~/.zshrc

Install lldb-mi:

git clone https://github.com/lldb-tools/lldb-mi.git
cmake -DCMAKE_CXX_FLAGS="-I/usr/local/opt/llvm/include" -DCMAKE_CXX_COMPILER="/usr/local/opt/llvm/bin/clang++" ..
cmake --build .

Lastly, I updated the launch.json file with the following configuration:

"MIMode": "lldb",
"miDebuggerPath": "/Users/vivi/develop/lldb-mi/build/src/lldb-mi",
"miDebuggerArgs": "-Q",

Here, the miDebuggerPath is set to the directory where lldb-mi is installed.

With these changes, I was able to get the application running on my Mac.

I haven't tried it on Windows yet. If cross-platform compatibility is required, additional adjustments may be necessary. Let me know if you have any thought.

Comment on lines 13 to 17
if [ ! -d "$(realpath "$TARGET_DIR")" ]; then
echo "Target directory $(realpath "$TARGET_DIR") does not exist."
mkdir -p "$(realpath "$TARGET_DIR")"
echo "Target directory $(realpath "$TARGET_DIR") created."
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The realpath has different usage at mac os. Is it necessary to avoid the problem of not absolute path? If not, maybe can switch to

if [ ! -d "$TARGET_DIR" ]; then
  echo "Target directory $TARGET_DIR does not exist."
  mkdir -p "$TARGET_DIR"
  echo "Target directory $TARGET_DIR created."
fi

so it can run at both os.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed all of the realpath. I would like to make the message to be more informative before.
Please help me to test it again. Thanks!

echo "$filename copied."
fi

sed -i "s/Gamer_Working_SubDir/$WORKING_DIR/g" "$TARGET_DIR/$filename"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of sed is different between linux and mac os.

sed "s/Gamer_Working_SubDir/$WORKING_DIR/g" "$TARGET_DIR/$filename" > "$TARGET_DIR/$filename.tmp" && mv "$TARGET_DIR/$filename.tmp" "$TARGET_DIR/$filename"

This might can run on both os.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change the way to setup the working directory. So sed is not needed anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be more convenient if it can automatically copy the new build gamer into the work directory. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also maybe run sh generate_make.sh automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have integrated copying the new executable into the building task.
And added a new task for configuring.


### Run build task

After configuring Gamer with [configure.py](https://github.com/gamer-project/gamer/wiki/Installation%3A-Configure.py), select `Terminal` > `Run Build Task...` or press `Ctrl + Shift + B` to start the build task. This will update the macros, providing IntelliSense highlighting support.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that debugging with parallel at vscode is difficult (not only mpi, but also openmp). Should we remind to disable mpi and openmp here?

Copy link
Contributor Author

@technic960183 technic960183 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a note for the macOS users. But have not provide an explicit solusion yet.

- Add new tasks for configuring GAMER
- Copy the executable after building
- Update wiki for the new tasks
- Remove `realpath` from the copy script
- Add a note for macOS users

And some other minor improvements
- Make build-GAMER as a sequence of tasks
- Fix typos: `Gamer` -> `GAMER`
- Remove unnecessary information from `tool/vscode/README`.
- Make tasks as a `.sh` script
- Avoid the use of `sed` in the bash script
- Update wiki accordingly
- Update `tool/vscode/README` accordingly
Copy link
Contributor Author

@technic960183 technic960183 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thansk for the review and the comments.

The main change in this update is to add a new task for setup the working directory under bin/. And the copy script will only be executed once.

As the commit messages, the minor updates are:

Improvements as the code review comments

  • Add new tasks for configuring GAMER and update wiki accordingly
  • Copy the executable after building
  • Remove realpath from the copy script
  • Add a note for macOS users

And some other minor improvements

  • Fix typos: Gamer -> GAMER
  • Remove unnecessary information from tool/vscode/README.
  • Make tasks as .sh scripts
  • Avoid the use of sed in the bash script
  • Update wiki accordingly
  • Update tool/vscode/README accordingly

Please help me to review these updates, thanks!

Comment on lines 13 to 17
if [ ! -d "$(realpath "$TARGET_DIR")" ]; then
echo "Target directory $(realpath "$TARGET_DIR") does not exist."
mkdir -p "$(realpath "$TARGET_DIR")"
echo "Target directory $(realpath "$TARGET_DIR") created."
fi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed all of the realpath. I would like to make the message to be more informative before.
Please help me to test it again. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have integrated copying the new executable into the building task.
And added a new task for configuring.

echo "$filename copied."
fi

sed -i "s/Gamer_Working_SubDir/$WORKING_DIR/g" "$TARGET_DIR/$filename"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change the way to setup the working directory. So sed is not needed anymore.


### Run build task

After configuring Gamer with [configure.py](https://github.com/gamer-project/gamer/wiki/Installation%3A-Configure.py), select `Terminal` > `Run Build Task...` or press `Ctrl + Shift + B` to start the build task. This will update the macros, providing IntelliSense highlighting support.
Copy link
Contributor Author

@technic960183 technic960183 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a note for the macOS users. But have not provide an explicit solusion yet.

@hyschive
Copy link
Contributor

@technic960183 Please resolve the conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature tool Useful analysis and visualization tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants