tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
84.5k stars 2.54k forks source link

[bug] Sidecars - What am i doing wrong? #8170

Closed kacesensitive closed 1 year ago

kacesensitive commented 1 year ago

Describe the bug

So i have a tauri app which needs to run a sidecar application. Here is my tauri config

  "$schema": "../node_modules/@tauri-apps/cli/schema.json",
  "build": {
    "beforeBuildCommand": "npm run build",
    "beforeDevCommand": "npm run dev",
    "devPath": "http://localhost:3000",
    "distDir": "../out",
    "withGlobalTauri": true
  },
  "package": {
    "productName": "prochat-app-v2",
    "version": "2.7.2"
  },
  "tauri": {
    "macOSPrivateApi": true,
    "allowlist": {
      "shell": {
        "open": true,
        "sidecar": true
      },
      "clipboard": {
        "all": true,
        "writeText": true,
        "readText": true
      },
      "os": {
        "all": true
      },
      "all": false
    },
    "systemTray": {
      "iconPath": "icons/icon.png",
      "iconAsTemplate": true
    },
    "bundle": {
      "active": true,
      "category": "DeveloperTool",
      "copyright": "",
      "deb": {
        "depends": []
      },
      "externalBin": [
        "bin/chatserver-macos"
      ],
      "icon": [
        "icons/32x32.png",
        "icons/128x128.png",
        "icons/128x128@2x.png",
        "icons/icon.icns",
        "icons/icon.ico"
      ],
      "identifier": "com.kacey.dev",
      "longDescription": "",
      "macOS": {
        "entitlements": null,
        "exceptionDomain": "",
        "frameworks": [],
        "providerShortName": null,
        "signingIdentity": null
      },
      "resources": [],
      "shortDescription": "",
      "targets": "all",
      "windows": {
        "certificateThumbprint": null,
        "digestAlgorithm": "sha256",
        "timestampUrl": ""
      }
    },
    "security": {
      "csp": ""
    },
    "updater": {
      "active": false
    },
    "windows": [
      {
        "title": "ProChat",
        "label": "prochat-app-v2",
        "width": 800,
        "height": 600,
        "resizable": true,
        "fullscreen": false,
        "transparent": false,
        "url": "/"
      },
      {
        "title": "ProChat Engineer",
        "label": "prochat-app-v2-secondary",
        "width": 800,
        "height": 600,
        "resizable": true,
        "fullscreen": false,
        "transparent": false,
        "url": "/engineer"
      }
    ]
  }
}

And here is the folder structure in the image

When running the binary with the following

const startChatServer = async () => {
        const platform = await os.platform(); // 'darwin', 'linux', or 'win32'
        let binaryName = '';

        if (platform === 'win32') {
            binaryName = 'chatserver-win.exe';
        } else if (platform === 'darwin') {
            binaryName = 'chatserver-macos-aarch64-apple-darwin';
        } else if (platform === 'linux') {
            binaryName = 'chatserver-linux';
        }

        const command = Command.sidecar(`bin/${binaryName}`);
        try {
            const output = await command.execute();
            console.log('Chat server started:', output);
        } catch (error) {
            console.error('Failed to start chat server:', error);
        }
    };

I am getting

[Error] Failed to start chat server: – "sidecar not configured under `tauri.conf.json > tauri > bundle > externalBin`: bin/chatserver-macos-aarch64-apple-darwin"
    (anonymous function) (app-index.js:33)
    (anonymous function) (hydration-error-info.js:41)
    (anonymous function) (Control.tsx:60)```

Fine... then i'll add bin/chatserver-macos-aarch64-apple-darwin to the config But then my buiild fails with

Caused by:
  process didn't exit successfully: /Users/kc/Desktop/Code/prochat-app-v2/src-tauri/target/debug/build/app-62d9b38b50c54525/build-script-build (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=TAURI_CONFIG
  cargo:rerun-if-changed=tauri.conf.json
  cargo:rustc-cfg=desktop
  cargo:rustc-cfg=dev
  path matching bin/chatserver-macos-aarch64-apple-darwin-aarch64-apple-darwin not found.

I'm just confused, any help more than welcome!!

Posted to discord here -> https://discord.com/channels/616186924390023171/1170119995947225108

Reproduction

No response

Expected behavior

No response

Platform and versions

[✔] Environment
    - OS: Mac OS 14.1.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.67.1 (d5a82bbd2 2023-02-07)
    ✔ Cargo: 1.67.1 (8ecd4f20a 2023-01-10)
    ✔ rustup: 1.25.2 (17db695f1 2023-02-01)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 18.17.0
    - pnpm: 8.6.10
    - yarn: 1.22.19
    - npm: 9.8.1

[-] Packages
    - tauri [RUST]: 1.5.2
    - tauri-build [RUST]: 1.5.0
    - wry [RUST]: 0.24.4
    - tao [RUST]: 0.16.5
    - @tauri-apps/api [NPM]: 1.4.0
    - @tauri-apps/cli [NPM]: 1.4.0

[-] App
    - build-type: bundle
    - CSP:
    - distDir: ../out
    - devPath: http://localhost:3000/
    - framework: React (Next.js)
    - bundler: Webpack

Stack trace

No response

Additional context

No response

FabianLars commented 1 year ago

at first glance your initial approach was almost correct, you just had to change binaryName = 'chatserver-macos-aarch64-apple-darwin'; to binaryName = 'chatserver-macos'; -> The actual binary on the filesystem still needs that prefix.

Btw the idea here is that you don't need this manual binaryName handling. Just use bin/chatserver in externalBin and in your js code and name your actual binaries chatserver-${target-triplet} and tauri will care about loading the correct one.

kacesensitive commented 1 year ago

Heck yeah. Thanks a ton! @FabianLars