Skip to content
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
149 changes: 146 additions & 3 deletions docs/en/guide/installation/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Please refer to the [PostgreSQL Installation Guide](./postgres.md) to install an

After installation, create a database user and database for Palpo:

1. Open "SQL Shell (psql)" from the Start Menu, or run `psql` in the terminal.
1. Open "SQL Shell (psql)" from the Start Menu, or run `psql -U postgres` in the terminal.Enter the password configured during installation as prompted. If you encounter an error message like "command not found," please check if the installation path of PostgreSQL is included in the Windows environment variable PATH.
2. Execute the following in the psql shell:

```sql
Expand All @@ -19,12 +19,154 @@ Replace `'your_secure_password'` with a strong password. This creates a PostgreS

## Downloading Palpo Release


### Download officeal release
Visit the official GitHub releases page:

[https://github.com/palpo-im/palpo/releases](https://github.com/palpo-im/palpo/releases)

Download the latest Windows version (e.g., `palpo-x.y.z-windows.zip`) and extract it.

### Install from Source Code

#### Windows Environment

1. Configure the Rust Development Environment

Obtain the Windows installer from the official Rust website: [https://rust-lang.org/tools/install/](https://rust-lang.org/tools/install/)
Double-click the installer and select the **Quick install** option. During installation, you will be prompted to install dependencies such as the Windows SDK. After these tools finish installing, proceed with the Rust toolchain installation using default settings, and wait for components (e.g., `rustc`, `cargo`) to complete installation.Verify the installation success in PowerShell or Command Prompt (CMD) by running the following commands:

```bash
rustc --version
cargo --version
```

If you receive a "command not found" error, configure the `PATH` environment variable in Windows System Settings.

2. Obtain the Palpo Source Code

Visit the official Palpo GitHub repository: [https://github.com/palpo-im/palpo](https://github.com/palpo-im/palpo)
- If Git is installed: Use the `git clone` command to fetch the source code.
- If you prefer not to use Git: Directly download the source code package by selecting **Download ZIP** on the GitHub repository page.


3. Compile the Source Code
Before compilation, install CMake first. You have two installation options:
- Download the installer from the official CMake website: [https://cmake.org/download/](https://cmake.org/download/)
- Install via Winget (Windows Package Manager) with this command:

```bash
winget install --id=Kitware.CMake -e
```

**compile Palpo**

1. Navigate to the Palpo source code directory.
2. Open a terminal in this directory and execute the following command. Wait for compilation to finish:

```bash
cargo build --release
```

The Windows executable (`palpo.exe`) will be generated in the `./target/release/` subdirectory of the source code folder. This is a **standalone executable** with no external DLL dependencies—you can copy it to any directory for use.

---

#### Cross-Compilation and Installation on WSL Environment

If you have the Windows Subsystem for Linux (WSL) configured on your Windows machine, you can cross-compile Palpo to generate a Windows binary directly in WSL. This avoids configuring the Rust toolchain on Windows natively and simplifies multi-platform build workflows, though additional pre-configuration is required.

1. Configure the Cross-Compilation Toolchain
Add the Windows target to the Rust toolchain in WSL and install the MinGW64 cross-compiler (commands vary by Linux distribution):

```bash
# Add Windows target for Rust
rustup target add x86_64-pc-windows-gnu

# For Arch Linux
sudo pacman -S mingw-w64-gcc
# For Ubuntu/Debian
sudo apt-get update && sudo apt-get install gcc-mingw-w64-x86-64
# For Fedora/RHEL
sudo dnf install mingw64-gcc
```

2. Compile Dependent PostgreSQL Libraries

The official PostgreSQL binaries are built with the Visual Studio (VS) toolchain, but cross-compilation in WSL uses MinGW64. You must manually compile the required PostgreSQL libraries (not the full PostgreSQL software) to complete cross-compilation:
a. Download the PostgreSQL source code: [https://www.postgresql.org/ftp/source/](https://www.postgresql.org/ftp/source/)
b. Extract the source code package and navigate to the PostgreSQL root directory.
c. Configure compilation parameters (exclude unnecessary libraries):

```bash
./configure --host=x86_64-w64-mingw32 \
--without-readline \
--without-zlib \
--without-icu \
--without-openssl
```

d. Compile only the required libraries:

```bash
make -C src/port
make -C src/common
make -C src/interfaces/libpq
```

e. After compilation, locate the MinGW-compiled static libraries (`.a` files) at these paths:
* `src/interfaces/libpq/libpq.a`
* `src/common/libpgcommon.a`
* `src/port/libpgport.a`
f. Copy these `.a` files to a dedicated directory (we use `postgresql/lib-mingw32` in this guide for consistency).

3. Configure Cross-Compilation for Palpo

In the Palpo source code directory, create a `.cargo/config.toml` file with the following content to specify cross-compilation settings:

```toml
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-gcc-ar"

