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

feat(install): support msvc #26

Merged
merged 6 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,18 @@ Melon is a generic cross-platform C library. It contains many algorithms, data s

### Platform Support

Melon was originally written for UNIX systems, so it is suitable for UNIX-like systems such as Linux and MacOS. And there are a few optimizations for Intel CPUs.
- Linux

At present, Melon has also completed the preliminary porting to Windows, so it can be used on Windows. However, because Windows differs greatly from the UNIX system in the creation process, some functions of the above `framework` are temporarily not supported in Windows.
- MacOSX

- Windows
- `msys2` (Fully supported)
- `msvc` (Partially supported)


### Installation

On Windows, please install `mingw` or `msys2`.

If you install `mingw`, you may want to install `git bash` and `make` either. Install [MingW-W64-builds](https://www.mingw-w64.org/downloads/#mingw-builds) with the installation settings:

- `Version`: `8.1.0`

- `Architecture`: `i686`

- `Threads`: `posix`

- `Exception`: `dwarf`

- `Build revision`: `0`

If you install `msys2`, you can use `pacman` to install any tool softwares you may need.

Then execute these shell commands on git bash or terminal (on UNIX).
### Quick Installation

```
git clone https://github.com/Water-Melon/Melon.git
Expand All @@ -100,7 +87,7 @@ make
make install
```

For more `configure` options, please refer to [Official Document: Installation](http://doc.melonc.io/en/install.html).
For installation on other operating systems or for more configure options, please refer to [Official Document: Installation](http://doc.melonc.io/en/install.html).



Expand Down
74 changes: 74 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@echo off

set "HOME=%HOMEDRIVE%%HOMEPATH%"

echo Installation Path: [%HOME%/libmelon]
echo Generating files and directories ...

setlocal enabledelayedexpansion

set "old=MLN_ROOT"
set "new=!%HOME%!\libmelon"
set "new=%new:\=\\%"

set "file=src/mln_path.c"

powershell -Command "(Get-Content '%file%') -replace '%old%', '\"%new%\"' | Set-Content '%file%'"


set "old=MLN_NULL"
set "new=!%HOME%!\libmelon\null"
set "new=%new:\=\\%"

set "file=src/mln_path.c"

powershell -Command "(Get-Content '%file%') -replace '%old%', '\"%new%\"' | Set-Content '%file%'"


set "old=MLN_LANG_LIB"
set "new=!%HOME%!\libmelon\lang\lib"
set "new=%new:\=\\%"

set "file=src/mln_path.c"

powershell -Command "(Get-Content '%file%') -replace '%old%', '\"%new%\"' | Set-Content '%file%'"


set "old=MLN_LANG_DYLIB"
set "new=!%HOME%!\libmelon\lang\dylib"
set "new=%new:\=\\%"

set "file=src/mln_path.c"

powershell -Command "(Get-Content '%file%') -replace '%old%', '\"%new%\"' | Set-Content '%file%'"


set "old={{ROOT}}"
set "new=!%HOME%!\libmelon"
set "new=%new:\=\\%"

set "file=conf/melon.conf.msvc.template"

powershell -Command "(Get-Content '%file%') -replace '%old%', '%new%' | Set-Content 'conf/melon.conf'"

endlocal


mkdir lib objs\src "%HOME%\libmelon\logs" "%HOME%\libmelon\lang\lib" "%HOME%\libmelon\lang\dylib" "%HOME%\libmelon\include" "%HOME%\libmelon\conf" "%HOME%\libmelon\lib" "%HOME%\libmelon\tmp"
echo "" > "%HOME%\libmelon\null"

for %%f in (src\*.c) do (
cl /c /DMSVC /I include "%%f" /Fo:objs\%%f.o /O2
)

lib /OUT:lib\libmelon_static.lib objs\src\*.o

setlocal

xcopy include "%HOME%/libmelon/include" /E /I /Y
xcopy lib "%HOME%/libmelon/lib" /E /I /Y
xcopy conf "%HOME%/libmelon/conf" /E /I /Y

endlocal

echo Done
35 changes: 35 additions & 0 deletions conf/melon.conf.msvc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
log_level "none";
//user "root";
daemon off;
core_file_size "unlimited";
//max_nofile 1024;
worker_proc 1;
framework off;
log_path "{{ROOT}}\\logs\\melon.log";
/*
* Configurations in the 'proc_exec' are the
* processes which are customized by user.
*
* Here is an example to show you how to
* spawn a program.
* keepalive "/tmp/a.out" ["arg1" "arg2" ...]
* The command in this example is 'keepalive' that
* indicate master process to supervise this
* process. If process is killed, master process
* would restart this program.
* If you don't want master to restart it, you can
* default "/tmp/a.out" ["arg1" "arg2" ...]
*
* But you should know that there is another
* arugment after the last argument you write here.
* That is the file descriptor which is used to
* communicate with master process.
*/
proc_exec {
// keepalive "/tmp/a";
}
thread_exec {
// restart "hello" "hello" "world";
// default "haha";
}
//trace_mode "trace/trace.m"; /* path or off */
6 changes: 5 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ mingw_cflags=""
# constructor
constructor_flag=""

# msys2
msys2_flag=""

#Functions
set_melang_default_paths() {
if ! case $sysname in MINGW*) false;; esac; then
Expand All @@ -80,6 +83,7 @@ set_c_compilers() {
install_path=$HOME/libmelon
cc="gcc"
tcc="gcc"
msys2_flag="-DMSYS2"
else
install_path=`echo "/usr/local/melon"`
cc="cc"
Expand Down Expand Up @@ -400,7 +404,7 @@ generate_Makefile() {
if [ $wasm -eq 1 ]; then
echo -e "FLAGS\t\t= -Iinclude -c $debug $olevel $llvm_flag -s -mmutable-globals -mnontrapping-fptoint -msign-ext -Wemcc -DMLN_ROOT=\\\"$realpath\\\" -DMLN_NULL=\\\"$nullpath\\\" -DMLN_LANG_LIB=\\\"$melang_script_path\\\" -DMLN_LANG_DYLIB=\\\"$melang_dylib_path\\\" $CFLAGS" >> Makefile
else
echo -e "FLAGS\t\t= -Iinclude -c -Wall $debug -Werror $mingw_cflags $olevel -fPIC -DMLN_ROOT=\\\"$realpath\\\" -DMLN_NULL=\\\"$nullpath\\\" -DMLN_LANG_LIB=\\\"$melang_script_path\\\" -DMLN_LANG_DYLIB=\\\"$melang_dylib_path\\\" $event_flag $sendfile_flag $writev_flag $unix98_flag $mmap_flag $func_flag $c99_flag $constructor_flag $CFLAGS" >> Makefile
echo -e "FLAGS\t\t= -Iinclude -c -Wall $debug -Werror $mingw_cflags $olevel -fPIC -DMLN_ROOT=\\\"$realpath\\\" -DMLN_NULL=\\\"$nullpath\\\" -DMLN_LANG_LIB=\\\"$melang_script_path\\\" -DMLN_LANG_DYLIB=\\\"$melang_dylib_path\\\" $event_flag $sendfile_flag $writev_flag $unix98_flag $mmap_flag $func_flag $c99_flag $constructor_flag $msys2_flag $CFLAGS" >> Makefile
fi
if ! case $sysname in MINGW*) false;; esac; then
if [ $wasm -eq 0 ]; then
Expand Down
4 changes: 2 additions & 2 deletions docs/Melon Developer Guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3430,7 +3430,7 @@ Their definitions can be found in melon/include/mln_types.h.
return -1;
}
memset(&msg, 0, sizeof(msg));
#if defined(____WIN32____)
#if defined(MSVC)
int n = recv(fd, (char *)&msg, sizeof(msg), 0);
#else
int n = recv(fd, &msg, sizeof(msg), 0);
Expand Down Expand Up @@ -3464,7 +3464,7 @@ Their definitions can be found in melon/include/mln_types.h.
msg.c = 'N';
msg.type = ITC_REQUEST;
msg.need_clear = 1;
#if defined(____WIN32____)
#if defined(MSVC)
int n = send(fd, (char *)&msg, sizeof(msg), 0);
#else
int n = send(fd, &msg, sizeof(msg), 0);
Expand Down
6 changes: 0 additions & 6 deletions docs/book/cn/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@



### 视频介绍

<iframe src="//player.bilibili.com/player.html?bvid=BV1Tz4y1F7vr&page=1&autoplay=0" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height="480px" width="100%"> </iframe>



### 头文件

```c
Expand Down
4 changes: 3 additions & 1 deletion docs/book/cn/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

类模板用于提供一种类似面向对象编程的编程体验。模块提供了若干宏来实现面向对象的编程风格。

本模块在MSVC环境中暂不支持。



### 头文件
Expand Down Expand Up @@ -104,4 +106,4 @@ int main(void)
}
```

注意,这里函数指针、构造函数和析构函数的声明必须放在宏`class`前。而所有函数定义必须放在`class`之后。
注意,这里函数指针、构造函数和析构函数的声明必须放在宏`class`前。而所有函数定义必须放在`class`之后。
5 changes: 0 additions & 5 deletions docs/book/cn/conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@



### 视频介绍

<iframe src="//player.bilibili.com/player.html?bvid=BV1ih4y1B7Fi&page=1&autoplay=0" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height="480px" width="100%"> </iframe>



### 说明
这里仅给出开发者所需要的结构定义和函数声明。
Expand Down
5 changes: 0 additions & 5 deletions docs/book/cn/cron.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@



### 视频介绍

<iframe src="//player.bilibili.com/player.html?bvid=BV1Ju4y1d7Zg&page=1&autoplay=0" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height="480px" width="100%"> </iframe>



### 头文件

Expand Down
7 changes: 1 addition & 6 deletions docs/book/cn/error.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@



### 视频讲解

<iframe src="//player.bilibili.com/player.html?bvid=BV148411R7Xt&page=1&autoplay=0" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height="480px" width="100%"> </iframe>



### 头文件

Expand Down Expand Up @@ -63,7 +58,7 @@ RET(code)

描述:根据给定的错误码`code`生成返回值。如果`code`为0,则表示无错。若`code`小于0则是不合法的错误值。若`code`大于0,则表示一个合法错误码。如果再此之前使用了`mln_error_callback_set`设置了回调函数,那么在返回值拼装完成后,回调函数会被调用。

返回值:0或一个负值,0表示无错误,负值表示出错
返回值:0或一个负值,0表示无错误,负值表示出错。`msvc`环境下,返回值将直接赋值给参数`code`,而不是像函数一样返回。



Expand Down
7 changes: 1 addition & 6 deletions docs/book/cn/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
- kqueue
- select



### 视频介绍

<iframe src="//player.bilibili.com/player.html?bvid=BV1q94y1p7cn&page=1&autoplay=0" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" height="480px" width="100%"> </iframe>

`msvc`环境中,本模块不是线程安全的。


### 头文件
Expand Down
2 changes: 1 addition & 1 deletion docs/book/cn/fheap.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Melon中实现的是**最小堆**。
与红黑树组件类似,斐波那契堆组件有三种用法:

- 基本用法
- 内联用法
- 内联用法 (`msvc`中不支持)
- 容器用法


Expand Down
4 changes: 4 additions & 0 deletions docs/book/cn/framework_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

`master_process`/`worker_process`是在多进程模型下,在主/工作进程中被调用的,用于针对单个进程进行一些全局设置。

`msvc`中,不包含`main_thread`,`master_process`和`worker_process`。初始化流程仅对配置和日志等初始化后返回。



### 头文件
Expand All @@ -55,9 +57,11 @@ struct mln_framework_attr {
int argc; //一般为main的argc
char **argv; //一般为main的argv
mln_framework_init_t global_init; //初始化回调函数,一般用于初始化全局变量,该回调会在配置加载完成后被调用
#if !defined(MSVC)
mln_framework_process_t main_thread; //主线程处理函数,我们将在多线程框架部分深入
mln_framework_process_t master_process; //主进程处理函数,我们将在多进程框架部分深入
mln_framework_process_t worker_process; //工作进程处理函数,我们将在多进程框架部分深入
#endif
};

typedef int (*mln_framework_init_t)(void);
Expand Down
20 changes: 18 additions & 2 deletions docs/book/cn/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,25 @@ Melon当前提供了如下功能:

### 平台支持

Melon最初是为UNIX系统编写,因此适用于Linux、MacOS等类UNIX系统,并在针对Intel CPU有少量优化。
- Linux

目前Melon也已经完成了向Windows的初步移植,因此可以在Windows上进行使用。但由于Windows在创建进程上与UNIX系统差异较大,因此导致上述`框架`部分功能在Windows中暂时不支持。
- MacOSX

- Windows
- `msys2` (完全支持)
- `msvc` (部分支持,详情参考下一小节的安装文档)


### 快速安装
```
git clone https://github.com/Water-Melon/Melon.git
cd Melon
./configure [--prefix=LIB_INSTALL_PATH | ...]
make
make install
```

关于如何在其他平台安装以及configure的更多选项,请参考[安装](http://doc.melonc.io/cn/install.html)章节内容。



Expand Down
Loading
Loading