From fffd7d315f4350c71c651042646145a09bd3985d Mon Sep 17 00:00:00 2001 From: jzsz-wsl <840863191@qq.com> Date: Mon, 8 Apr 2024 12:11:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A4=BA=E4=BE=8B=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=AC=A6=E5=90=88side=E5=AE=B9=E5=99=A8=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=A0=87=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/Dockerfile | 4 +- .devcontainer/devcontainer.json | 25 +++--------- .gitignore | 3 +- .vscode/tasks.json | 51 ++++++++++++++++++++++++ Makefile | 18 +++++---- README.md | 69 ++++++++++++++++++++++++++++++--- SuperIDE.ini | 11 ++++++ include/README | 39 +++++++++++++++++++ lib/README | 46 ++++++++++++++++++++++ hello.c => src/source.c | 3 +- 10 files changed, 233 insertions(+), 36 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 SuperIDE.ini create mode 100644 include/README create mode 100644 lib/README rename hello.c => src/source.c (43%) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 10e2e7a..18ad12c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,3 +1,3 @@ -FROM mcr.microsoft.com/devcontainers/base:alpine-3.19 +FROM jzsz/c-test:0.1 # Install the gdb -RUN apk add gdb \ No newline at end of file +# RUN apk add gdb \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4dd962f..16126ed 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,22 +2,9 @@ // README at: https://github.com/devcontainers/templates/tree/main/src/alpine { "name": "My Dev Container", - "build": { - // Path is relative to the devcontainer.json file. - "dockerfile": "Dockerfile" - } - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "uname -a", - - // Configure tool-specific properties. - // "customizations": {}, - - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} + "build": { + "dockerfile": "Dockerfile" + } + // "image": "jzsz/c-test:0.1", + // "workspaceFolder": "/app/project" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index ce1c3d3..f68f6ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -hello -hello.o \ No newline at end of file +.side diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..23a0ee3 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,51 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build", + "type": "shell", + "command": "gcc", + "args": [ + "-g", + "./src/source.c", + "-o", + "./target" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Check", + "type": "shell", + "command": "clang", + "args": [ + "--analyze", + "./target" + ], + "dependsOn": [ + "Build" + ], + "group": { + "kind": "test", + "isDefault": true + } + }, + { + "label": "Run", + "type": "shell", + "command": "./target", + "args": [ + + ], + "dependsOn": [ + "Build" + ], + "group": { + "kind": "test", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index 54f1940..7daad6b 100644 --- a/Makefile +++ b/Makefile @@ -9,14 +9,18 @@ CC = gcc RM = rm RM_FLAGS = -f -TARGET = hello -OBJS = hello.o +TARGET = target +SRCDIR = src -all: $(OBJS) - $(CC) $(CC_OUTPUT_FLAGS) $(TARGET) $(OBJS) +OBJS = $(SRCDIR)/source.o -.c.o: - $(CC) $(CC_FLAGS) $< +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) $(CC_OUTPUT_FLAGS) $@ $^ $(CC_PTHREAD_FLAGS) + +$(SRCDIR)/%.o: $(SRCDIR)/%.c + $(CC) $(CC_FLAGS) $< $(CC_OUTPUT_FLAGS) $@ clean: - $(RM) $(RM_FLAGS) $(OBJS) $(TARGET) *.bak \ No newline at end of file + $(RM) $(RM_FLAGS) $(OBJS) $(TARGET) *.bak \ No newline at end of file diff --git a/README.md b/README.md index 93eda2a..ec128cf 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # DevContainerExample -#### 介绍 +## 介绍 -DevContainerExample 是一个基于Dockerfile定义开发环境容器的hello world范例项目。 +DevContainerExample 是一个可供SuperIDE使用的C语言开发环境容器的范例项目。 [直接指定容器镜像作为开发环境的hello world范例项目](https://gitee.com/SuperIDE/DevContainerExample/releases/tag/v1.0) -#### 使用说明 +[基于Dockerfile定义开发环境容器的hello world范例项目](https://gitee.com/SuperIDE/DevContainerExample/releases/tag/v2.0) + +## 使用说明 1. 安装Docker,https://www.docker.com/products/docker-desktop/ 2. 安装Git, https://git-scm.com/download @@ -24,9 +26,40 @@ make make clean ``` -#### 自定义开发环境 +也可使用vscode定义的task执行既定任务(任务定义在`.vscode/tasks.json`中): + +- 快捷键`Ctrl + Shift + P`打开命令面板输入`task` +- 在列出的命令中选择想要执行的命令 + +## 容器相关设置 + +### 指定容器镜像 + +`.devcontainer/devcontainer.json` 中的`image`可以指定开发环境容器镜像 + +```json +{ + "name": "My Dev Container", + "image": "ContainerImageName", + // 其他设置 +} +``` + +### 自定义开发环境 -修改.devcontainer/Dockerfile 可以自定义开发环境 +定义`.devcontainer/devcontainer.json` 中`build`中的`dockerfile`可以指定构建容器镜像的Dockerfile + +```json +{ + "name": "My Dev Container", + "build":{ + "dockerfile": "Dockerfile" + } + //其他设置 +} +``` + +修改`.devcontainer/Dockerfile` 可以自定义开发环境 ``` FROM mcr.microsoft.com/devcontainers/base:alpine-3.19 @@ -34,6 +67,32 @@ FROM mcr.microsoft.com/devcontainers/base:alpine-3.19 RUN apk add gdb ``` +## SuperIDE容器镜像标准 + +### 开发环境容器镜像目录 + +- /app + + - config.json 配置说明文件,toolchain根据内容获取示例项目、工作挂载目录等信息 + + ```json + { + "work_directory":"/app/project", + "example_directory": "/app/ExampleProject", + "tasks_file": "/app/project/.vscode/tasks.json", + } + ``` + + - project 工作时项目目录的挂载文件夹,也是容器默认工作目录 + + - ExampleProject 示例项目目录,初始化空文件夹时从该目录拷贝初始化项目 + +### 项目工作目录结构 + +- .vsocde + - tasks.json 保存工具链执行命令,toolchain根据这些命令执行对应操作 +- SuperIDE.ini 项目配置文件 +- 其余文件夹 ## License diff --git a/SuperIDE.ini b/SuperIDE.ini new file mode 100644 index 0000000..1c55f7a --- /dev/null +++ b/SuperIDE.ini @@ -0,0 +1,11 @@ +; superide Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.superide.org/page/projectconf.html +[env:testdemo] +env_image = jzsz/c-test:0.1 \ No newline at end of file diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..e1680c6 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +superide will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.superide.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +superide Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about superide Library Dependency Finder +- https://docs.superide.org/page/librarymanager/ldf.html diff --git a/hello.c b/src/source.c similarity index 43% rename from hello.c rename to src/source.c index c4e6237..d841e2d 100644 --- a/hello.c +++ b/src/source.c @@ -2,5 +2,6 @@ int main() { - printf("hello world!\n"); + printf("Hello World!\n"); + return 0; } \ No newline at end of file -- Gitee