rustflags = [
"-L", "postgresql/lib-mingw32", # Path to compiled PostgreSQL libraries
"-C", "link-args=-lpthread",
"-C", "link-args=-lwinpthread",
]
```

4. Run Cross-Compilation

Execute the following command and wait for compilation to complete:

```bash
cargo build --release --target x86_64-pc-windows-gnu
```

The Windows binary will be generated in the `target/x86_64-pc-windows-gnu/release/` directory. Copy it to a Windows directory to run.

---

**Notes on Running Cross-Compiled Binaries**

Cross-compiled binaries use **dynamic linking** by default. Double-clicking the generated `.exe` file on Windows will trigger this error (or no valid output in the terminal):

```bash
The procedure entry point nanosleep64 could not be located in the dynamic link library D:\palpo\palpo-mingw.exe
```

This occurs because Palpo requires the MinGW dynamic library `libwinpthread-1.dll` to run.

1. Locate `libwinpthread-1.dll` in WSL (path may vary by distribution):

```bash
/usr/x86_64-w64-mingw32/bin/libwinpthread-1.dll
```

2. Copy this DLL file to the **same directory** as `palpo-mingw.exe` on Windows, then proceed with Palpo configuration.


## Configuring Palpo

Copy the example configuration file and rename it:
Expand All @@ -45,10 +187,11 @@ Edit `palpo.toml` according to your environment and database settings. At minimu

```toml
[db]
url = "postgresql://palpo:your_secure_password@localhost:5432/palpo"
url = "postgresql://palpo:your_secure_password@your.domain.com:5432/palpo"
```

Replace `your.domain.com` and `your_secure_password` with your actual domain and password.
Use `localhost` as the domain name for local testing.

For more advanced configuration, please refer to the [Configuration Page](../configuration/index.md).

Expand Down Expand Up @@ -93,4 +236,4 @@ sc create Palpo binPath= "C:\\path\\to\\palpo.exe" start= auto
Replace `C:\\path\\to\\palpo.exe` with the actual path to the Palpo executable.

Palpo will now start automatically on boot.
{/* 本行由工具自动生成,原文哈希值:8d6bf9b2dacdf6172cb54f60a30db81d */}
{/* 本行由工具自动生成,原文哈希值:8d6bf9b2dacdf6172cb54f60a30db81d */}
144 changes: 141 additions & 3 deletions docs/zh-hans/guide/installation/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

安装完成后,为 Palpo 创建数据库用户和数据库:

1. 从开始菜单打开 "SQL Shell (psql)",或在终端运行 `psql`
1. 从开始菜单打开 "SQL Shell (psql)",或在终端运行 `psql -U postgres`。按照提示输入安装过程中配置的密码。如果遇到"命令无法找到"类似的报错提示,请查询Windows的环境变量PATH中是否包括了PostgreSQL的安装路径
2. 在 psql shell 中执行:

```sql
Expand All @@ -17,14 +17,152 @@

将 `'your_secure_password'` 替换为强密码。这会创建名为 `palpo` 的 PostgreSQL 用户和数据库,并将该用户设为数据库所有者。

## 下载 Palpo 发行版
## 安装 Palpo

### 下载官方发行版

访问官方 GitHub 发布页面:

