# iOS Port of Syncthing

**URL:** https://forum.syncthing.net/t/ios-port-of-syncthing/5061
**Category:** Development
**Created:** [July 6, 2015, 2:05am UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061 "2015-07-06T02:05:23Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 2:05am UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/1 "2015-07-06T02:05:23Z")

</div>

I’am working on a iOS Port of Syncthing, i am able now after some weeks to compile go source for iOS arm & arm64, now i can compile go source as a library like a go-output.a file with c header like \_cgo\_export.h and run go code on iOS Devices.

In the next weeks i will puplish the workaround how to do this for go source on iOS.

But now i need a little bit help to compile Syncthing

//THIS IS JUST A BASIC EXAMPLE WHAT I MUST DO For Compile:

```
CGO_ENABLED=1 GOARCH=arm64 GOARM=7 $GO tool cgo -objdir $GG_CGO_OBJ main.go
cp $GG_CGO_OBJ/_cgo_export.h /Users/XXXXXXX/go1.5/ios/src/github.com/syncthing/syncthing

#CGO_ENABLED=1 GOARCH=arm GOARM=7 $GO build -ldflags '-tmpdir ../go-obj -linkmode external'

```

Imports

```
/*
#cgo LDFLAGS: -framework UIKit -framework Foundation -framework CoreGraphics
extern void iosmain(int argc, char *argv[]);
*/
import "C"

func main() {
fmt.Printf("Hello from Saber from Go!\n")
C.iosmain(0, nil)
}

//export WebServer
func WebServer() {
fmt.Println("------------------WebServer--------------")
fmt.Printf("Now lets run the Webserver!\n")
fmt.Println("------------------WebServer--------------")
//Continue with some Code

```

I think the file which i must modify is /github.com/syncthing/syncthing/cmd/syncthing/main.go right?

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 3:21am UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/2 "2015-07-06T03:21:09Z")

</div>

OK, looks better now:

C Header `_cgo_export.h` is now generated with link to iosmain() xcode

Build for arm64 looks also fine, when i run it, it shows be “Bad CPU…”, is a good sign!

Next step:

-ldflags ‘-tmpdir …/go-obj -linkmode external’ this makes troubles because i can use it in the console, i must find the ldflags and adjust it in Syncthing.

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 3:58am UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/3 "2015-07-06T03:58:37Z")

</div>

-ldflags also done by the way.

Hello to Syncthing from Go!!! 2015-07-06 04:50:47.179 SyncthingWebView [804:177827] Hello to Syncthing from Object C!!! 2015-07-06 04:50:48.224 SyncthingWebView[804:177827] -[SyncthingWebViewViewController updateButtons] loading = YES 2015-07-06 04:50:48.301 SyncthingWebView[804:177827] -[SyncthingWebViewViewController updateButtons] loading = NO

Now its time to fix a lot of things for iOS… but i need sleep…

---

<div class="post-metadata">

### Author: ![calmh](https://forum.syncthing.net/user_avatar/forum.syncthing.net/calmh/32/15311_2.png) [@calmh](https://forum.syncthing.net/u/calmh)
#### Post date: [July 6, 2015, 8:48am UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/4 "2015-07-06T08:48:14Z")

</div>

Neat.

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 3:14pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/5 "2015-07-06T15:14:14Z")

</div>

![](https://forum-uploads.syncthingcdn.net/original/2X/3/3796ae9505aa8f1d70b2da6d68878a4ab642d243.png)

i fixed now a lot of stuff puhhh… so compile is done.. and no errors anymore…just some warnings about icons.. nothing important right now.

when i start the iOS App, i get permission denied error, i think this happend because it try to generate the config.xml and the ssh key’s… right?

Where i can find this part to adjust this parts.. on ios i must move all to the Documents folder dynamically, this is the only folder which Apple allows me to create or modify files inside the sandbox.

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 4:07pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/6 "2015-07-06T16:07:30Z")

</div>

monitor.go trys to start a second process which is not allowed in iOS… i have some pain now… haha

---

<div class="post-metadata">

### Author: ![calmh](https://forum.syncthing.net/user_avatar/forum.syncthing.net/calmh/32/15311_2.png) [@calmh](https://forum.syncthing.net/u/calmh)
#### Post date: [July 6, 2015, 4:16pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/7 "2015-07-06T16:16:25Z")

</div>

The monitor process is optional though. Check the code path for `STNORESTART=1`.

---

<div class="post-metadata">

