Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

os.execShellCmd won't compile on IOS #24732

Open
alexjba opened this issue Feb 27, 2025 · 5 comments
Open

os.execShellCmd won't compile on IOS #24732

alexjba opened this issue Feb 27, 2025 · 5 comments
Assignees
Labels
OS/Architecture Specific OS (stdlib) Related to OS modules in standard library

Comments

@alexjba
Copy link

alexjba commented Feb 27, 2025

Description

It can be reproduced when compiling this code using the IOS SDK.

import browsers

openDefaultBrowser("https://github.com/nim-lang/Nim/issues")
    nim c --noMain:on --app:staticlib -d:ios --os:ios

The issue I have here is that openDefaultBrowser will eventually call system imported from stdlib.h. This symbol has been deprecated on IOS and will fail with Use posix_spawn APIs or NSTask instead. (On iOS, process spawning is unavailable.)

Nim/lib/pure/os.nim

Lines 210 to 211 in a18dcca

proc c_system(cmd: cstring): cint {.
importc: "system", header: "<stdlib.h>".}

Nim Version

Nim Compiler Version 2.0.12 [MacOSX: arm64]
Compiled at 2025-02-26
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: ce7c6f4

Current Output

Build fails with:

Use posix_spawn APIs or NSTask instead. (On iOS, process spawning is unavailable.)

Expected Output


Build succeeded.
The default browser is opened when the code runs.

Known Workarounds

No response

Additional Information

No response

@metagn metagn added OS/Architecture Specific OS (stdlib) Related to OS modules in standard library labels Feb 27, 2025
@ringabout ringabout self-assigned this Feb 27, 2025
@ringabout
Copy link
Member

Hello, do you happen to have some tips/workflows to test the program on macOS. I spent hours in vain to try to learn swift and xcode.

@alexjba
Copy link
Author

alexjba commented Feb 27, 2025

Hello, do you happen to have some tips/workflows to test the program on macOS. I spent hours in vain to try to learn swift and xcode.

I'm using QT for the nim library wrapper. It will generate the Xcode project for you. No swift or Xcode necessary. I just hope the steps below to work out of the box for you.

Installing QT

pip3 install -U pip
pip3 install aqtinstall
aqt install-qt mac ios 5.15.2 -O ~/Qt
### OR if it fails for arm64
arch -x86_64 aqt install-qt mac ios 5.15.2 -O ~/Qt

export QTDIR=~/Qt/5.15.2/ios
export PATH=${QTDIR}/bin:$PATH

Creating a new project

# Browser.pro file
TEMPLATE = app

SOURCES += main.cpp
LIBS += -l<nim library>
// main.cpp
#include <stdlib.h>
#include <unistd.h>

extern "C" {
    void NimMain();
}

int main(int argc, char* argv[])
{
    NimMain();
    return 0;
}

Building and running

mkdir build
cd build
# Generate the Xcode project
qmake ../browser.pro -spec macx-ios-clang CONFIG+=debug CONFIG+=iphonesimulator

# Build the project
xcodebuild -configuration Release -target "Qt Preprocess" -sdk iphonesimulator -arch x86_64
xcodebuild -configuration Release -target "Browser" install -sdk iphonesimulator -arch x86_64

# Find a simulator device. Copy the device id. (Should be installed by xcode)
xcrun simctl list devices

export SIMULATOR_DEVICE_ID=<your device id from the list above>
# Boot the device
xcrun simctl boot $SIMULATOR_DEVICE_ID
# Open the simulator 
open -a Simulator --args -CurrentDeviceUDID $SIMULATOR_DEVICE_ID
# Install the app
xcrun simctl install $SIMULATOR_DEVICE_ID <path to .app file built above>

@Araq
Copy link
Member

Araq commented Feb 27, 2025

So is this even fixable if iOS doesn't support process creation?

@alexjba
Copy link
Author

alexjba commented Feb 27, 2025

My understanding is that system should be replaceable with posix_spawn. And the posix_spawn seems to be available on IOS

int     posix_spawn(pid_t * __restrict, const char * __restrict,
    const posix_spawn_file_actions_t *,
    const posix_spawnattr_t * __restrict,
    char *const __argv[__restrict],
    char *const __envp[__restrict]) __API_AVAILABLE(macos(10.5), ios(2.0)) __API_UNAVAILABLE(watchos, tvos);

@Araq
Copy link
Member

Araq commented Feb 27, 2025

Ok. typical Apple nonsense as I can implement system via posix_spawn+waitpid...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
OS/Architecture Specific OS (stdlib) Related to OS modules in standard library
Projects
None yet
Development

No branches or pull requests

4 participants