[https://github.com/palpo-im/palpo/releases](https://github.com/palpo-im/palpo/releases)

下载最新的 Windows 版本(如 `palpo-x.y.z-windows.zip`),并解压缩。

### 源码安装

#### Windows 环境

1. 配置 Rust 开发环境

从 Rust 官方网站获取 Windows 安装程序:https://rust-lang.org/tools/install/
双击安装程序,选择**Quick Install**选项。安装过程中,系统会提示安装 Windows SDK 等依赖项。待这些工具安装完成后,使用默认设置继续安装 Rust 工具链,等待 `rustc`、`cargo` 等组件安装完毕。

在 PowerShell 或命令提示符(CMD)中执行以下命令,验证安装是否成功:
```bash
rustc --version
cargo --version
```

若出现“命令未找到”错误,请在 Windows 系统设置中配置 PATH 环境变量。

2. 获取 Palpo 源代码

访问 Palpo 官方 GitHub 代码仓库:https://github.com/palpo-im/palpo

- 若已安装 Git:使用 `git clone` 命令拉取源代码。
- 若不想使用 Git:直接在 GitHub 仓库页面选择**Download ZIP**,获取源代码压缩包。

3. 编译源代码

编译前,需先安装 CMake,有以下两种安装方式:

- 从 CMake 官方网站下载安装程序:https://cmake.org/download/
- 通过 Winget(Windows 包管理器)执行以下命令安装:

```bash
winget install --id=Kitware.CMake -e
```

**编译 Palpo 步骤**:

a. 进入 Palpo 源代码目录。
b. 在该目录下打开终端,执行以下命令,等待编译完成:

```bash
cargo build --release
```
编译完成后,Windows 可执行文件 `palpo.exe` 会生成在源代码文件夹的 `./target/release/` 子目录下。该文件为独立可执行程序,不依赖外部 DLL 文件,可复制到任意目录运行。

---

#### WSL 环境下交叉编译与安装

若你的 Windows 设备已配置适用于 Linux 的 Windows 子系统(WSL),可直接在 WSL 中交叉编译 Palpo 生成 Windows 二进制文件。这种方式无需在原生 Windows 系统配置 Rust 工具链,能简化多平台编译流程,但需进行额外的前置配置。

1. 配置交叉编译工具链

在 WSL 的 Rust 工具链中添加 Windows 目标平台,并安装 MinGW64 交叉编译器(命令因 Linux 发行版而异):

```bash
# 为 Rust 添加 Windows 目标平台
rustup target add x86_64-pc-windows-gnu

# Arch Linux 系统
sudo pacman -S mingw-w64-gcc
# Ubuntu/Debian 系统
sudo apt-get update && sudo apt-get install gcc-mingw-w64-x86-64
# Fedora/RHEL 系统
sudo dnf install mingw64-gcc
```

2. 编译依赖的 PostgreSQL 库

官方 PostgreSQL 二进制文件基于 Visual Studio(VS)工具链构建,而 WSL 中的交叉编译使用 MinGW64 工具链。因此,你需要手动编译所需的 PostgreSQL 库(无需编译完整的 PostgreSQL 软件),才能完成交叉编译:

a. 下载 PostgreSQL 源代码:https://www.postgresql.org/ftp/source/
b. 解压源代码压缩包,进入 PostgreSQL 根目录。
c. 配置编译参数(排除不必要的库):

```bash
./configure --host=x86_64-w64-mingw32 \
--without-readline \
--without-zlib \
--without-icu \
--without-openssl
```
d. 仅编译所需的库文件:

```bash
make -C src/port
make -C src/common
make -C src/interfaces/libpq
```
e. 编译完成后,在以下路径找到 MinGW 编译生成的静态库文件(`.a` 文件):
- `src/interfaces/libpq/libpq.a`
- `src/common/libpgcommon.a`
- `src/port/libpgport.a`
f. 将这些 `.a` 文件复制到一个专用目录(例如`postgresql/lib-mingw32` 目录)。

3. 配置 Palpo 交叉编译环境

在 Palpo 源代码目录中,创建 `.cargo/config.toml` 文件,并写入以下内容,指定交叉编译配置:

```toml
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-gcc-ar"

rustflags = [
"-L", "postgresql/lib-mingw32",
"-C", "link-args=-lpthread",
"-C", "link-args=-lwinpthread",
]
```

4. 执行交叉编译

运行以下命令,等待编译完成:

```bash
cargo build --release --target x86_64-pc-windows-gnu
```
Windows 二进制文件会生成在 `target/x86_64-pc-windows-gnu/release/` 目录下,将其复制到 Windows 系统的任意目录。

---

**交叉编译二进制文件运行注意事项**

交叉编译生成的二进制文件默认采用动态链接方式。在 Windows 系统中双击生成的 `palpo.exe` 文件时,可能会触发以下错误:

> 无法在动态链接库 D:\palpo\palpo-mingw.exe 中定位程序入口点 nanosleep64

出现此问题的原因是,Palpo 运行需要依赖 MinGW 动态库文件 `libwinpthread-1.dll`。

1. 在 WSL 中找到 `libwinpthread-1.dll` 文件(路径因 Linux 发行版而异):
```
/usr/x86_64-w64-mingw32/bin/libwinpthread-1.dll
```
2. 将该 DLL 文件复制到 Windows 系统中 `palpo.exe` 所在的同一目录,随后即可进行 Palpo 的配置与运行。

## 配置 Palpo

复制示例配置文件并重命名:
Expand Down Expand Up @@ -92,4 +230,4 @@ sc create Palpo binPath= "C:\\path\\to\\palpo.exe" start= auto

将 `C:\\path\\to\\palpo.exe` 替换为 Palpo 可执行文件的实际路径。

Palpo 现在会在开机时自动启动。
Palpo 现在会在开机时自动启动。