### Author: ![canton7](https://forum.syncthing.net/user_avatar/forum.syncthing.net/canton7/32/9528_2.png) [@canton7](https://forum.syncthing.net/u/canton7)
#### Post date: [July 6, 2015, 4:16pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/8 "2015-07-06T16:16:58Z")

</div>

`-no-restart`

You then become responsible for restarting Syncthing if it exits with an exit code which indicates it wants to be restarted.

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 4:22pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/9 "2015-07-06T16:22:22Z")

</div>

-no-restart at this time is not possible… see monitor.go… because it fails on first start… forc/exec is not allowed, just threads on iOS…

```
            Infoln("Starting syncthing")
		err = cmd.Start()
		if err != nil {
            Infoln("1 Starting failed!!!!!!!!!!!")
            Fatalln(err)
		}
		// Let the next child process know that this is not the first time
		// it's starting up.
		os.Setenv("STRESTART", "yes")
```

---

<div class="post-metadata">

### Author: ![calmh](https://forum.syncthing.net/user_avatar/forum.syncthing.net/calmh/32/15311_2.png) [@calmh](https://forum.syncthing.net/u/calmh)
#### Post date: [July 6, 2015, 4:30pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/10 "2015-07-06T16:30:09Z")

</div>

The monitor process is never involved at all in the STNORESTART path. There is no fork.

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 4:31pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/11 "2015-07-06T16:31:53Z")

</div>

Good to know let me try 🙂

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 4:42pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/12 "2015-07-06T16:42:10Z")

</div>

I would say this is now awesome!!!

Check this out:

Say hello to Syncthing from Go! 2015-07-06 17:40:52.552 IDZWebBrowser[1366:329658] Hello to Syncthing from Object C!!! ------------------WebServer-------------- Now lets run the Webserver! ------------------WebServer-------------- [start] 16:40:52 INFO: Generating RSA key and certificate for syncthing… 2015-07-06 17:40:54.868 IDZWebBrowser[1366:329658] -[IDZWebBrowserViewController updateButtons] loading = YES 2015-07-06 17:40:55.035 IDZWebBrowser[1366:329658] -[IDZWebBrowserViewController updateButtons] loading = NO [K2HOG] 16:41:13 INFO: syncthing unknown-dev (devel +300d9a2 Tue Jun 30 22:56:30 2015 +0000 darwin-arm64 default) unknown@unknown 1970-01-01 00:00:00 UTC [K2HOG] 16:41:13 INFO: My ID: K2HOGDV-2CD2P3N-LYNRWIW-T6XJAKR-HOZOCSY-ZFQT4NX-DH3IYBB-EH7IWAG [K2HOG] 16:41:13 INFO: No config file; starting with empty defaults [K2HOG] 16:41:13 INFO: Edit /private/var/mobile/Containers/Data/Application/8D2A1F26-4DD8-4027-BDC7-CC199DD249F8/Library/Application Support/Syncthing/config.xml to taste or use the GUI [K2HOG] 16:41:13 INFO: Starting deadlock detector with 20m0s timeout [K2HOG] 16:41:13 OK: Ready to synchronize default (read-write) [K2HOG] 16:41:13 INFO: Starting web GUI on [http://127.0.0.1:8384/](http://127.0.0.1:8384/) [K2HOG] 16:41:13 INFO: Loading HTTPS certificate: open /private/var/mobile/Containers/Data/Application/8D2A1F26-4DD8-4027-BDC7-CC199DD249F8/Library/Application Support/Syncthing/https-cert.pem: no such file or directory [K2HOG] 16:41:13 INFO: Creating new HTTPS certificate [K2HOG] 16:41:13 INFO: Generating RSA key and certificate for iPhone-von-Saber-Gilani… [K2HOG] 16:41:13 WARNING: Stopping folder “default” - mkdir /private/var/mobile/Containers/Data/Application/8D2A1F26-4DD8-4027-BDC7-CC199DD249F8/Sync: operation not permitted [K2HOG] 16:41:13 INFO: Skipping folder default scan due to folder error: mkdir /private/var/mobile/Containers/Data/Application/8D2A1F26-4DD8-4027-BDC7-CC199DD249F8/Sync: operation not permitted [K2HOG] 16:41:18 INFO: Starting local discovery announcements [K2HOG] 16:41:18 INFO: Starting global discovery announcements [K2HOG] 16:41:18 INFO: API listening on 127.0.0.1:8384 [K2HOG] 16:41:18 INFO: Device K2HOGDV-2CD2P3N-LYNRWIW-T6XJAKR-HOZOCSY-ZFQT4NX-DH3IYBB-EH7IWAG is “iPhone-von-Saber-Gilani” at [dynamic] [K2HOG] 16:41:18 INFO: No automatic upgrades; unknown-dev is not a release version. [K2HOG] 16:41:31 INFO: New UPnP port mapping: external port 8712 to local port 22000.

---

<div class="post-metadata">

### Author: ![AudriusButkevicius](https://forum.syncthing.net/user_avatar/forum.syncthing.net/audriusbutkevicius/32/277_2.png) [@AudriusButkevicius](https://forum.syncthing.net/u/AudriusButkevicius)
#### Post date: [July 6, 2015, 4:49pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/13 "2015-07-06T16:49:10Z")

</div>

Cool stuff, I guess you’ll have to jump hoops to get around the sandbox and in order to access the filesystem etc?

Did syncthing itself require any modifications? How is it being linked/invoked?

Are you using the iOS toolchain (GOOS=iOS) for Go?

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 4:52pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/14 "2015-07-06T16:52:37Z")

