> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> دليل لبناء ClickHouse من المصدر لمعمارية s390x

# البناء على Linux لـ s390x ‏(zLinux)

يدعم ClickHouse معمارية s390x بشكل تجريبي.

<div id="building-clickhouse-for-s390x">
  ## بناء ClickHouse لـ s390x
</div>

على منصة s390x، كما في المنصات الأخرى، يُبنى OpenSSL كمكتبة ثابتة. وإذا أردت البناء باستخدام OpenSSL الديناميكي، فعليك تمرير `-DENABLE_OPENSSL_DYNAMIC=1` إلى CMake.

تفترض هذه التعليمات أن الجهاز المضيف يعمل بنظام Linux x86\_64/ARM وأن جميع الأدوات اللازمة للبناء الأصلي متوفرة فيه، وذلك استنادًا إلى [تعليمات البناء](/docs/ar/resources/develop-contribute/build/build). كما تفترض أيضًا أن النظام المضيف هو Ubuntu 22.04، لكن ينبغي أن تعمل التعليمات التالية أيضًا على Ubuntu 20.04.

بالإضافة إلى تثبيت الأدوات المستخدمة للبناء الأصلي، يجب تثبيت الحزم الإضافية التالية:

```bash theme={null}
apt-get mold
rustup target add s390x-unknown-linux-gnu
```

للبناء لـ s390x:

```bash theme={null}
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/linux/toolchain-s390x.cmake ..
ninja
```

<div id="running">
  ## التشغيل
</div>

لإجراء المحاكاة، ستحتاج إلى الملف التنفيذي الثابت الخاص بـ QEMU user لمعمارية s390x. على Ubuntu، يمكن تثبيته باستخدام:

```bash theme={null}
apt-get install binfmt-support binutils-s390x-linux-gnu qemu-user-static
```

بعد اكتمال البناء، يمكن تشغيل الملف التنفيذي، على سبيل المثال، باستخدام:

```bash theme={null}
qemu-s390x-static -L /usr/s390x-linux-gnu ./programs/clickhouse local --query "Select 2"
2
```

<div id="debugging">
  ## تصحيح الأخطاء
</div>

ثبّت LLDB:

```bash theme={null}
apt-get install lldb-21
```

لتنقيح ملف تنفيذي بمعمارية s390x، شغّل ClickHouse باستخدام QEMU في وضع التنقيح:

```bash theme={null}
qemu-s390x-static -g 31338 -L /usr/s390x-linux-gnu ./clickhouse
```

في نافذة طرفية أخرى، شغِّل LLDB ونفِّذ الأمر attach، واستبدل `<Clickhouse Parent Directory>` و`<build directory>` بالقيم المناسبة لبيئتك.