</div>

![](https://forum-uploads.syncthingcdn.net/original/2X/8/8b7985c33db9f20d7a24baef49a76be70c99aaec.PNG)

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 6, 2015, 4:55pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/15 "2015-07-06T16:55:47Z")

</div>

Ohh yes this is now amazing, tonight i will work on the filesystem to get around the sandbox…

Yes i adjusted a some files in syncthing and i use a modified minix goios port the gernerate the .a file.

In the next weeks i will puplish the workaround in my blog and the xcode project.

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 7, 2015, 2:04pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/16 "2015-07-07T14:04:06Z")

</div>

I moved now all config and cert files to the iOS Documents Folder, now i am able to change the config add a new device or folder, because the document folder is write able.

But still i have a problem:

```
[KRYMQ] 13:58:23 INFO: Skipping folder default scan due to folder error: mkdir /private/var/mobile/Containers/Data/Application/CEE251AF-4A07-4890-945A-37EE25BFE81A:

```

I must change this to also to the documents folder like:

```
mkdir /private/var/mobile/Containers/Data/Application/CEE251AF-4A07-4890-945A-37EE25BFE81A/Documents

```

Any ideas where?

 ![](https://forum-uploads.syncthingcdn.net/original/2X/5/5068ae5285da389c702a7f0fa6cb7f00a32b540b.png)

Update: This happend only with the default folder, with a new folder all is fine and sync works

---

<div class="post-metadata">

### Author: ![Alex](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@Alex](https://forum.syncthing.net/u/Alex)
#### Post date: [July 7, 2015, 3:12pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/17 "2015-07-07T15:12:35Z")

</div>

probably the location of the default folder is not writeable because $HOME is not writeable on iOS (wherever it points to)?

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 7, 2015, 3:20pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/18 "2015-07-07T15:20:20Z")

</div>

```
<folder id="default" path="/private/var/mobile/Containers/Data/Application/6B48106D-212D-4634-9641-62ADB1AA55FE/Documents/Sync" ro="false" rescanIntervalS="60" ignorePerms="false" autoNormalize="true">

```

I change the default config.xml automatically when syncthing starts first time… more ideas?

I get all the time:

```
[KRYMQ] 15:21:06 INFO: Skipping folder default scan due to folder error: folder path missing
```

---

<div class="post-metadata">

### Author: ![AudriusButkevicius](https://forum.syncthing.net/user_avatar/forum.syncthing.net/audriusbutkevicius/32/277_2.png) [@AudriusButkevicius](https://forum.syncthing.net/u/AudriusButkevicius)
#### Post date: [July 7, 2015, 3:28pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/19 "2015-07-07T15:28:40Z")

</div>

You can generate the config on first start via -generate, modify it with you local xml parser, and then restart syncthing.

I believe this is what syncthing-android does.

---

<div class="post-metadata">

### Author: ![sgilani](https://forum.syncthing.net/user_avatar/forum.syncthing.net/sgilani/32/1649_2.png) [@sgilani](https://forum.syncthing.net/u/sgilani)
#### Post date: [July 7, 2015, 3:39pm UTC](https://forum.syncthing.net/t/ios-port-of-syncthing/5061/20 "2015-07-07T15:39:38Z")

</div>

I know this is a possible way but do you like really this workaround with syncthing -generate ?

I think it more (nice) to modify the default config which Syncthing generates by first lunch after ssh cert generation.

And for me it looks not like a config.xml problem. I added now also a new folder, all is fine in the config.xml and sync works, but after restart i get “folder path missing” i think it happend somewhere else…

[Next page](https://forum.syncthing.net/t/ios-port-of-syncthing/5061.md?page=2)