```bash theme={null}
lldb-15
(lldb) target create ./clickhouse
Current executable set to '/<Clickhouse Parent Directory>/ClickHouse/<build directory>/programs/clickhouse' (s390x).
(lldb) settings set target.source-map <build directory> /<Clickhouse Parent Directory>/ClickHouse
(lldb) gdb-remote 31338
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0x0000004020e74cd0
->  0x4020e74cd0: lgr    %r2, %r15
    0x4020e74cd4: aghi   %r15, -160
    0x4020e74cd8: xc     0(8,%r15), 0(%r15)
    0x4020e74cde: brasl  %r14, 275429939040
(lldb) b main
Breakpoint 1: 9 locations.
(lldb) c
Process 1 resuming
Process 1 stopped
* thread #1, stop reason = breakpoint 1.1
    frame #0: 0x0000004005cd9fc0 clickhouse`main(argc_=1, argv_=0x0000004020e594a8) at main.cpp:450:17
   447  #if !defined(FUZZING_MODE)
   448  int main(int argc_, char ** argv_)
   449  {
-> 450      inside_main = true;
   451      SCOPE_EXIT({ inside_main = false; });
   452
   453      /// PHDR cache is required for query profiler to work reliably
```

<div id="visual-studio-code-integration">
  ## تكامل Visual Studio Code
</div>

* إضافة [CodeLLDB](https://github.com/vadimcn/vscode-lldb) مطلوبة لإجراء التنقيح المرئي.
* يمكن أن تساعد إضافة [Command Variable](https://github.com/rioj7/command-variable) في التشغيل الديناميكي عند استخدام [CMake Variants](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/variants.md).
* تأكد من ضبط الواجهة الخلفية على تثبيت LLVM لديك، على سبيل المثال: `"lldb.library": "/usr/lib/x86_64-linux-gnu/liblldb-21.so"`
* تأكد من تشغيل الملف التنفيذي لـ ClickHouse في وضع التنقيح قبل البدء. (ومن الممكن أيضًا إنشاء `preLaunchTask` لأتمتة ذلك)

<div id="example-configurations">
  ### أمثلة على الإعدادات
</div>

<div id="cmake-variantsyaml">
  #### cmake-variants.yaml
</div>

```yaml theme={null}
buildType:
  default: relwithdebinfo
  choices:
    debug:
      short: Debug
      long: Emit debug information
      buildType: Debug
    release:
      short: Release
      long: Optimize generated code
      buildType: Release
    relwithdebinfo:
      short: RelWithDebInfo
      long: Release with Debug Info
      buildType: RelWithDebInfo
    tsan:
      short: MinSizeRel
      long: Minimum Size Release
      buildType: MinSizeRel

toolchain:
  default: default
  description: Select toolchain
  choices:
    default:
      short: x86_64
      long: x86_64
    s390x:
      short: s390x
      long: s390x
      settings:
        CMAKE_TOOLCHAIN_FILE: cmake/linux/toolchain-s390x.cmake
```

<div id="launchjson">
  #### launch.json
</div>

```json theme={null}
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "custom",
            "name": "(lldb) Launch s390x with qemu",
            "targetCreateCommands": ["target create ${command:cmake.launchTargetPath}"],
            "processCreateCommands": ["gdb-remote 2159"],
            "preLaunchTask": "Run ClickHouse"
        }
    ]
}
```

<div id="settingsjson">
  #### settings.json
</div>

سيؤدي هذا أيضًا إلى وضع نواتج البناء المختلفة في مجلدات فرعية منفصلة داخل المجلد `build`.

```json theme={null}
{
    "cmake.buildDirectory": "${workspaceFolder}/build/${buildKitVendor}-${buildKitVersion}-${variant:toolchain}-${variant:buildType}",
    "lldb.library": "/usr/lib/x86_64-linux-gnu/liblldb-21.so"
}
```

<div id="run-debugsh">
  #### run-debug.sh
</div>

```sh theme={null}
#! /bin/sh
echo 'Starting debugger session'
cd $1
qemu-s390x-static -g 2159 -L /usr/s390x-linux-gnu $2 $3 $4
```

<div id="tasksjson">
  #### tasks.json
</div>

يُعرّف مهمة لتشغيل الملف التنفيذي المُجمَّع في وضع `server` داخل مجلد `tmp` إلى جانب الملفات الثنائية، باستخدام الإعدادات الموجودة في `programs/server/config.xml`.

```json theme={null}
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run ClickHouse",
            "type": "shell",
            "isBackground": true,
            "command": "${workspaceFolder}/.vscode/run-debug.sh",
            "args": [
                "${command:cmake.launchTargetDirectory}/tmp",
                "${command:cmake.launchTargetPath}",
                "server",
                "--config-file=${workspaceFolder}/programs/server/config.xml"
            ],
            "problemMatcher": [
                {
                    "pattern": [
                        {
                            "regexp": ".",
                            "file": 1,
                            "location": 2,
                            "message": 3
                        }
                    ],
                    "background": {
                        "activeOnStart": true,
                        "beginsPattern": "^Starting debugger session",
                        "endsPattern": ".*"
                    }
                }
            ]
        }
    ]
}
```
