Re: [swift-users] Incorrect Fisher-Yates shuffle in example code

2017-12-16 Thread Daniel Dunbar via swift-users
Would you like to post a PR to fix these issues?

 - Daniel

> On Dec 16, 2017, at 4:34 PM, Nevin Brackett-Rozinsky via swift-users 
>  wrote:
> 
> The example implementation of the Fisher-Yates shuffle found here 
> 
>  on Apple’s GitHub (and linked from swift.org/package-manager 
> ) has some problems. Stripping it down to 
> just the Swift 4 version, the code is:
> 
> public extension MutableCollection where Index == Int, IndexDistance == Int {
> mutating func shuffle() {
> guard count > 1 else { return }
> 
> for i in 0.. let j = random(count - i) + i
> guard i != j else { continue }
> swapAt(i, j)
> }
> }
> }
> 
> The main issues are:
> 
> 1) It assumes that indices are 0-based.
> 2) It assumes that indices can be randomly accessed by addition.
> 
> The former means it does not work for ArraySlice, and the latter means it 
> won’t work for all custom types. Additionally, the “count” property (which is 
> only guaranteed to be O(n) here) is accessed inside the loop, thus making the 
> algorithm potentially O(n²).
> 
> To fix everything, we’ll want RandomAccessCollection conformance. Once we add 
> that, we no longer need “Index == Int”. The result looks like:
> 
> public extension MutableCollection where Self: RandomAccessCollection, 
> IndexDistance == Int {
> mutating func shuffle() {
> for n in 0 ..< count-1 {
> let i = index(startIndex, offsetBy: n)
> let j = index(i, offsetBy: random(count-n))
> swapAt(i, j)
> }
> }
> }
> 
> Both of the original guard statements would be superfluous here (notably, 
> “swapAt” is documented to have no effect when i and j are the same) so I 
> removed them.
> 
> Technically we could get away without random access and still have an O(n) 
> algorithm, at the cost of copying the indices to an array:
> 
> public extension MutableCollection {
> mutating func shuffle() {
> guard !isEmpty else { return }
> 
> var idx = Array(indices)
> 
> for i in 0 ..< idx.count - 1 {
> let j = i + random(idx.count - i)
> swapAt(idx[i], idx[j])
> idx.swapAt(i, j)
> }
> }
> }
> 
> In any event, just in case someone was using a cut-and-paste version of the 
> example code in their own project, now you know it needs adjustment.
> 
> Nevin
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] module.modulemap documentation

2017-12-04 Thread Daniel Dunbar via swift-users
That is correct. If you have a suggestion for places you looked in the docs and 
a reference or explanation would have been good, feel free to open a PR for it!

 - Daniel

> On Dec 3, 2017, at 7:56 PM, Frank Swarbrick  wrote:
> 
> Well no wonder I couldn’t find it.  So this is a feature of clang/llvm rather 
> than Swift?  Interesting!
> Thanks much,
> Frank
>  
> From: daniel_dun...@apple.com [mailto:daniel_dun...@apple.com] 
> Sent: Sunday, December 3, 2017 8:55 PM
> To: Frank Swarbrick ; swift-users@swift.org
> Subject: Re: [swift-users] module.modulemap documentation
>  
>  
> On Dec 3, 2017, at 7:42 PM, Frank Swarbrick via swift-users 
>  wrote:
> 
> Where are all of the options/parameters/behaviors/whatever documented?  I 
> can’t for the life of me find it anywhere.  GINMF.
>  
> https://clang.llvm.org/docs/Modules.html
>  
>  - Daniel
> 
> 
>  
> Frank
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] module.modulemap documentation

2017-12-03 Thread Daniel Dunbar via swift-users

> On Dec 3, 2017, at 7:42 PM, Frank Swarbrick via swift-users 
>  wrote:
> 
> Where are all of the options/parameters/behaviors/whatever documented?  I 
> can’t for the life of me find it anywhere.  GINMF.

https://clang.llvm.org/docs/Modules.html

 - Daniel

>  
> Frank
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Cancelling an SPM build cleanly

2017-11-07 Thread Daniel Dunbar via swift-users


> On Nov 7, 2017, at 10:25 AM, Geordie J  wrote:
> 
> I was just reminded of this issue by another thread (thanks Daniel Dunbar for 
> https://github.com/apple/swift-llbuild/pull/196 
> !)
> 
> Is it possible to cancel an SPM build cleanly? If I run swift build and then 
> press Ctrl-C halfway through I end up in a weird broken state that requires a 
> swift package clean before anything works again. Maybe because SPM thinks 
> it’s still building the last job?

This is always a bug, please file!

FWIW, I cancel builds all the time and haven’t seen this issue, so it would be 
good to provide as many details as possible.

 - Daniel

> 
> I ask because sometimes I start a build, realise I actually wanted to make 
> one more change and then press start again. This works in Xcode and breaks in 
> SPM.
> 
> Thanks,
> Geordie

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] xcode 9 new build system too aggressive?

2017-11-07 Thread Daniel Dunbar via swift-users


> On Nov 7, 2017, at 10:18 AM, David Baraff  wrote:
> 
> Ah.  i hadn’t thought about the fact that often-time my first attempt to 
> build fails.  that might well be the deciding thing.
> any idea how long before this will show up in a release xcode?  weeks? 
> months?  a year?

We can’t comment on unreleased software schedules.

 - Daniel

> Begin forwarded message:
> 
>> From: Daniel Dunbar > >
>> Subject: Re: [swift-users] xcode 9 new build system too aggressive?
>> Date: November 7, 2017 at 9:55:06 AM PST
>> To: David Baraff >
>> Cc: swift-users >
>> 
>> This does sound like a serious bug (and may be one I just fixed 
>> https://github.com/apple/swift-llbuild/pull/196 
>> ), but if its specific to 
>> an Apple product please report bugs in Xcode on http://bugreporter.apple.com 
>> 
>> 
>> - Daniel
>> 
>>> On Nov 6, 2017, at 10:11 PM, David Baraff via swift-users 
>>> > wrote:
>>> 
>>> I will be editing a single file, and usually xcode will do a quick build as 
>>> i change the code.  then, abruptly, i make one more edit to the file and 
>>> all of a sudden xcode decides to compile tons more.  (little changes in the 
>>> file, not defining new methods or classes or anything).
>>> 
>>> anybody else seeing this?
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users
>> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] xcode 9 new build system too aggressive?

2017-11-07 Thread Daniel Dunbar via swift-users
This does sound like a serious bug (and may be one I just fixed 
https://github.com/apple/swift-llbuild/pull/196), but if its specific to an 
Apple product please report bugs in Xcode on http://bugreporter.apple.com

 - Daniel

> On Nov 6, 2017, at 10:11 PM, David Baraff via swift-users 
>  wrote:
> 
> I will be editing a single file, and usually xcode will do a quick build as i 
> change the code.  then, abruptly, i make one more edit to the file and all of 
> a sudden xcode decides to compile tons more.  (little changes in the file, 
> not defining new methods or classes or anything).
> 
> anybody else seeing this?
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Communicating with dynamically loaded swift library

2017-10-07 Thread Daniel Dunbar via swift-users
Is it possible for you to make a small test package that shows the problem, and 
file a bug in bugs.swift.org? There may be something we need to fix in SwiftPM 
before this can work (because of our linking model).

 - Daniel

> On Oct 7, 2017, at 10:42 PM, Ján Kosa via swift-users  
> wrote:
> 
> That is exactly what I did. The only package that depends on the protobuf is 
> the PluginInterface. Both MyPlugin and and PluginConsumer depend on the 
> PluginInterface and not on the protobuf itself. I had to shuffle around my 
> dependencies a bit, which resulted in smaller number of dependencies but they 
> don't make much sense now (as in, some target had to depend on 
> PluginInterface even if they don't need to, just to get access to protobuf). 
> I could live with that if it solved the issue, but it didn't.
> 
> I am adding my Package.swift files in case I missed something:
> 
> PluginInterface:
> 
> ```swift
> let package = Package(
> name: "PluginInterface",
> 
> products: [ .library(name: "PluginInterface", type: .dynamic, targets: 
> ["PluginInterface"]) ],
> 
> dependencies: [ .package(url: "https://github.com/apple/swift-protobuf.git 
> ", from: "0.0.0") ],
> 
> targets: [ .target(name: "PluginInterface", dependencies: ["SwiftProtobuf"]) ]
> 
> )```
> 
> 
> 
> MyPlugin:
> 
> ```swift
> 
> let package = Package(
> 
> name: "MyPlugin",
> 
> products: [ .library(name: "MyPlugin", type: .dynamic, targets: 
> ["PluginImpl"]) ],
> 
> dependencies: [
> 
> .package(url: "path/to/PluginInterface.git", from: "0.0.0"),
> 
> ],
> 
> targets: [
> 
> .target(name: "PluginImpl", dependencies: ["ProtoBufMessages"]),
> 
> .target(name: "ProtoBufMessages", dependencies: ["PluginInterface"])
> 
> ]
> 
> 
> )```
> 
> 
> 
> PluginConsumer:
> 
> ```swift
> 
> let package = Package(
> 
> name: "PluginConsumer",
> 
> dependencies: [
> 
> .package(url: "https://github.com/PerfectlySoft/Perfect-WebSockets.git 
> ", from: "3.0.0"),
> 
> .package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git 
> ", from: "3.0.0"),
> 
> .package(url: "path/to/PluginInterface", from: "0.0.0"),
> 
> .package(url: "https://github.com/krzyzanowskim/CryptoSwift.git 
> ", from: "0.0.0")
> 
> ],
> 
> targets: [
> 
> .target(name: "AppMaster", dependencies: ["Shared", "CryptoSwift"]),
> 
> .target(name: "PluginConsumer", dependencies: ["Shared", "CryptoSwift"]),
> 
> .target(name: "Shared", dependencies: ["ProtoBufMessages", 
> "PerfectHTTPServer", "PerfectWebSockets"]),
> 
> .target(name: "ProtoBufMessages", dependencies: ["PluginInterface"])
> 
> ]
> 
> 
> )```
> 
> 
> 
> App master is separate executable that shares some functionality with 
> PluginConsumer, but it doesn't link against it in any way. I guess it could 
> be omitted, but I wanted to give you whole thing as it is
> 
> 
> On 7 October 2017 at 18:33, Geordie Jay  > wrote:
> 
> Ján Kosa > schrieb am Sa. 7. 
> Okt. 2017 um 15:27:
> I tried to use @_exported and it helped somewhat. While I still have same 
> warnings, size of the PluginInterface library went down by 6mb (to 120kb) so 
> it looks like Protobuf is no longer statically linked to it. However, size of 
> PluginConsumer executable went up by same 6mb, it looks like it is linked 
> there twice now. 
> 
> To be clear: take protobuf out of the PluginConsumer dependencies. Actually, 
> I’m not sure which is which, but protobuf should only be listed as a 
> dependency of one package, where it is imported as @_exported. After that, 
> your other modules depend on the package that imports / exports protobuf.
> 
> I also noticed interesting thing. If I build executable using `swift build` 
> the size is around 17mb, when I generate xcode project and build it using 
> that, size is around 200kb, but I get same warnings using both approaches
> 
> On 7 October 2017 at 15:44, Geordie Jay  > wrote:
> 
> Ján Kosa > schrieb am Sa. 7. 
> Okt. 2017 um 13:34:
> I tried swift package clean, but it didn't help
> 
> "Try to ensure the plugin provider module (libA) is (only) being compiled 
> into its standalone shared library file." 
> How do I go about this? It is 3rd party module, it doesn't define any 
> products (https://github.com/apple/swift-protobuf.git 
> ). Is there something I can do 
> in my Package files to make sure it is loaded dynamically?
> 
> When you compile a package depending on protobuf, all the relevant symbols 
> end up in your package’s library file. So here’s something you might try:
> 
> import protobuf into your own “PluginProvider” module (package), which has 

Re: [swift-users] Communicating with dynamically loaded swift library

2017-10-04 Thread Daniel Dunbar via swift-users
The way that I have done this in the past is pass a protocol as an unsafe 
pointer to an exposed entry point:
```swift
let entryPoint = dlsym(handle, “initializePlugin”)
guard entryPoint != nil else {
fatalError("missing plugin entry point: \(pluginPath)")
}
typealias PluginInitializationFunc = @convention(c) 
(UnsafeRawPointer) -> ()
let f = unsafeBitCast(entryPoint, to: PluginInitializationFunc.self)
f(Unmanaged.passUnretained(self).toOpaque())
```

and then in the plugin convert back to the appropriate type:

```
@_cdecl("initializePlugin")
public func initializePlugin(_ ptr: UnsafeRawPointer) {
let manager = Unmanaged.fromOpaque(ptr).takeUnretainedValue()
```

HTH,
 - Daniel

> On Oct 4, 2017, at 11:02 AM, Ján Kosa via swift-users  
> wrote:
> 
> Hello folks,
> 
> I have been toying with dynamic libraries, trying to implement plugin 
> functionality. I was able to get to the point where I can call simple 
> function in loaded library, but I am having troubles starting more 
> sophisticated communication channel.
> 
> There are 3 projects
> - PluginConsumer is an app that loads plugin libraries 
> - MyPlugin is a plugin implementation, output is dynamic library that 
> PluginConsumer loads
> - PluginInterface is common interface that both MyPlugin and PluginConsumer 
> use, so that they know how to communicate
> 
> My first idea was to have PluginInterface be a simple SPM project with single 
> file where the bare-bones PluginInterface class would be:
> 
> 
> open class PluginInterface {
> 
> open func sayHi()
> 
> }
> 
> 
> 
> Package.swift file:
> 
> 
> 
> // swift-tools-version:4.0
> 
> import PackageDescription
> 
> let package = Package(
> 
> name: "PluginInterface",
> 
> products: [ .library(name: "PluginInterface", type: .dynamic, targets: 
> ["PluginInterface"]) ],
> 
> targets: [ .target(name: "PluginInterface") ]
> 
> 
> )
> 
> 
> 
> 
> 
> UserPlugin is also very simple project containing only one file:
> 
> 
> 
> public func getPlugin() -> AnyObject {
> 
> return MyPlugin()
> 
> 
> }
> 
> 
> 
> class MyPlugin: PluginInterface {
> 
> override func sayHi() {
> 
> print("Hi from my plugin")
> 
> }
> 
> }
> 
> Package.swift:
> 
> 
> 
> // swift-tools-version:4.0
> 
> import PackageDescription
> 
> let package = Package(
> 
> name: "MyPlugin",
> 
> products: [ .library(name: "MyPlugin", type: .dynamic, targets: 
> ["MyPlugin"]) ],
> 
> dependencies: [ .package(url: "url_to_PluginInterface", from: "0.0.0"), ],
> 
> targets: [
> 
> .target(name: "PluginInterface", dependencies: ["PluginInterface"]),
> 
> .target(name: "MyPlugin", dependencies: ["PluginInterface"]),
> 
> ]
> 
> 
> )
> 
> 
> 
> The PluginConsumer is bit more complicated, but here is relevant part (lib 
> loading and function calling):
> 
> 
> 
> typealias InitFunction = @convention(c) () -> AnyObject
> 
> 
> 
> let openRes = dlopen(pathToLib, RTLD_NOW|RTLD_LOCAL)
> 
> if openRes != nil {
> 
> defer {
> 
> dlclose(openRes)
> 
> }
> 
> let symbolName = "mangled_symbol_name"
> 
> let sym = dlsym(openRes, symbolName)
> 
> 
> 
> if sym != nil {
> 
> let f: InitFunction = unsafeBitCast(sym, to: InitFunction.self)
> 
> let plugin = f() as? PluginInterface
> 
> }
> 
> 
> }
> 
> Package.swift file:
> 
> // swift-tools-version:4.0
> 
> import PackageDescription
> 
> let package = Package(
> 
> name: "PluginConsumer",
> 
> dependencies: [ .package(url: "path_to_plugin_interface", from: "0.0.0") 
> ],
> 
> targets: [ .target(name: "PluginConsumer", dependencies: 
> ["PluginConsumer"]) ]
> 
> 
> )
> 
> 
> 
> This all compiles nicely, MyPlugin project creates dylib file that executable 
> created by PluginConsumer can load, but the problem is with following line:
> 
> let plugin = f() as? PluginInterface
> 
> Type of the plugin is MyPlugin, but from the consumer's view, it doesn't 
> inherit from PluginInterface so I can't call sayHi() method. I assume this is 
> because there is no relation between PluginInterface class that compiler uses 
> for MyPlugin project one that it uses for PluginConsumer project. After 
> library is loaded, they are two completely different classes that happen to 
> share same name. Is my assumption correct and how do I go about fixing it?
> 
> I had an idea I could make PluginInterface emit dynamic library that would be 
> dynamically linked by both MyPlugin and PluginConsumer, thus making them 
> share same PluginInterface class, but I can't figure out how to do that (or 
> if it's right way of doing this).
> 
> 
> 
> Any help appreciated :)
> 
> Lope
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing 

Re: [swift-users] Package Manager test target name conflict

2017-07-29 Thread Daniel Dunbar via swift-users
Since we don’t have any name spacing facility yet, I think the right answer 
here is for packages to always give their tests a name like Tests.

Even though we might conceptually be able to allow a few limited areas of 
collision, it gets cumbersome when we might offer features like “run all tests 
of all dependencies”, since we would have to add more complexity to the build 
process to support this. That doesn’t feel worth it to me given that non-test 
targets are going to always require some for of name-based name spacing.

 - Daniel

> On Jul 29, 2017, at 1:57 PM, Taylor Swift via swift-users 
>  wrote:
> 
> Many libraries I maintain contain a testTarget called "Tests", but whenever 
> an external package depends on two or more library packages, the "Tests" 
> targets conflict with one another, even though the testTargets are never 
> actually depended on. How do I get the SPM to ignore them?
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Is there any harm that an @escaping handler never called?

2017-07-11 Thread Daniel Dunbar via swift-users

> On Jul 11, 2017, at 3:55 PM, Zhao Xin via swift-users  > wrote:
> 
> For example, I have an async query, I pass it an `@escaping resultHandler`. 
> If there is any results, the handler will run. However, if the result is 
> empty, the `@escaping resultHandler` will never run.
> 
> Is there any memory leak or something will happen if the `@escaping 
> resultHandler` never runs?

No, assuming your handler has been written to not participate in a retain cycle 
(for example, ensuring you use [weak self] if appropriate).

 - Daniel

> Zhao Xin
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Passing Data to a f(void *) function

2017-06-30 Thread Daniel Dunbar via swift-users

> On Jun 30, 2017, at 7:40 AM, Martin R via swift-users  
> wrote:
> 
> I have a C function 
> 
>void myfunc(const void *ptr);
> 
> which is imported to Swift as
> 
>func myfunc(_ ptr: UnsafeRawPointer!)
> 
> This compiles and runs without problems:
> 
>let data = Data(bytes: [1, 2, 3, 4])
>data.withUnsafeBytes { (ptr) in myfunc(ptr) } // (A)
> 
> and the type of `ptr` is inferred as `UnsafePointer`. But adding an 
> explicit type
> annotation produces a compiler warning:

How do you know the inferred type is `UnsafePointer`? I think it is more 
likely it is `UnsafePointer`, and the following compiles:
```
let data = Data(bytes: [1, 2, 3, 4])
data.withUnsafeBytes { (ptr: UnsafePointer) in
myfunc(ptr)
}
```

 - Daniel

> 
>data.withUnsafeBytes { (ptr: UnsafePointer) in myfunc(ptr) } // (B)
>// warning: UnsafePointer has been replaced by UnsafeRawPointer
> 
> which is understandable in the view of "SE-0107 UnsafeRawPointer API".
> 
> The "Fix-it" replaces `UnsafePointer` by `UnsafeRawPointer`, and that 
> does not
> compile anymore:
> 
>data.withUnsafeBytes { (ptr: UnsafeRawPointer) in myfunc(ptr) } // (C)
>// error: cannot convert value of type 'Void' to closure result type '_'
> 
> because there is no `withUnsafeBytes()` method taking a 
> `(UnsafeRawPointer)->ResultType`
> closure.
> 
> 
> My questions are:
> 
> 1. Why are (A) and (B) treated differently?
> 
> 2. Is (A) "legal", or should one use some non-void pointer
> 
>data.withUnsafeBytes { (ptr: UnsafePointer) in myfunc(ptr) } // (D)
> 
>   (which feels wrong to me because it is converted back to a void pointer when
>   calling the function).
> 
> 3. Or should there be a `withUnsafeRawPointer()` method which makes (C) 
> compile as
> 
>  data.withUnsafeRawBytes { (ptr: UnsafeRawPointer) in myfunc(ptr) }
> 
>   This would also allow to access the data at byte offsets more easily, e.g.
> 
>   data.withUnsafeRawBytes { ptr in
>   let u16 = ptr.load(fromByteOffset: 4, as: UInt16.self)
>   }
> 
>   Does that makes sense?
> 
> Regards, Martin
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] swift 4 compiler error tuple parameter does not support destructing

2017-06-29 Thread Daniel Dunbar via swift-users
This is due to SE-0110:
  
https://github.com/apple/swift-evolution/blob/master/proposals/0110-distingish-single-tuple-arg.md
but see the additional commentary:
  
https://lists.swift.org/pipermail/swift-evolution-announce/2017-June/000386.html

For now you can rewrite it as:
```
let filenamelength = bytes
  .enumerated()
  .map {
let (index, element) = $0
return Int(Double(element) * pow(256,Double(index))) }
  .reduce(0, +)
```

 - Daniel

> On Jun 29, 2017, at 8:08 PM, CK TUNG via swift-users  
> wrote:
> 
> I have the following code snippet that compile OK in swift 3
> 
> bytes = Array(UnsafeBufferPointer())
> let filenamelength = bytes[(i+28)..<(i+28+2)]
> .enumerated()
> .map { (index, element) in return Int(Double(element) * 
> pow(256,Double(index))) }
> .reduce(0, +)
>  
> I have the following code snippet that compile OK in swift 3
> In Swift 4 (Xcode beta1) it compiled with error something like "... too 
> complex"
> Now in Swift 4 Xocde beta2 the error is tuple parameter element does not 
> support destructing
> what has been changed in swift 4 ?
> 
> Please help how to solve it ?
> 
> Thanks
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] arc4random_uniform on Linux is missing from Foundation??

2017-05-22 Thread Daniel Dunbar via swift-users
This function isn't something which comes with Foundation, it is supplied by 
the BSD libraries on Darwin, but those aren't present on Linux.

I recommend looking for a Swift implementation of a high-quality RNG which will 
meet your needs, rather than trying to rely on a non-portable implementation 
coming from the base OS.

 - Daniel

> On May 22, 2017, at 8:44 AM, Edward Connell via swift-users 
>  wrote:
> 
> Any ideas when Foundation on Linux will support arc4random_uniform? This is 
> kind of an important function.
> There doesn't seem to be any decent substitute without requiring the 
> installation of libbsd-dev, which turns out to be messy. Currently I am doing 
> this, but glibc random with mod does not produce good quality numbers, due to 
> modulo bias.
> 
> Has anyone come up with a better solution to get a true uniform distribution 
> that isn't super messy?
>  
> import Foundation
> 
> #if os(Linux)
>   import Glibc
> #endif
> 
> 
> public func random_uniform(range: Int) -> Int {
>   guard range > 0 else { return 0 }
>   #if os(Linux)
> return Int(random()) % range
>   #else
> return Int(arc4random_uniform(UInt32(range)))
>   #endif
> }
> 
> 
> Thanks, Ed
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] passing command line arguments to `swift test`

2017-05-21 Thread Daniel Dunbar via swift-users
To run one test you can use:
  swift test -s BasicTests.PathTests/testContains

See:
  swift test --help

 - Daniel

> On May 19, 2017, at 4:34 PM, Kelvin Ma via swift-users 
>  wrote:
> 
> i want to be able to run a single test case at a time instead of my whole 
> test suite and i’m currently invoking the test binary directly after doing 
> `swift test`
> 
> On May 19, 2017, at 4:56 PM, Brent Royal-Gordon  
> wrote:
> 
>>> On May 18, 2017, at 8:16 AM, Kelvin Ma via swift-users 
>>>  wrote:
>>> 
>>> Is there a way I can pass command line arguments along to the testing 
>>> program with `swift test` so that they are visible in 
>>> `CommandLine.arguments`?
>> 
>> No. If there were one, you would not be able to reliably invoke the tests 
>> automatically.
>> 
>> What are you trying to do? Test code that uses `CommandLine.arguments`?
>> 
>> -- 
>> Brent Royal-Gordon
>> Architechies
>> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Annotating C APIs without changing the original header files

2017-05-12 Thread Daniel Dunbar via swift-users
We don't have explicit support for api notes in SwiftPM.

We discussed it, and it something which probably makes sense, but no one has 
worked on a design or implementation yet.

 - Daniel

> On May 12, 2017, at 11:32 AM, Michael Gottesman via swift-users 
>  wrote:
> 
> +Ankit
> 
> Michael
> 
>> On May 12, 2017, at 10:10 AM, Geordie J via swift-users 
>> > wrote:
>> 
>> To continue this thread: I managed to annotate a bunch of C APIs with 
>> modulename.apinotes. This works with Xcode (to a certain degree - pointers, 
>> enums, and especially OpaquePointers are tricky). I’m now trying to build my 
>> package with SwiftPM and it doesn’t seem to recognise the apinotes file. 
>> 
>> @Doug Gregor, would you be able to advise as to whether apinotes works with 
>> SwiftPM (on Linux) and whether it requires some extra settings that I may be 
>> unaware of?
>> 
>> Thanks and best regards for the weekend,
>> Geordie
>> 
>> 
>>> Am 08.05.2017 um 00:51 schrieb Geordie Jay >> >:
>>> 
>>> I'm having the same issue. The renames seem to work, as in they disappear 
>>> from the global scope with a fixit to rename to the new (namespaced) 
>>> version if I type in the name manually, but they don't appear as static 
>>> members of the enum type, regardless of how I call them. Would appreciate 
>>> some help with this too.
>>> 
>>> Cheers,
>>> Geordie 
>>> Rick Mann > schrieb am 
>>> So. 7. Mai 2017 um 23:06:
>>> I'm trying to use apinotes for this third-party C library (call it 
>>> "Lib.dylib"). It has an enum lgs_error_t:
>>> 
>>> typedef enum {
>>> lgs_error_none = 0,
>>> lgs_error_invalid_handle = -1,
>>> lgs_error_null = -2,
>>> lgs_error_invalid_parameter = -3,
>>> lgs_error_invalid_operation = -4,
>>> lgs_error_queue_full = -5
>>> } lgs_error_t;
>>> 
>>> So I wrote apinotes ("Lib.apinotes") that look like this, next to the 
>>> .dylib, and part of my Xcode iOS app target:
>>> 
>>> Enumerators:
>>> # lgs_error_t
>>> 
>>> - Name: lgs_error_none
>>>   SwiftName: lgs_error_t.none
>>> - Name: lgs_error_invalid_handle
>>>   SwiftName: lgs_error_t.invalidHandle
>>> - Name: lgs_error_null
>>>   SwiftName: lgs_error_t.nullParameter
>>> - Name: lgs_error_invalid_parameter
>>>   SwiftName: lgs_error_t.invalideParameter
>>> - Name: lgs_error_invalid_operation
>>>   SwiftName: lgs_error_t.invalidOperation
>>> - Name: lgs_error_queue_full
>>>   SwiftName: lgs_error_t.queueFull
>>> 
>>> But this line of code fails:
>>> 
>>> var err: lgs_error_t = .nullParameter
>>> Type 'lgs_error_t' has no member 'nullParameter'
>>> 
>>> Am I missing something else?
>>> 
>>> > On May 4, 2017, at 16:55 , Douglas Gregor via swift-users 
>>> > > wrote:
>>> >
>>> >
>>> >> On May 3, 2017, at 4:10 PM, Geordie J via swift-users 
>>> >> > wrote:
>>> >>
>>> >> Hi everyone,
>>> >>
>>> >> I’m about to start on another big project with Swift on Android and 
>>> >> would like to annotate that JNI headers as much as possible before I do: 
>>> >> specifically I’d like to make _Nonnull and CF_SWIFT_NAME annotations to 
>>> >> the headers found in a user's jni.h.
>>> >>
>>> >> The question is: is it possible to annotate headers this without 
>>> >> changing the original header files? Specifically I’m looking for an 
>>> >> options that allows annotations in a separate file, probably one that is 
>>> >> read when loading the package’s module.modulemap.
>>> >>
>>> >> I’d like to distribute the annotations in a SwiftPM package that also 
>>> >> exposes the original (hopefully annotated) headers. Up until now I’ve 
>>> >> been using Swift to override methods in code, but this isn’t as clean or 
>>> >> extensible and I fear it may have other (particularly performance) 
>>> >> implications.
>>> >>
>>> >> I guess the alternative would be to just maintain and distribute a 
>>> >> modified version of jni.h with the annotations, but that would be a 
>>> >> "last resort” option.
>>> >
>>> >
>>> > This is the role of API notes, which you can see here:
>>> >
>>> >   https://github.com/apple/swift/tree/master/apinotes 
>>> > 
>>> >
>>> > with some rough documentation-in-source here:
>>> >
>>> >   
>>> > https://github.com/apple/swift-clang/blob/stable/lib/APINotes/APINotesYAMLCompiler.cpp
>>> >  
>>> > 
>>> >
>>> >   - Doug
>>> >
>>> > ___
>>> > swift-users mailing list
>>> > swift-users@swift.org 
>>> > https://lists.swift.org/mailman/listinfo/swift-users 
>>> > 
>>> 
>>> 
>>> --
>>> Rick Mann
>>> 

Re: [swift-users] Passing value types or members of value types?

2017-05-06 Thread Daniel Dunbar via swift-users

> On May 6, 2017, at 10:27 PM, Nate Birkholz via swift-users 
>  wrote:
> 
> Classes and structs are different things. Classes are passed by reference, 
> structs are passed by value with copy on write. 

This is not correct. Array, and other types, implement copy-on-write 
themselves, but this is not true of arbitrary structs.

To answer Kelvin's question, yes, the optimizer will be able to see through 
that code _assuming_ it can see the definition in a way it can optimize 
(generally speaking, this means not something which will be dynamically 
dispatched, and where the implementation is available (i.e. the same file, or 
the same module with whole module optimization enabled)).

You can verify this by simply writing a small sample program and spot checking 
the assembly matches what you want, for example:
--
$ cat z.swift 
struct Vertex {
let x: Double, y: Double
var r:Int, g:Int, b:Int
let s:Double, t:Double
var selected:Bool
}

private func taxicab_distance(_ v1:Vertex, _ v2:Vertex) -> Double {
return v2.x - v1.x + v2.y - v1.y
}

func f0(a: Vertex, b: Vertex) -> Double {
  return taxicab_distance(a, b)
}

$ swiftc -Ounchecked -S -o - z.swift | grep 'main2f0' -A8
.private_extern __T04main2f0SdAA6VertexV1a_AD1btF
.globl  __T04main2f0SdAA6VertexV1a_AD1btF
.p2align4, 0x90
__T04main2f0SdAA6VertexV1a_AD1btF:
pushq   %rbp
movq%rsp, %rbp
movsd   (%rsi), %xmm0
subsd   (%rdi), %xmm0
addsd   8(%rsi), %xmm0
subsd   8(%rdi), %xmm0
popq%rbp
retq
--

 - Daniel


> 
> Strings and Arrays are structs, not classes.
> 
> On Sat, May 6, 2017 at 10:24 PM, Kelvin Ma  > wrote:
> I hear that a lot but why do all the official sources sound like 
> copy-on-write is something you have to manually implement with a class and 
> isUniquelyReferenced if it’s not an array or a string?
> 
> On May 7, 2017, at 12:02 AM, Nate Birkholz  > wrote:
> 
>> Let me try one more time, my stupid phone keeps changing words. 
>> 
>> ACTUALLY, the struct is a pointer until it's written to, and is only copied 
>> on write.
>> 
>> Sent from my iPhone, please excuse brevity and errors
>> 
>> On May 6, 2017, at 9:59 PM, Nate Birkholz > > wrote:
>> 
>>> Oddly, until it's *written* you will be working with a pointer.
>>> 
>>> Sent from my iPhone, please excuse brevity and errors
>>> 
>>> On May 6, 2017, at 9:33 PM, Kelvin Ma via swift-users 
>>> > wrote:
>>> 
 If I have a “large” struct like
 
 struct Vertex
 {
 let x:Double, y:Double
 var r:Int, g:Int, b:Int
 let s:Double, t:Double
 var selected:Bool
 }
 
 and I want to pass it to a function without modifying it like
 
 func taxicab_distance(_ v1:Vertex, _ v2:Vertex) -> Double
 {
 return v2.x - v1.x + v2.y - v1.y
 }
 
 Will the entire struct Vertex get copied and pushed onto the stack, or 
 will only the relevant members be passed to the function?
 
 In other words, does the compiler know to optimize this call down to
 
 func taxicab_distance(v2x:Double, v1x:Double, v2y:Double, v1y:Double) -> 
 Double
 {
 return v2x - v1x + v2y - v1y
 }
 
 ?
 ___
 swift-users mailing list
 swift-users@swift.org 
 https://lists.swift.org/mailman/listinfo/swift-users 
 
> 
> 
> 
> -- 
> Nate Birkholz
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] error: the package has an unsupported layout, unexpected source file(s) found: /Users/maximveksler/Project/Org/Collection/Sources/main.swift

2017-01-24 Thread Daniel Dunbar via swift-users

> On Jan 24, 2017, at 11:57 AM, Maxim Veksler via swift-users 
>  wrote:
> 
> The most recent change I've done is add the Sources/extensions/Jay.swift, now 
> I'm unable to build the project.
> 
> No idea what could have gone wrong, feedback?
> 
> 
> ➜  Collection git:(master) ✗ find Sources
> Sources
> Sources/extensions
> Sources/extensions/Jay.swift
> Sources/main.swift

If you want one module with both sources but some in a subdirectory, you need 
to write it as:

Sources/Collection/main.swift
Sources/Collection/extensions/Jay.swift

If you want two modules then you need to lay this out as:
  Sources/extensions/Jay.swift
and
  Sources/Collection/main.swift

We know this UX is not very good and are debating how to best resolve this...

 - Daniel

> 
> ➜  Collection git:(master) ✗ cat Package.swift
> import PackageDescription
> 
> let package = Package(
> name: "Collection",
> dependencies: [
>   .Package(url: "https://github.com/GraphQLSwift/GraphQL.git 
> ", majorVersion: 0),
>   .Package(url: "https://github.com/czechboy0/Jay.git 
> ", majorVersion: 1)
> ]
> )
> 
> ➜  Collection git:(master) ✗ swift build
> error: the package has an unsupported layout, unexpected source file(s) 
> found: /Users/maximveksler/Project/Org/Collection/Sources/main.swift
> fix: move the file(s) inside a module
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Announcement: Official Docker Image for Swift now available

2017-01-21 Thread Daniel Dunbar via swift-users
Awesome, thanks for pushing this forward!

 - Daniel

> On Jan 21, 2017, at 2:10 PM, Swizzlr via swift-users  
> wrote:
> 
> Hello all,
> 
> I'm pleased to announce that with the assistance of many, many people (see 
> below), we have released an “official" Docker image for Swift 
> . 
> 
> The image contains everything needed to compile and run a Swift application, 
> reliably and reproducibly. It’s based on Ubuntu 16.04 and has been used in 
> production for many months now. A Docker library image such as this one 
> occupies the top level namespace, so that you can simply write “FROM swift” 
> to refer to the image. It has received extensive auditing for best practices 
> and security by Docker experts, and will be maintained by a dedicated team of 
> volunteers.
> 
> I would like to encourage everyone interested to ask questions and offer 
> improvements over on the Github repo 
> . Personally, I want to offer my 
> thanks to Haris Amin and Oliver Letterer for their early and pioneering work 
> on Dockerizing Swift, Tianon Gravi for his patient and informative feedback 
> while refining the image; and all those who have contributed to its 
> development .
> 
> Happy coding – I hope you make something excellent with this.
> 
> Tom
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Exclamation mark's in swift parameter listings?

2017-01-09 Thread Daniel Dunbar via swift-users
It is an "implicitly unwrapped optional", or IOU.

See:
  
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html

 - Daniel

> On Jan 9, 2017, at 4:23 PM, Ethin Probst via swift-users 
>  wrote:
> 
> Hello all,
> I was wondering what an exclamation mark in a swift parameter listing
> means. For instance, I used Elements Oxidizer Live to translate some
> C# code into Swift. Reviewing it, I found the following (among
> others):
> @DllImport("ScriptHookV.dll")
> private static __extern func scriptRegister(_ module: System.IntPtr!,
> _ LP_SCRIPT_MAIN: LP_SCRIPT_MAINDelegate!)
> What I'm wondering is what does the '!' in that list of parameters
> mean? I also saw it when writing another program:
>func MainForm_Load(_ sender: System.Object!, _ e: System.EventArgs!) {
> // ...
> }
> I don't recall the swift book teaching you what that means, so could
> someone tell me what those mean?
> -- 
> Signed,
> Ethin D. Probst
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] [swift-build-dev] SwiftPM Test Fixtures

2016-11-18 Thread Daniel Dunbar via swift-users
The way that we have been doing this is by using `#file` to derive the location 
of the test data. It is gross, but it works until we have a real resource story.

 - Daniel

> On Nov 17, 2016, at 7:07 PM, Ryan Lovelett via swift-build-dev 
>  wrote:
> 
> If I have a number of `*.json` files that are meant to be loaded and
> used as a part of my SwiftPM test suite:
> 
> 1. how do I get SwiftPM to bundle them with the test bundle?
> 2. how do I reference the fixtures in the test bundle?
> 
> ## What I've tried...
> 
> I tried creating a top-level directory called `Fixtures`.  Then
> referencing the bundle with something like:
> `Bundle.allBundles.first(where: { $0.bundlePath.hasSuffix(".xctest")
> })!.bundleURL`.
> 
> Is this even possible?
> ___
> swift-build-dev mailing list
> swift-build-...@swift.org
> https://lists.swift.org/mailman/listinfo/swift-build-dev

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Using Swift Package Manager with C++

2016-11-12 Thread Daniel Dunbar via swift-users
This was just fixed on trunk:
  
https://bugs.swift.org/browse/SR-3152?jql=text%20~%20%22C%2B%2B%22%20ORDER%20BY%20created%20DESC

In the meantime, you can either use a recent snapshot from swift.org, or you 
can pass `-Xlinker -lc++` on the command line to work around the problem.

 - Daniel

> On Nov 12, 2016, at 1:42 PM, Vinicius Vendramini via swift-users 
>  wrote:
> 
> I’m having issues using C++ code with the Swift PM. Simple examples work fine 
> as long as I don’t use anything in the C++ standard library, otherwise the 
> programs don’t compile.
> 
> My guess is that the Swift PM internally uses clang (as opposed to clang++) 
> to compile C++ code, and while clang can compile normal C++ code it can’t 
> link against the C++ standard library. Is that it?
> 
> The second example on the link below shows working C++ code with Swift. If I 
> try to add a simple call to std::cout, for instance, the program stops 
> compiling.
> 
> Thanks for any help :)
> 
> link: 
> http://ankit.im/swift/2016/05/21/creating-objc-cpp-packages-with-swift-package-manager/
>  
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] swift3 - Trying to get swift package example to work - Stack Overflow

2016-11-11 Thread Daniel Dunbar via swift-users
Hey Dave,

Thanks for pointing this out, we will take a look.

 - Daniel

> On Nov 11, 2016, at 3:35 PM, Dave Yost via swift-users 
>  wrote:
> 
> 
>> http://stackoverflow.com/questions/40557767/trying-to-get-swift-package-example-to-work
>>  
>> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] How to include swift test resource files?

2016-11-10 Thread Daniel Dunbar via swift-users
We do not yet have any kind of story for resources.

If you just need data during tests, what you can do is just rely on the tests 
being run in an environment which has access to the source, so you can use 
Swift's `#file` to derive the location of your test artifacts from the current 
source file path.

This is kind of a hack, but it works. Example:
  
https://github.com/apple/swift-package-manager/blob/master/Sources/TestSupport/misc.swift#L38

 - Daniel

> On Nov 10, 2016, at 9:29 AM, Edward Connell  wrote:
> 
> Swift test builds and runs the package Tests. My tests require data files 
> such as images to run. 
> With an Xcode project we can Copy Bundle Resources in the Build Phases to 
> include the necessary files.
> 
> How do we do this with swift test, or swift build?
> 
> I thought about a hack to manually copy the resource files, but since "swift 
> test" builds and runs the tests as a single action there doesn't seem to be 
> an opportunity.
> 
> How do we include package resources during build and test?
> 
> Thanks, Ed

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Monorepo workflow using SPM

2016-11-09 Thread Daniel Dunbar via swift-users

> On Nov 3, 2016, at 2:06 PM, Erica Sadun via swift-users 
>  wrote:
> 
> I want less of a monorepo than an ability to build a group of orthogonal 
> elements into a single repo so I don't have to create a separate repo for 
> every single Swift library I build, especially when there are logical 
> relationships between subfolders and partial incorporation into builds  For 
> example, I'm messing with core graphics geometry right now. I have basic 
> types & extensions, some experimental stuff, and other misc things for (for 
> example) doing playground visualization support. Rather than 
> over-conditionalize my code, I'd rather conditionalize the package, so that 
> everything pulls, compiles, and works fine on, say, a macOS build but bits 
> that don't belong (iOS playground visualization support) can be omitted from 
> a specific configuration *for* *that* *repo* instead of me having to make 
> really ugly code conditions in files which are intended specifically for 
> known targets and may be excluded from package builds because of their 
> intended targets.

Can you explain the interaction between conditional compilation and monorepo / 
multi-package repos? They seem somewhat orthogonal to me.

 - Daniel

> -- E
> 
> 
>> On Nov 3, 2016, at 2:31 PM, Ankit Agarwal via swift-users 
>> > wrote:
>> 
>> +swift-build-dev
>> 
>> Not right now but we're considering adding support for multiple packages in 
>> a repository. It would be good if you can explain your 
>> requirements/features/flow are you looking for.
>> 
>> On Friday 4 November 2016, Georgios Moschovitis via swift-users 
>> > wrote:
>> The Swift Package Manager is a great addition to the Swift programmer's 
>> toolbelt and in general I like the integration with Git.
>> 
>> However, since SPM promotes a separate Git repo per package and actually 
>> leverages Git tags to resolve dependency versions, I am wondering if it's 
>> possible to use the popular(?) 'monorepo' workflow with SPM. 
>> 
>> thanks,
>> -g.
>> 
>> 
>> -- 
>> Ankit
>> 
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Monorepo workflow using SPM

2016-11-09 Thread Daniel Dunbar via swift-users
(+ swift-build-dev)

Hi Georgios,

This is a very timely question, because I have been working on a proposal for 
solving exactly this problem.

Can you take a look at:
  
https://github.com/ddunbar/swift-evolution/blob/multi-package-repos/proposals/-swiftpm-multi-package-repos.md
and see if you feel it would meet your needs?

 - Daniel


> On Nov 3, 2016, at 10:08 PM, Georgios Moschovitis via swift-users 
>  wrote:
> 
>> It would be good if you can explainyour requirements/features/floware you 
>> looking for.
> 
> Well the flow is simple, just put all your packages in one root repository. I 
> guess, SPM could be updated to allow
> linking to a local dependency by file path, not only by Git tag. 
> 
> Actually this feature would be useful even when developing multiple dependent 
> packages in separate repos. Currently you have to create new tags and refetch 
> all the time when you work on multiple packages at the same time, a small 
> annoyance.
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Package Manager and Git submodules

2016-10-30 Thread Daniel Dunbar via swift-users

> On Oct 29, 2016, at 7:22 AM, Anton Bronnikov  wrote:
> 
> Thanks, Daniel.
> 
> Yes, on Oct-27 snapshot `Swift version 3.0-dev (LLVM b52fce3ab4, Clang 
> 4edf31e82f, Swift bf2de4a41c)` if I build with `swift build 
> --enable-new-resolver` then I do get the expected behaviour.  Building with 
> usual `swift build` gets me an old - wrong - one.
> 
> It’s an experimental feature at the moment, right (e.g. I can not invoke 
> `swift package fetch --enable-new-resolver`).

You should be able to use it almost everywhere, but yes it isn't on by default 
because there are a couple pieces not done.

>  Will it be in 3.1?

We are working to switch over to it ASAP, but I don't know exactly when that 
will happen. I hope w/in a month or two.

 - Daniel

> 
> Thank you.
> Cheers,
> Anton
> 
>> On 29 Oct 2016, at 00:18, Daniel Dunbar  wrote:
>> 
>> This sounds like a bug to me, I suspect that the current code isn't causing 
>> the submodule to update appropriately.
>> 
>> If you have a working example, can you try using the latest OSS snapshot 
>> from swift.org, and running:
>> swift package reset
>> swift build --enable-new-resolver
>> and seeing if you get the behavior you expect?
>> 
>> - Daniel
>> 
>>> On Oct 28, 2016, at 1:53 PM, Anton Bronnikov via swift-users 
>>>  wrote:
>>> 
>>> Hi,
>>> 
>>> I have a question whether what I observe is by-design, a bug, or not yet 
>>> fully implemented feature in Swift Package Manager.
>>> 
>>> - Let’s say, I have a C repository with some library, and it has two 
>>> versions tagged, namely 0.0.1 and 0.0.2.
>>> - Then I have a Swift repository that includes the above as a submodule, 
>>> provides necessary files and exports C functionality into Swift.  This one 
>>> also has two versions tagged, 0.0.1 and 0.0.2, each matching corresponding 
>>> version within C repository.
>>> - Finally, I have an application in Swift, that uses the wrapper package as 
>>> a dependency and specifies 0.0.1 as the desired version.
>>> 
>>> Normally, I would expect that `swift build` would have PM to check out 
>>> 0.0.1/0.0.1 versions of the repositories (SwiftWrapper/CLibrary).  However, 
>>> in fact what I get is 0.0.1/0.0.2 (in other words, I get the right - older 
>>> - version of the wrapper package, but wrong - new - version of the C 
>>> submodule).
>>> 
>>> The use case is to “escort” a C library that is being continuously 
>>> developed and used as such (e.g. in Linux community) with its Swift bridge 
>>> without having to copy-paste the sources from the original repo into the 
>>> mirror (so that the Swift wrapper would only provide the Package.swift, 
>>> public header file, and possible a modulemap).
>>> 
>>> If there are other (better) way to do this, I will be glad to hear.
>>> 
>>> Thanks for the help.
>>> Cheers,
>>> Anton
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Package Manager and Git submodules

2016-10-28 Thread Daniel Dunbar via swift-users
This sounds like a bug to me, I suspect that the current code isn't causing the 
submodule to update appropriately.

If you have a working example, can you try using the latest OSS snapshot from 
swift.org, and running:
  swift package reset
  swift build --enable-new-resolver
and seeing if you get the behavior you expect?

 - Daniel

> On Oct 28, 2016, at 1:53 PM, Anton Bronnikov via swift-users 
>  wrote:
> 
> Hi,
> 
> I have a question whether what I observe is by-design, a bug, or not yet 
> fully implemented feature in Swift Package Manager.
> 
> - Let’s say, I have a C repository with some library, and it has two versions 
> tagged, namely 0.0.1 and 0.0.2.
> - Then I have a Swift repository that includes the above as a submodule, 
> provides necessary files and exports C functionality into Swift.  This one 
> also has two versions tagged, 0.0.1 and 0.0.2, each matching corresponding 
> version within C repository.
> - Finally, I have an application in Swift, that uses the wrapper package as a 
> dependency and specifies 0.0.1 as the desired version.
> 
> Normally, I would expect that `swift build` would have PM to check out 
> 0.0.1/0.0.1 versions of the repositories (SwiftWrapper/CLibrary).  However, 
> in fact what I get is 0.0.1/0.0.2 (in other words, I get the right - older - 
> version of the wrapper package, but wrong - new - version of the C submodule).
> 
> The use case is to “escort” a C library that is being continuously developed 
> and used as such (e.g. in Linux community) with its Swift bridge without 
> having to copy-paste the sources from the original repo into the mirror (so 
> that the Swift wrapper would only provide the Package.swift, public header 
> file, and possible a modulemap).
> 
> If there are other (better) way to do this, I will be glad to hear.
> 
> Thanks for the help.
> Cheers,
> Anton
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] how to ``swift build`` C library cleanly without using -Xcc -Xlinker and -Xswiftc

2016-10-20 Thread Daniel Dunbar via swift-users

> On Oct 20, 2016, at 7:25 AM, Martin Man via swift-users 
>  wrote:
> 
> Hi guys,
> 
> I’m wrapping three little native C libraries using SPM to a nice swifty 
> modules. Say cmod1, cmod2, and cmod3. They all in the and are dependencies of 
> a bigger project.
> 
> Since these legacy C libraries have headers in various ways incompatible with 
> SPM I’m also providing my own custom module.modulemap inside of 
> Sources/cmod1/include folder which exports only certain headers.
> 
> The module.modulemap is in pretty standard form with relative path to the 
> header
> 
> module cmod1 {
> header “cmod1/header1.h”
> export “*”
> link “cmod1"
> } 
> 
> When using ``swift build`` to build the module, C sources compile fine but 
> switc bails out when parsing modulemap because it can not find headers 
> referenced from header1.h with an error message like this
> 
> :1:10: note: in file included from :1:
> #include “/projects/something/Sources/cmod1/include/cmod/header1.h"

Is this misspelled? cmod/header1.h vs cmod1/header1.h?

Can you show the exact include style used in the module.modulemap and in the 
project?

>  ^
> /projects/something/Sources/cmod1/include/cmod1/header1.h:18:10: error: 
> ‘cmod1/header2.h' file not found
> 
> Now I know that I can give swiftc correct -Xswiftc -Ipath switch and then it 
> builds cleanly, but this means that plain ``swift build`` never succeeds…
> 
> Q1: Is my assumption correct that the ultimate goal of mine is to make the 
> swift package build cleanly using just ``swift build`` without providing any 
> commandline flags?

Yes.

> Q2: When build of a certain package cmod1 requires command line flags -Xcc 
> -Xlinker and -Xswiftc, what’s the correct way to pass them in when such 
> package is a dependency of bigger project and which gets git pulled and 
> compiled as part of outer package build?

We don't have a solution for this yet, eventually we want to find a way that 
all that data has a proper home in the manifest.

 - Daniel

> 
> thanks for your time, unfortunately the sources of these packages can not be 
> made public yet but I think I can generate a simple broken project on github 
> if anyone wants to take a look...
> 
> thanks,
> Martin
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Package Manager questions

2016-10-17 Thread Daniel Dunbar via swift-users
Hi Ed,

No, the package manager in the Xcode 8.1 beta only has minimal bug fixes.

You can, however, get this by grabbing a snapshot toolchain from 
http://swift.org/download.

 - Daniel

> On Oct 17, 2016, at 12:10 PM, Edward Connell via swift-users 
>  wrote:
> 
> Thanks Ankit,
> Should I be able to pick up that change with Xcode 8.1 beta 3 (latest)? Oct 
> 10th.
> 
> Ed
> 
> On Mon, Oct 17, 2016 at 11:42 AM, Ankit Agarwal  > wrote:
> Hi,
> 
> Currently in Swift 3 release of SwiftPM, you cannot override this setting. 
> A proper solution to this problem is yet to be built in SwiftPM however in 
> the mean time this patch was landed to allow overrides by passing custom 
> args: https://github.com/apple/swift-package-manager/pull/715 
> 
> It is available in a recent trunk snapshot from swift.org 
> 
> Also, while passing custom arguments to swift build, escape each argument 
> with the prefix eg: 
> `-Xswiftc -target x86_64-apple-macosx10.12`  should be: `-Xswiftc -target 
> -Xswiftc x86_64-apple-macosx10.12`
> 
> 
> On Mon, Oct 17, 2016 at 5:23 AM, Edward Connell via swift-users 
> > wrote:
> Hi, I've written a Swift (with some C) framework the builds and runs cleanly 
> in Xcode 8. 
> A critical feature of my project is for my framework to run on MacOS, iOS, 
> and Linux.
> I am trying to figure out how to build using the SPM so I can run on Ubuntu.
> I'm not so happy with the project structure now, but at least I think I am 
> almost there.
> 
> I've hit a sticking point that I can't seem to figure out. The SPM sets the 
> target SDK to 10.10 by default.
> Features in Swift 3.0 that I am using require at least 10.11. When I type:
> 
> swift build -Xcc -I/usr/local/include -Xswiftc -j4 -Xlinker -L/usr/local/lib 
> -Xlinker -lpng -Xlinker -ljpeg
> 
> The build bombs with:
> 
> "... error: 'init(fileURLWithPath:relativeTo:)' is only available on OS X 
> 10.11 or newer"
> 
> How do I set the correct OS version??
> 
> I looked at the Xcode settings and tried to pass them through, but there 
> seems to be an argument parsing error by SPM.
> I am currently trying:
> 
> swift build -Xcc -I/usr/local/include -Xswiftc -j4 -Xswiftc -sdk 
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
>  -Xswiftc -target x86_64-apple-macosx10.12 -Xlinker -L/usr/local/lib -Xlinker 
> -lpng -Xlinker -ljpeg
> 
> And I get:
> 
> error: unknown command: 
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
> So it seems it thinks the parameter is a command. 
> 
> How do you set the sdk and target versions through swift build to fix this 
> problem?
> 
> Thanks, Ed
> 
> 
> 
> Configuration:
> 
> MacBook Pro (Retina, 13-inch, Early 2015)
> 
> Sierra 10.12 (16A323)
> 
> Xcode Version 8.0 (8A218a)
> 
> 
> 
> 
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> 
> 
> 
> 
> -- 
> Ankit
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Counting in Threads

2016-10-12 Thread Daniel Dunbar via swift-users
Not in this case, today:
--
$ cat x.swift 
import Darwin.C

public class AtomicInt32 {
   public fileprivate (set) var value : Int32 = 0

   /// Create a new atomic integer with the specified initial value.
   public init(_ value: Int32 = 0) {
   self.value = value
   }

   /// Add one to the value.
   public func increment () {
   OSAtomicIncrement32()
   }
}

$ swiftc -S -o - x.swift -O | grep '.globl  
__TFC4main11AtomicInt329incrementfT_T_' -A16
.globl  __TFC4main11AtomicInt329incrementfT_T_
.align  4, 0x90
__TFC4main11AtomicInt329incrementfT_T_:
.cfi_startproc
pushq   %rbp
Ltmp4:
.cfi_def_cfa_offset 16
Ltmp5:
.cfi_offset %rbp, -16
movq%rsp, %rbp
Ltmp6:
.cfi_def_cfa_register %rbp
leaq16(%rdi), %rsi
movl$1, %edi
popq%rbp
jmp _OSAtomicAdd32
.cfi_endproc
--

 - Daniel

> On Oct 12, 2016, at 8:31 AM, Philippe Hausler <phaus...@apple.com> wrote:
> 
> I was under the impression that taking the address was more than a single 
> load instruction and would emit a placeholder invalid value: which would make 
> that technically unsafe in a threaded context.
> 
> Sent from my iPhone
> 
> On Oct 12, 2016, at 8:18 AM, Daniel Dunbar via swift-users 
> <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:
> 
>> I suspect one of the actual compiler people might tell me I shouldn't trust 
>> this, but in practice it works:
>> --
>> import Darwin.C
>> 
>> public class AtomicInt32 {
>>public fileprivate (set) var value : Int32 = 0
>> 
>>/// Create a new atomic integer with the specified initial value.
>>public init(_ value: Int32 = 0) {
>>self.value = value
>>}
>> 
>>/// Add one to the value.
>>public func increment () {
>>OSAtomicIncrement32()
>>}
>> }
>> 
>> public func +=(int: AtomicInt32, value: Int32) {
>>OSAtomicAdd32(value, )
>> }
>> --
>> 
>> Would also love to know if compiler guarantees I *can* trust this.
>> 
>> Note that this has to be a class for this to be in any way safe, which means 
>> it is also rather inefficient if the use case was having a lot of them.
>> 
>> - Daniel
>> 
>>> On Oct 12, 2016, at 12:47 AM, Gerriet M. Denkmann via swift-users 
>>> <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:
>>> 
>>> 
>>> How to translate this to Swift:
>>> 
>>> __block atomic_uint_fast64_t counter = ATOMIC_VAR_INIT(0);
>>> dispatch_apply( nbrInterations, queue, ^void(size_t idx)
>>>{
>>>uint64_t tCount = 0;
>>>... do some counting ...
>>>atomic_fetch_add_explicit( , tCount, memory_order_relaxed );
>>>}
>>> )
>>> 
>>> Currently I am using:
>>> 
>>> var counter: UInt64 = 0
>>> let dsema = DispatchSemaphore(value: 1)  
>>> DispatchQueue.concurrentPerform( iterations: nbrInterations )
>>> { ( idx: size_t) -> Void in
>>>
>>>var tCount: UInt64 = 0
>>>... do some counting ...
>>>_ = dsema.wait(timeout: .distantFuture) 
>>>counter += tCount;
>>>dsema.signal()  
>>> }
>>> 
>>> Is there a better way?
>>> 
>>> Gerriet.
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org <mailto:swift-users@swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> <https://lists.swift.org/mailman/listinfo/swift-users>
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org <mailto:swift-users@swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> <https://lists.swift.org/mailman/listinfo/swift-users>

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Counting in Threads

2016-10-12 Thread Daniel Dunbar via swift-users
I suspect one of the actual compiler people might tell me I shouldn't trust 
this, but in practice it works:
--
import Darwin.C

public class AtomicInt32 {
public fileprivate (set) var value : Int32 = 0

/// Create a new atomic integer with the specified initial value.
public init(_ value: Int32 = 0) {
self.value = value
}

/// Add one to the value.
public func increment () {
OSAtomicIncrement32()
}
}

public func +=(int: AtomicInt32, value: Int32) {
OSAtomicAdd32(value, )
}
--

Would also love to know if compiler guarantees I *can* trust this.

Note that this has to be a class for this to be in any way safe, which means it 
is also rather inefficient if the use case was having a lot of them.

 - Daniel

> On Oct 12, 2016, at 12:47 AM, Gerriet M. Denkmann via swift-users 
>  wrote:
> 
> 
> How to translate this to Swift:
> 
> __block atomic_uint_fast64_t counter = ATOMIC_VAR_INIT(0);
> dispatch_apply( nbrInterations, queue, ^void(size_t idx)  
>   {
>   uint64_t tCount = 0;
>   ... do some counting ...
>   atomic_fetch_add_explicit( , tCount, 
> memory_order_relaxed );
>   }
> )
> 
> Currently I am using:
> 
> var counter: UInt64 = 0
> let dsema = DispatchSemaphore(value: 1)  
> DispatchQueue.concurrentPerform( iterations: nbrInterations )
> { ( idx: size_t) -> Void in
>   
>   var tCount: UInt64 = 0
>   ... do some counting ...
>   _ = dsema.wait(timeout: .distantFuture) 
>   counter += tCount;
>   dsema.signal()  
> }
> 
> Is there a better way?
> 
> Gerriet.
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Package Manager (SPM) Deployment Target

2016-09-26 Thread Daniel Dunbar via swift-users
There isn't yet a builtin way to manage this. When generating an Xcode project, 
you can use the undocumented `--xcconfig-overrides` option to pass a path to an 
extra .xcconfig file you wish to include in the project and have build settings 
read from. You could then override the deployment target there.

See also:
  
https://lists.swift.org/pipermail/swift-build-dev/Week-of-Mon-20160919/000636.html

 - Daniel

> On Sep 24, 2016, at 4:44 PM, Gmail via swift-users  
> wrote:
> 
> Does anyone know if it’s possible to set the deployment target when building 
> with the Swift Package Manager (SPM)? From what I can tell, it is not 
> currently possible to override it based on the source code itself. In the 
> pbxproj().swift 
> 
>  file, the MACOSX_DEPLOYMENT_TARGET is hardcoded to 10.10 with a FIXME saying 
> it needs to be configurable. 
> 
> If this currently cannot be overridden, then I’d like to file a feature 
> request so we can build Alamofire 4.0.0 with the SPM. If it can be 
> overridden, I’d really appreciate someone letting me know how.
> 
> Thanks in advance!
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Stored Property on Protocol Extension

2016-09-12 Thread Daniel Dunbar via swift-users

> On Sep 11, 2016, at 6:12 PM, Tanner Nelson via swift-users 
>  wrote:
> 
> Hey Swift Users,
> 
> I was wondering how you all work around not being able to add stored 
> properties in extensions (especially protocol extensions).
> 
> I ran into an issue recently where I needed an internal stored variable for a 
> protocol, but I didn't want the conformer to worry about implementing the 
> variable.
> 
> I ended up using something like this to achieve the effect.
> 
>extension MyProtocol {
>private var address: String {
>mutating get {
>var id = ""
>withUnsafePointer(to: ) { id = "\($0)"}
>return id

BTW, you can write `return withUnsafePointer(to: ) { "\($0)" }` instead.

>}
>}
> 
>var myStoredVar: Bool {
>mutating get {
>return _storage[address] ?? false
>}
>set {
>_storage[address] = newValue
>}
>}
>}
> 
> Obviously not ideal, but I don't see another way to achieve this besides 
> subclassing (which has its own problems for my situation).
> 
> Wondering if anyone has run into this and come up with a better solution or 
> other type of work around.

I don't have a better answer to this part.

This particular solution only works if it is ok for `_storage[address]` to 
potentially be reused by a new instance, though (if the old instance is 
deallocated and the new one is allocated in its place).

 - Daniel

> 
> Thanks!
> Tanner
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Statically linked binaries on linux

2016-09-01 Thread Daniel Dunbar via swift-users
We don't currently build static versions of the other libraries (Foundation, 
XCTest), or a support process for picking them up.

This is covered by:
  https://bugs.swift.org/browse/SR-648

As you note, it largely works for Swift-only, so this is feasible but we need 
someone to drive it. Are you interested in working on it?

 - Daniel

> On Sep 1, 2016, at 9:13 AM, Joel Hughes via swift-users 
>  wrote:
> 
> Hi,
> 
> I'm attempting to get a statically linked binary and am running into errors.
> 
> I'm using Swift 3 Preview 6 on Ubuntu.
> 
> Regular _swift build_ and _swift test_ are all running fine.
> 
> I can produce a static binary for a simple "hello world" using:
> 
> swift build -c release -Xswiftc -static-stdlib
> 
> (although I do get error while loading shared libraries: libicui18n.so.55 
> when running in a basic vm).
> 
> However I can't compile a more complicated project. It's only dependency is 
> Foundation (it uses NSUUID, and JSON) and can't seem to find them.
> 
> I get a stream of errors, examples:
> 
> Linking ./.build/release/joke
> /usr/bin/ld.gold: error: cannot find -lFoundation
> ...
> error: undefined reference to '_TMaC10Foundation6NSUUID'
> ...
> error: undefined reference to 
> '_TFC10Foundation6NSUUIDCfT10uuidStringSS_GSqS0__'
> 
> Any pointers or advice much appreciated.
> 
> Thanks
> 
> Joel
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Updating the swift.org examples

2016-08-18 Thread Daniel Dunbar via swift-users
Hi Joel,

Thank you for pointing this out!

> On Aug 18, 2016, at 3:14 AM, Joel Hughes via swift-users 
>  wrote:
> 
> Morning all,
> 
> I've just upgraded to Swift 3 Preview 6 for Ubuntu and have noticed a few 
> changes.
> 
> First using XCTest: "the name of a test module has no ‘Tests’ suffix" - easy 
> to follow the error message, good stuff!
> 
> And also reading command line args:
> 
> Process.arguments
> 
> Now available at: ProcessInfo.processInfo().arguments
> 
> This one is on the swift.org  home page, I'm happy to to 
> make changes and pull request but not sure if this is how the page is 
> constructed?

The sources for the website are not publicly available, so unfortunately no PR 
is possible. Would you mind filing a bug at bugs.swift.org for this so we can 
assign someone to fix it?

> Also I couldn't easily locate release notes for the latest changes, where's a 
> good place to look?

The CHANGELOGs for each project are one place you can look:
  https://github.com/apple/swift/blob/master/CHANGELOG.md
  https://github.com/apple/swift-package-manager/blob/master/CHANGELOG.md

 - Daniel

> Thanks
> 
> Joel
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] repo questions when using example-package-dealer

2016-06-30 Thread Daniel Dunbar via swift-users
I wouldn't say they are "unclean", but they have not been retagged after the 
latest commits to them, and you are right they probably should be. Feel free to 
file a bug on this at http://bugs.swift.org .

 - Daniel

> On Jun 29, 2016, at 11:25 PM, Dave Yost  wrote:
> 
> Dumb questions:
> 
> These repos are not clean, tho, right? The head should be tagged with a 
> version number, right?
> 
>> On 2016-06-29, at 7:56 PM, Daniel Dunbar > > wrote:
>> 
>> FYI, some of our planned workflow improvements here are covered by:
>>   
>> https://github.com/apple/swift-evolution/blob/master/proposals/0082-swiftpm-package-edit.md
>>  
>> 
>> 
>>  - Daniel
>> 
>>> On Jun 29, 2016, at 7:11 PM, Hugo Hennies via swift-users 
>>> > wrote:
>>> 
>>> The swift package manager uses git tags to resolve the commit it’s going to 
>>> get. So if you want to make your changes available to the package manager, 
>>> you must tag your latest commit with a semantic versioning number (1.0.3 
>>> for instance) and explicitly put that as the version you want to fetch in 
>>> your Package.swift file.
>>> 
>>> You can find more information on the swift project website
>>> https://swift.org/package-manager/ 
>>> 
>>> —H
>>> 
 On Jun 29, 2016, at 10:43 PM, Dave Yost via swift-users 
 > wrote:
 
 Following the example here:
 https://swift.org/package-manager/#conceptual-overview 
 
 
 When I do “swift build”, as expected the dependencies are downloaded into 
 the Packages/ subfolder. I expect them to all be up to date, but they are 
 all behind their origin/master repos. Why?
 
 This is really a problem when I clone theses 4 projects and modify the 
 dependencies to point to my clones. When I do that, the DeckOfPlayingCards 
 project doesn’t download with my changes.
 
 0 Wed 18:30:30 yost DaveBook ~/p/swift
 421 Z% git clone g...@github.com:apple/example-package-dealer.git
 Cloning into 'example-package-dealer'...
 remote: Counting objects: 21, done.
 remote: Total 21 (delta 0), reused 0 (delta 0), pack-reused 21
 Receiving objects: 100% (21/21), 7.03 KiB | 0 bytes/s, done.
 Resolving deltas: 100% (8/8), done.
 Checking connectivity... done.
 0 Wed 18:30:40 yost DaveBook ~/p/swift
 422 Z% cd example-package-dealer 
 0 Wed 18:30:42 yost DaveBook ~/p/swift/example-package-dealer
 423 Z% swift build
 Cloning https://github.com/apple/example-package-deckofplayingcards.git 
 
 HEAD is now at 0879cff Merge pull request #1 from kostiakoval/master
 Resolved version: 1.0.4
 Cloning https://github.com/apple/example-package-fisheryates.git 
 
 HEAD is now at d3752ab Merge pull request #5 from 
 contraultra/random-for-all
 Resolved version: 1.1.0
 Cloning https://github.com/apple/example-package-playingcard.git 
 
 HEAD is now at 7986c83 Remove: `targets: []`
 Resolved version: 1.0.1
 Compile Swift Module 'FisherYates' (2 sources)
 Compile Swift Module 'PlayingCard' (3 sources)
 Compile Swift Module 'DeckOfPlayingCards' (1 sources)
 Compile Swift Module 'Dealer' (1 sources)
 Linking .build/debug/Dealer
 0 Wed 18:30:52 yost DaveBook ~/p/swift/example-package-dealer
 424 Z% .build/debug/Dealer
 ♣︎7
 ♢A
 ♡A
 ♠︎Q
 ♣︎5
 ♢6
 ♣︎8
 ♢8
 ♢Q
 ♣︎4
 0 Wed 18:30:59 yost DaveBook ~/p/swift/example-package-dealer
 425 Z% cd Packages/PlayingCard-1.0.1 
 0 Wed 18:31:28 yost DaveBook 
 ~/p/swift/example-package-dealer/Packages/PlayingCard-1.0.1
 430 Z% git status
 On branch 1.0.1
 Your branch is behind 'origin/master' by 4 commits, and can be 
 fast-forwarded.
   (use "git pull" to update your local branch)
 nothing to commit, working directory clean
 0 Wed 18:31:31 yost DaveBook 
 ~/p/swift/example-package-dealer/Packages/PlayingCard-1.0.1
 431 Z% git remote -v  
 origin https://github.com/apple/example-package-playingcard.git 
  (fetch)
 origin https://github.com/apple/example-package-playingcard.git 
  (push)
 0 Wed 18:35:57 yost DaveBook 
 ~/p/swift/example-package-dealer/Packages/PlayingCard-1.0.1
 432 Z% cd ../FisherYates-1.1.0
 0 Wed 18:36:19 yost DaveBook 
 

Re: [swift-users] repo questions when using example-package-dealer

2016-06-29 Thread Daniel Dunbar via swift-users
FYI, some of our planned workflow improvements here are covered by:
  
https://github.com/apple/swift-evolution/blob/master/proposals/0082-swiftpm-package-edit.md
 


 - Daniel

> On Jun 29, 2016, at 7:11 PM, Hugo Hennies via swift-users 
>  wrote:
> 
> The swift package manager uses git tags to resolve the commit it’s going to 
> get. So if you want to make your changes available to the package manager, 
> you must tag your latest commit with a semantic versioning number (1.0.3 for 
> instance) and explicitly put that as the version you want to fetch in your 
> Package.swift file.
> 
> You can find more information on the swift project website
> https://swift.org/package-manager/ 
> 
> —H
> 
>> On Jun 29, 2016, at 10:43 PM, Dave Yost via swift-users 
>> > wrote:
>> 
>> Following the example here:
>> https://swift.org/package-manager/#conceptual-overview 
>> 
>> 
>> When I do “swift build”, as expected the dependencies are downloaded into 
>> the Packages/ subfolder. I expect them to all be up to date, but they are 
>> all behind their origin/master repos. Why?
>> 
>> This is really a problem when I clone theses 4 projects and modify the 
>> dependencies to point to my clones. When I do that, the DeckOfPlayingCards 
>> project doesn’t download with my changes.
>> 
>> 0 Wed 18:30:30 yost DaveBook ~/p/swift
>> 421 Z% git clone g...@github.com:apple/example-package-dealer.git
>> Cloning into 'example-package-dealer'...
>> remote: Counting objects: 21, done.
>> remote: Total 21 (delta 0), reused 0 (delta 0), pack-reused 21
>> Receiving objects: 100% (21/21), 7.03 KiB | 0 bytes/s, done.
>> Resolving deltas: 100% (8/8), done.
>> Checking connectivity... done.
>> 0 Wed 18:30:40 yost DaveBook ~/p/swift
>> 422 Z% cd example-package-dealer 
>> 0 Wed 18:30:42 yost DaveBook ~/p/swift/example-package-dealer
>> 423 Z% swift build
>> Cloning https://github.com/apple/example-package-deckofplayingcards.git 
>> 
>> HEAD is now at 0879cff Merge pull request #1 from kostiakoval/master
>> Resolved version: 1.0.4
>> Cloning https://github.com/apple/example-package-fisheryates.git 
>> 
>> HEAD is now at d3752ab Merge pull request #5 from contraultra/random-for-all
>> Resolved version: 1.1.0
>> Cloning https://github.com/apple/example-package-playingcard.git 
>> 
>> HEAD is now at 7986c83 Remove: `targets: []`
>> Resolved version: 1.0.1
>> Compile Swift Module 'FisherYates' (2 sources)
>> Compile Swift Module 'PlayingCard' (3 sources)
>> Compile Swift Module 'DeckOfPlayingCards' (1 sources)
>> Compile Swift Module 'Dealer' (1 sources)
>> Linking .build/debug/Dealer
>> 0 Wed 18:30:52 yost DaveBook ~/p/swift/example-package-dealer
>> 424 Z% .build/debug/Dealer
>> ♣︎7
>> ♢A
>> ♡A
>> ♠︎Q
>> ♣︎5
>> ♢6
>> ♣︎8
>> ♢8
>> ♢Q
>> ♣︎4
>> 0 Wed 18:30:59 yost DaveBook ~/p/swift/example-package-dealer
>> 425 Z% cd Packages/PlayingCard-1.0.1 
>> 0 Wed 18:31:28 yost DaveBook 
>> ~/p/swift/example-package-dealer/Packages/PlayingCard-1.0.1
>> 430 Z% git status
>> On branch 1.0.1
>> Your branch is behind 'origin/master' by 4 commits, and can be 
>> fast-forwarded.
>>   (use "git pull" to update your local branch)
>> nothing to commit, working directory clean
>> 0 Wed 18:31:31 yost DaveBook 
>> ~/p/swift/example-package-dealer/Packages/PlayingCard-1.0.1
>> 431 Z% git remote -v  
>> origin   https://github.com/apple/example-package-playingcard.git 
>>  (fetch)
>> origin   https://github.com/apple/example-package-playingcard.git 
>>  (push)
>> 0 Wed 18:35:57 yost DaveBook 
>> ~/p/swift/example-package-dealer/Packages/PlayingCard-1.0.1
>> 432 Z% cd ../FisherYates-1.1.0
>> 0 Wed 18:36:19 yost DaveBook 
>> ~/p/swift/example-package-dealer/Packages/FisherYates-1.1.0
>> 433 Z% git status
>> On branch 1.1.0
>> Your branch is behind 'origin/master' by 2 commits, and can be 
>> fast-forwarded.
>>   (use "git pull" to update your local branch)
>> nothing to commit, working directory clean
>> 0 Wed 18:36:20 yost DaveBook 
>> ~/p/swift/example-package-dealer/Packages/FisherYates-1.1.0
>> 434 Z% git remote -v
>> origin   https://github.com/apple/example-package-fisheryates.git 
>>  (fetch)
>> origin   https://github.com/apple/example-package-fisheryates.git 
>>  (push)
>> 0 Wed 18:36:23 yost DaveBook 
>> ~/p/swift/example-package-dealer/Packages/FisherYates-1.1.0
>> 435 Z% cd 

Re: [swift-users] Clarification on the role of `CustomStringConvertible`

2016-06-29 Thread Daniel Dunbar via swift-users
Thanks for the pointers!

I agree with the motivation in the proposal, unfortunately this doesn't really 
help address the question of how to understand the current protocol though, 
unless I am mistaken?

 - Daniel

> On Jun 29, 2016, at 2:37 PM, Matthew Johnson <matt...@anandabits.com> wrote:
> 
>> 
>> On Jun 29, 2016, at 3:51 PM, Erica Sadun <er...@ericasadun.com> wrote:
>> 
>> On Jun 29, 2016, at 2:33 PM, Daniel Dunbar via swift-users 
>> <swift-users@swift.org> wrote:
>>> 
>>> I would like some clarification regarding the expected role of 
>>> `CustomStringConvertible` for types which have a natural, lossless, string 
>>> representation.
>> 
>> And this is why we started down the road towards clarifying that it wasn't 
>> convertible but a lossy representation. What you really want is a protocol 
>> that
>> represents an isomorphic relationship. RawRepresentable is about as close as 
>> you can get right now.
>> 
>> And "representation" in RawRepresentable actually means "isomorphic 
>> conversion
>> between types". (ish.)
>> 
>> -- E, paging Matthew Johnson to the SE-0041 courtesy phone
> 
> 
> RawRepresentable does not require isomorphism and in fact conforming types 
> *cannot* express isomorphm through conformances to this protocol due to the 
> failable initializer.  RawRepresentable expresses an injective conversion 
> making the inverse a partial function which is why the initializer is 
> failable (https://en.wikipedia.org/wiki/Injective_function 
> <https://en.wikipedia.org/wiki/Injective_function>).  RawRepresentable 
> conformance with a String `RawValue` is exactly the right way to express a 
> lossless String representation in Swift.  
> 
> Isomorphic relationships require a precise one-to-one correspondence between 
> values of two types (sets in mathematics).  They are usually bijective (I 
> didn’t know they aren’t always bijective until I consulted wikipedia!).  
> https://en.wikipedia.org/wiki/Isomorphism 
> <https://en.wikipedia.org/wiki/Isomorphism> 
> https://en.wikipedia.org/wiki/Bijection 
> <https://en.wikipedia.org/wiki/Bijection>
> 
> A good example of an isomorphism in Swift is CGFloat and Double on platforms 
> where CGFloat is a Double.  For any value of one you can convert to the other 
> and convert back to the original type without losing any information in 
> either direction.
> 
>> 
>> p.s. 
>> https://github.com/apple/swift-evolution/blob/master/proposals/0041-conversion-protocol-conventions.md
>> 
>> 
>>> I don't have good terminology to use here, but is the expectation that the 
>>> "textual string representation" is a readable description of the object? 
>>> This seems to correspond to the synthesized (?) default definition for 
>>> struct types, as well as some of the uses for Foundation types without 
>>> natural string representations (i.e. `Foundation.Notification` reports 
>>> something like "name = foo, object = ..., userInfo = ...").
>>> 
>>> Or, is the expectation that it provide a string *representation* of the 
>>> object, for objects where that makes sense. This corresponds to the use in 
>>> `Foundation.UUID`, or the example of `Point.description` from the stdlib's 
>>> `CustomStringConvertible` documentation.
>>> 
>>> Another way of phrasing this question is: for types which have a reversible 
>>> string representation, should I expect 
>>> `CustomStringConvertible.description` to give me a string I could use to 
>>> reconstruct an instance _without_ knowing its type?
>>> 
>>> And another way (my actual question) is, given a `struct Path` object which 
>>> contains a path string, what should `print(Path("a"))` print?
>>> 
>>> - Daniel
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Clarification on the role of `CustomStringConvertible`

2016-06-29 Thread Daniel Dunbar via swift-users
I would like some clarification regarding the expected role of 
`CustomStringConvertible` for types which have a natural, lossless, string 
representation.

I don't have good terminology to use here, but is the expectation that the 
"textual string representation" is a readable description of the object? This 
seems to correspond to the synthesized (?) default definition for struct types, 
as well as some of the uses for Foundation types without natural string 
representations (i.e. `Foundation.Notification` reports something like "name = 
foo, object = ..., userInfo = ...").

Or, is the expectation that it provide a string *representation* of the object, 
for objects where that makes sense. This corresponds to the use in 
`Foundation.UUID`, or the example of `Point.description` from the stdlib's 
`CustomStringConvertible` documentation.

Another way of phrasing this question is: for types which have a reversible 
string representation, should I expect `CustomStringConvertible.description` to 
give me a string I could use to reconstruct an instance _without_ knowing its 
type?

And another way (my actual question) is, given a `struct Path` object which 
contains a path string, what should `print(Path("a"))` print?

 - Daniel

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] New Swift Snapshots Available!

2016-06-21 Thread Daniel Dunbar via swift-users
Can you reduce the problem to a small test case? Please file a bug report on 
bugs.swift.org  for this, and include information on 
the last toolchain which worked.

 - Daniel

> On Jun 21, 2016, at 5:16 AM, Charles Lane via swift-users 
>  wrote:
> 
> I’m running macOS Sierra. When I set ios 10 as the deployment target, I get 
> an error: Command failed due to signal: Illegal instruction: 4
> It seems to build ok when using 9.3 or below as the build target.
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] SPM - point dependcies to branches

2016-06-20 Thread Daniel Dunbar via swift-users
As you have noticed, we don't have support for this yet.

Most requests of this nature are currently in our bug tracker, for example:
  https://bugs.swift.org/browse/SR-666

 - Daniel

> On Jun 20, 2016, at 6:14 AM, Anindha Parthy via swift-users 
>  wrote:
> 
> Hi,
> 
> I want to be able to point dependencies to branches or hashes. The open 
> source dependencies for my project don't have a tagged version that builds 
> for developer preview 1. It would save time to point at a branch.
> 
> Sorry if this point had been covered already, I wasn't quite sure where to 
> find feature proposals.
> 
> Thanks,
> 
> Anindha
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] String initializers and developer ergonomics

2016-05-09 Thread Daniel Dunbar via swift-users

> On May 9, 2016, at 10:28 AM, Jacob Bandes-Storch via swift-users 
>  wrote:
> 
> On Mon, May 9, 2016 at 10:25 AM, Joe Groff via swift-users 
> > wrote:
> 
> > On May 7, 2016, at 10:39 AM, Austin Zheng via swift-users 
> > > wrote:
> >
> > Hello Swift users,
> >
> > I wanted to run something past you folks and get some opinions/feedback.
> >
> > About a month ago on Hacker News I saw someone commenting about how Swift's 
> > string-handling code was unbearably slow (3 seconds to run a code sample, 
> > vs. 0.8 in Java). I asked him to provide the code, and he obliged. 
> > Unfortunately, I didn't have time to dig into it until this morning. The 
> > code in its entirety can be found here: 
> > https://gist.github.com/austinzheng/d6c674780a58cb63832c4df3f809e683 
> > 
> >
> > At line 26 we have the following code:
> >
> > result.append(begin == eos ? "" : String(cs[begin.. >
> > 'cs' is a UTF16 view into an input string, while 'result' is a [String]. 
> > When I profiled the code in Instruments, I noticed that it was spending 
> > significant time within the reflection machinery.
> >
> > It turns out that the initializer to make a String out of a utf16 view 
> > looks like this, and I believe this is the initializer the author intended 
> > to call:
> >
> > init?(_: String.UTF16View)
> >
> > However, the actual initializer being called was this String initializer in 
> > the Mirror code:
> >
> > public init(_ instance: Subject)
> >
> > This seems like a tricky gotcha for developers who aren't extremely 
> > familiar with both the String and reflection APIs. His code looked 
> > reasonable at a first glance and I didn't suspect anything was wrong until 
> > I profiled it. Even so, I only made the connection because I recognized the 
> > name of the standard library function from poking around inside the source 
> > files.
> >
> > What do other people think? Is this something worth worrying about, or is 
> > it so rare that it shouldn't matter? Also, any suggestions as to how that 
> > code sample might be improved would be appreciated - my naive first attempt 
> > wasn't any better.
> 
> This definitely strikes me as a problem. The String(_:) constructor is 
> very easy to call by accident if you're trying to hit another unlabeled 
> initializer. It also strikes me as not particularly "value-preserving", since 
> stringifying many types loses information. Perhaps we should propose giving 
> it a label, String(printing:) maybe?
> 
> +1

+1

 - Daniel

>  
> 
> -Joe
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] make swift compiler to use the precompiled module files

2016-04-29 Thread Daniel Dunbar via swift-users
Clang will cache these automatically, can you give more details on exactly what 
you are seeing?

 - Daniel

> On Apr 28, 2016, at 10:50 PM, Ramakrishna Mallireddy via swift-users 
>  wrote:
> 
> I have these precompiled module files generated every-time I run the swift 
> compiler.
> 
> _Builtin_stddef_max_align_t-1LMTETLX3WNFT.pcm
> CFNetwork-1UTIO6DPB9R5P.pcm
> CoreFoundation-CF8BGN41VJ11.pcm
> CoreGraphics-3SDFP08OX46EF.pcm
> CoreImage-3SDFP08OX46EF.pcm
> Darwin-4F8STAM1KXDF.pcm
> Foundation-2LQ7EQYFLQOP.pcm
> ...etc
> 
> How can I make the swift compiler to use these cache rather than compiling 
> the libraries again.
> 
> Thanks
> Ramakrishna
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] build swift-package-manager-0.1 Linux Swift 2.2

2016-04-07 Thread Daniel Dunbar via swift-users
+Lang

`swift build` currently uses the Swift interpreter to get the Package metadata 
from the Package.swift. That in turn uses the LLVM JIT. It may be that some of 
what Swift is using is not implemented in the JIT for this platform.

This is worth filing a bug on http://bugs.swift.org, if you haven't already.

 - Daniel

> On Apr 5, 2016, at 7:29 PM, CK TUNG via swift-users  
> wrote:
> 
> Hi
> I try to build swift-package-manager-0.1 from source in raspberry pi, build 
> success but with error on run as below
> 
> $ swift build
> Not implemented relocation type!
> UNREACHABLE executed at 
> /mnt/usbms/package-swift/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:453!
> Stack dump:
> 0.Program arguments: /usr/bin/swift -frontend -interpret 
> /home/pi/Package.swift -target armv7-unknown-linux-gnueabihf 
> -disable-objc-interop -I /usr/lib/swift/pm -module-name Package 
> -lPackageDescription 
> swift-build: ExitSignal
> 
> Thanks 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] swift build

2016-04-03 Thread Daniel Dunbar via swift-users
If you build swift yourself you need to point directly at swift-build. Most 
people grab the pre-built toolchains from swift.org to start trying things out. 
Have you seen the instructions here:
  https://swift.org/download/#using-downloads

 - Daniel

> On Apr 3, 2016, at 7:27 PM, Shawn Erickson via swift-users 
>  wrote:
> 
> It isn't very clear what you have done or what you are actually doing. The 
> path "path/to/bin/swift build" doesn't make much sense, it must be an example 
> trying to imply you need to supply the path to the actual swift command on 
> your system.
> 
> Review https://github.com/apple/swift-package-manager/blob/master/README.md 
> .
> 
> On my system with Xcode 7.3 installed as well as the 03-01 swift snapshot...
> 
> [shawnce:~/]
> [1:539]> xcodebuild -version
> Xcode 7.3
> Build version 7D175
> 
> [shawnce:~/]
> [1:540]> xcrun --find swift
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
> 
> [shawnce:~/]
> [1:541]> swift --version
> Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)
> Target: x86_64-apple-macosx10.9
> 
> [shawnce:~/]
> [1:542]> swift build
> error: unable to invoke subcommand: 
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build
>  (No such file or directory)
> 
> [shawnce:~/]
> [1:543]> export TOOLCHAINS=swift
> 
> [shawnce:~/]
> [1:544]> xcrun --find swift
> /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a.xctoolchain/usr/bin/swift
> 
> [shawnce:~/]
> [1:545]> swift --version
> Apple Swift version 3.0-dev (LLVM b361b0fc05, Clang 11493b0f62, Swift 
> 24a0c3de75)
> Target: x86_64-apple-macosx10.9
> 
> [shawnce:~/]
> [1:554]> swift build
> error: no Package.swift file found << which is expect since I don't have a 
> package in this directory.
> 
> 
> 
> On Sun, Apr 3, 2016 at 6:51 PM Dave Yost via swift-users 
> > wrote:
> This happens with the swift in Xcode 7.3 on 10.11.4, and it happens with the 
> swift I just built from http://github.com/apple/swift 
> 
> 
> $ /path/to/bin/swift build
> error: unable to invoke subcommand: /path-to/bin/swift-build (No such file or 
> directory)
> $
> 
> There is no file called “swift-build” anywhere on my system.
> 
> How do I fix this?
> 
> Thanks
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Sporadically undefined symbols during linking

2016-04-02 Thread Daniel Dunbar via swift-users
Are you saying that it fails about 75% of the time even when building from 
clean, or it fails overall 75% of the time and you have to build from clean to 
fix? In my experiments it always fails when building just ostrichframework. My 
guess is that if you build in the IDE you are seeing it sometimes stop based on 
one failure and other times stop based on another failure.

Can you open a bug on bugreporter.apple.com about this (and let me know the #), 
I do see some surprising behavior on your project.

 - Daniel

> On Apr 1, 2016, at 7:19 PM, Ryan Conway via swift-users 
>  wrote:
> 
> Hey swift-users,
> 
> I'm experiencing a linking issue that causes builds to sometimes complete and 
> sometimes fail, without code changes. I'm not sure if the problem is with 
> Swift, Xcode, or my usage of either.
> 
> My Xcode 7.3 project target is a Swift framework with no dependencies other 
> than Foundation. Compiling always succeeds, but linking fails about 75% of 
> the time with errors like the following:
> 
> Undefined symbols for architecture x86_64: 
> "__TWPuRx16ostrichframework11OperandTypexS_8ReadablexS_9WriteablewxPS1_8ReadTypezVs6UInt16wxPS2_9WriteTypezS4_ERRzS4_ERRzS4_ERRzSiERRzSiERRzSiERRzSirGVS_5DEC16x_S_11InstructionS_",
>  referenced from:
>   ostrichframework.Z80.getInstruction () -> ostrichframework.Instruction? 
> in Z80.o
> ld: symbol(s) not found for architecture x86_64
> 
> The other 25% of the time, the framework will be built fine, with its user 
> application working as expected.
> 
> Has anyone experienced issues like this, or does anyone have advice on 
> troubleshooting it? I've tried cleaning, deleting DerivedData, and building 
> on a different machine, to no avail.
> 
> If it helps, the failing project is "ostrichframework" found in the Xcode 
> workspace here: https://github.com/PumpMagic/ostrich 
> 
> 
> Any help is greatly appreciated.
> 
> Ryan
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Serious Issue with Project Preprocessor Build Setting, Xcode 7.3 and Swift.

2016-03-24 Thread Daniel Dunbar via swift-users
(+Jordan)

Jordan, did something change here? Were we previously getting these via the 
Clang importer in a way we aren't anymore?

 - Daniel

> On Mar 24, 2016, at 9:02 AM, James Campbell  wrote:
> 
> I've just attached one now. The preprocessor macro is specified in the build 
> settings.
> 
> In Xcode 7.2 these were imported and worked like they did in C i.e 
> API_VERSION=2 would be imported as a constant named API_VERSION and would be 
> a 2
> 
> In Xcode 7.3 it broke.
> 
> ___
> 
> James⎥Head Of CEO
> 
> ja...@supmenow.com ⎥supmenow.com 
> 
> Sup
> 
> Runway East
> 
> 
> 10 Finsbury Square
> 
> London
> 
> 
> EC2A 1AF 
> 
> 
> On Thu, Mar 24, 2016 at 3:54 PM, Daniel Dunbar  > wrote:
> Swift has never supported referring directly to macros, it only supports 
> "build configurations". I'm still not sure exactly what you have that could 
> have worked previously.
> 
> Can you please attach a complete project showing something which worked in 
> 7.2 and does not work now to the bug you filed?
> 
>  - Daniel
> 
>> On Mar 24, 2016, at 8:50 AM, James Campbell > > wrote:
>> 
>> To hold keys and api endpoints.
>> 
>> In the past for Objective-C I would have used it like this:
>> 
>> request.api_endpoint = MY_MACRO_ENDPOINT
>> 
>> And then when Swift was released I was able to do it in Xcode 7.2:
>> 
>> request.api_endpoint = MY_MACRO_ENDPOINT
>> 
>> But when using Xocde 7.3 I get this:
>> 
>> request.api_endpoint = MY_MACRO_ENDPOINT //MY_MACRO_ENDPOINT not defined.
>> 
>> 
>> ___
>> 
>> James⎥Head Of CEO
>> 
>> ja...@supmenow.com ⎥supmenow.com 
>> 
>> Sup
>> 
>> Runway East
>> 
>> 
>> 10 Finsbury Square
>> 
>> London
>> 
>> 
>> EC2A 1AF 
>> 
>> 
>> On Thu, Mar 24, 2016 at 3:40 PM, Daniel Dunbar > > wrote:
>> 
>>> On Mar 24, 2016, at 5:21 AM, James Campbell >> > wrote:
>>> 
>>> This is the "GCC_PREPROCESSOR_DEFINITIONS" build setting. This previously 
>>> imported into swift. But in Xcode 7.3 it no longer does this.
>> 
>> Ok, and exactly how are you trying to use them? Via an #if in C or via an 
>> #if in Swift?
>> 
>>  - Daniel
>> 
>>> 
>>> If I write the Macros in the bridging header they are imported but I would 
>>> ideally like to keep them in a build setting.
>>> 
>>> ___
>>> 
>>> James⎥Head Of CEO
>>> 
>>> ja...@supmenow.com ⎥supmenow.com 
>>> 
>>> Sup
>>> 
>>> Runway East
>>> 
>>> 
>>> 10 Finsbury Square
>>> 
>>> London
>>> 
>>> 
>>> EC2A 1AF 
>>> 
>>> 
>>> On Wed, Mar 23, 2016 at 11:23 PM, Daniel Dunbar >> > wrote:
>>> To follow on to what Joe said, can you provide more info about the exact 
>>> problem. Is this a C preprocessor definition that you expect to be 
>>> available in code imported by the Clang importer (i.e., bridging header 
>>> files, etc.), or is a a macro you are expecting to use within Swift itself? 
>>> And please let us know exactly which build setting you are referring to.
>>> 
>>> Thanks,
>>>  - Daniel
>>> 
>>> > On Mar 23, 2016, at 3:59 PM, Joe Groff via swift-users 
>>> > > wrote:
>>> >
>>> >
>>> >> On Mar 23, 2016, at 9:43 AM, James Campbell via swift-users 
>>> >> > wrote:
>>> >>
>>> >> We are experiencing an issue when compiling swift code under Xcode 7.3.
>>> >>
>>> >> Preprocessor macros specified in the Xcode Project aren't imported into 
>>> >> swift. Ones manually declared in code are imported fine.
>>> >>
>>> >> Specifying Xcode 7.3 to use the Xcode 7.2 toolchain (Swift 2.1 etc) has 
>>> >> no effect on this.
>>> >>
>>> >> This is preventing us from using Xcode 7.3 and being able to test for 
>>> >> 9.3. Anybody else getting this issue?
>>> >
>>> > The Swift and C family build settings in Xcode are distinct. Are you sure 
>>> > you set the -D flags in "Other Swift Flags" and not in the C build 
>>> > settings? Swift doesn't have preprocessor macros.
>>> >
>>> > -Joe
>>> >
>>> > ___
>>> > swift-users mailing list
>>> > swift-users@swift.org 
>>> > https://lists.swift.org/mailman/listinfo/swift-users 
>>> > 
>>> 
>>> 
>> 
>> 
> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Serious Issue with Project Preprocessor Build Setting, Xcode 7.3 and Swift.

2016-03-24 Thread Daniel Dunbar via swift-users
Swift has never supported referring directly to macros, it only supports "build 
configurations". I'm still not sure exactly what you have that could have 
worked previously.

Can you please attach a complete project showing something which worked in 7.2 
and does not work now to the bug you filed?

 - Daniel

> On Mar 24, 2016, at 8:50 AM, James Campbell  wrote:
> 
> To hold keys and api endpoints.
> 
> In the past for Objective-C I would have used it like this:
> 
> request.api_endpoint = MY_MACRO_ENDPOINT
> 
> And then when Swift was released I was able to do it in Xcode 7.2:
> 
> request.api_endpoint = MY_MACRO_ENDPOINT
> 
> But when using Xocde 7.3 I get this:
> 
> request.api_endpoint = MY_MACRO_ENDPOINT //MY_MACRO_ENDPOINT not defined.
> 
> 
> ___
> 
> James⎥Head Of CEO
> 
> ja...@supmenow.com ⎥supmenow.com 
> 
> Sup
> 
> Runway East
> 
> 
> 10 Finsbury Square
> 
> London
> 
> 
> EC2A 1AF 
> 
> 
> On Thu, Mar 24, 2016 at 3:40 PM, Daniel Dunbar  > wrote:
> 
>> On Mar 24, 2016, at 5:21 AM, James Campbell > > wrote:
>> 
>> This is the "GCC_PREPROCESSOR_DEFINITIONS" build setting. This previously 
>> imported into swift. But in Xcode 7.3 it no longer does this.
> 
> Ok, and exactly how are you trying to use them? Via an #if in C or via an #if 
> in Swift?
> 
>  - Daniel
> 
>> 
>> If I write the Macros in the bridging header they are imported but I would 
>> ideally like to keep them in a build setting.
>> 
>> ___
>> 
>> James⎥Head Of CEO
>> 
>> ja...@supmenow.com ⎥supmenow.com 
>> 
>> Sup
>> 
>> Runway East
>> 
>> 
>> 10 Finsbury Square
>> 
>> London
>> 
>> 
>> EC2A 1AF 
>> 
>> 
>> On Wed, Mar 23, 2016 at 11:23 PM, Daniel Dunbar > > wrote:
>> To follow on to what Joe said, can you provide more info about the exact 
>> problem. Is this a C preprocessor definition that you expect to be available 
>> in code imported by the Clang importer (i.e., bridging header files, etc.), 
>> or is a a macro you are expecting to use within Swift itself? And please let 
>> us know exactly which build setting you are referring to.
>> 
>> Thanks,
>>  - Daniel
>> 
>> > On Mar 23, 2016, at 3:59 PM, Joe Groff via swift-users 
>> > > wrote:
>> >
>> >
>> >> On Mar 23, 2016, at 9:43 AM, James Campbell via swift-users 
>> >> > wrote:
>> >>
>> >> We are experiencing an issue when compiling swift code under Xcode 7.3.
>> >>
>> >> Preprocessor macros specified in the Xcode Project aren't imported into 
>> >> swift. Ones manually declared in code are imported fine.
>> >>
>> >> Specifying Xcode 7.3 to use the Xcode 7.2 toolchain (Swift 2.1 etc) has 
>> >> no effect on this.
>> >>
>> >> This is preventing us from using Xcode 7.3 and being able to test for 
>> >> 9.3. Anybody else getting this issue?
>> >
>> > The Swift and C family build settings in Xcode are distinct. Are you sure 
>> > you set the -D flags in "Other Swift Flags" and not in the C build 
>> > settings? Swift doesn't have preprocessor macros.
>> >
>> > -Joe
>> >
>> > ___
>> > swift-users mailing list
>> > swift-users@swift.org 
>> > https://lists.swift.org/mailman/listinfo/swift-users 
>> > 
>> 
>> 
> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Package Manager: Linker Flags

2016-01-04 Thread Daniel Dunbar via swift-users
You can't do this via the package manager, but you can include "link" 
declarations in the module map itself which specify additional linker arguments 
to plumb through when that module is used. See:
  http://clang.llvm.org/docs/Modules.html#link-declaration

Here is a concrete example, which is how Swift knows to automatically link 
libpthread and libdl when Glibc is used:
  https://github.com/apple/swift/blob/master/stdlib/public/Glibc/module.map.in

 - Daniel

> On Jan 1, 2016, at 4:48 PM, Ilija Tovilo via swift-users 
>  wrote: 
> 
> Happy new year everyone! 
> 
> I’m writing a wrapper around the LLVM-C API for Swift and thought it’d be fun 
> to use the Swift Package Manager.
> So I created a repository for the module.modulemap that includes the relevant 
> .h files (as instructed in Documentation/SystemModules.md in the GitHub 
> repository).
> 
> The package itself compiles fine and building the project that includes it 
> works too, except that it doesn’t link. 
> The problem is that you have to pass some LLVM linker flags and I have no 
> idea how to do that with the Swift Package Manager.
> 
> I’ve searched the tutorials, documentation and the source code but couldn’t 
> find a solution.
> Is there a way to add linker flags / compile flags to your Package.swift file?
> 
> It would be helpful to pass those flags manually, at least until the package 
> manager is mature enough to handle those things on its own.
> 
> Thanks for the help!
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] How to define interdependent modules in a package?

2015-12-24 Thread Daniel Dunbar via swift-users
What we hope to do here eventually is have swiftpm "notice" when a build has 
failed because of a missing dependency, and then automatically help you update 
the manifest to include it.

This allows the dependency specifications to continue to be explicit, which 
some people believe is important for maintenance of a large project, while 
still having a relatively painless workflow for incremental development.

We don't yet have anyone actively working on this feature, though...

 - Daniel

> On Dec 23, 2015, at 6:50 AM, Pierre Monod-Broca via swift-users 
>  wrote:
> 
> It would be too costly to do that on each build, among other issues.
> 
> So you do have to add all imported stuff as dependencies.
> 
> If I recall correctly, SPM is planned to have an option to either list you 
> all your imports so you can populate your dependencies, or edit the package 
> manifest itself to add those dependencies.
> 
> -- 
> Pierre
> 
>> Le 23 déc. 2015 à 03:43, Tarun Joshi via swift-users > > a écrit :
>> 
>>> Is this in your package file?
>>> targets: [
>>>Target(
>>>name: "Foo",
>>>dependencies: [.Target(name: "Bar")]),
>>>Target(
>>>name: "Bar")
>> 
>> No. So for each module I write, I need to specify all the imported
>> stuff as dependency?
>> Shouldn't this be automatically picked in the build phase by seeing
>> imports in a file. Am I expecting too much?
>> 
>> 
>> -- 
>> Regards,
>> `Tarun`
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Linux: module for needs -fblocks to compile

2015-12-20 Thread Daniel Dunbar via swift-users

> On Dec 17, 2015, at 1:40 PM, Tom Sheffler via swift-users 
>  wrote:
> 
> I’m learning about Swift on Linux and using modules to wrap C libraries.  One 
> of the things I wanted to do was use libdispatch with blocks from Swift.  I 
> thought it would be easy to use a module to wrap .
> 
> I made a module called “CDispatch” with a module.modulemap like this
> 
> ===
> module CDispatch [system] {
> header "/usr/include/dispatch/dispatch.h"
> export *
> link "dispatch"
> }
> 
> 
> Then I created a little demo project called gcd4 whose Source/main.swift 
> prints some things and then uses a dispatch queue and a block to print a 
> message after 2 seconds delay.
> 
> =
> CDispatch.dispatch_after(time, queue, {
> print("Delayed!")
> })
> 
> 
> The entire project is checked in at https://github.com/sheffler/gcd4 
> 
> and the CDispatch module is checked in at 
> https://github.com/sheffler/CDispatch 
> 
> If I try to “swift build” the project, it almost works but reports that 
> dispatch_after is not found.  It seems that this function is not defined if 
> the “blocks" feature is not provided at compilation time.
> 
> 
> Compiling Swift Module 'gcd4' (1 sources)
> /home/sheffler/swift/gcd4/Sources/main.swift:42:1: error: module 'CDispatch' 
> has no member named 'dispatch_after'
> CDispatch.dispatch_after(time, queue, {
> ^ ~~
> :0: error: build had 1 command failures
> swift-build: exit(1): 
> ["/home/sheffler/src/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin/swift-build-tool",
>  "-f", "/home/sheffler/swift/gcd4/.build/debug/gcd4.o/llbuild.yaml”]
> 
> 
> I got the demo program to work by first using “swift build” to retrieve the 
> CDispatch module, and then manually running the compiler like this (and 
> including the “-Xcc -fblocks” arguments)
> 
> swiftc -v -o gcd4 Sources/main.swift -I .build/debug -j8 -Onone -g -Xcc 
> -fblocks -Xcc -F-module-map=Packages/CDispatch-1.0.0/module.modulemap -I 
> Packages/CDispatch-1.0.0 -I /usr/local/include
> 
> This is all pretty neat!  I’ve got blocks, dispatch queues and ARC on Ubuntu. 
>  I have one question and one remark.
> 
> - Am i missing something about how to create the CDispatch module?  Why can’t 
> “swift build” build this?

This is mostly an oversight, the libdispatch port has been coming up and you 
are perhaps the first person to try to integrate all of these things.

I'm not sure yet exactly how we should resolve this, it might be the case that 
swiftc should just default to enabling blocks support in the Clang importer. In 
any case, can you open a specific bug in JIRA for this issue?

> - Creating Git repositories for simple modules that wrap a single library and 
> include a header file or two seems like too much.  I would love to have been 
> able to create a sub-directory in my project with a modulemap that includes 
>  and links libdispatch.so

There will be an easier avenue to getting this working once we have some amount 
of C support in the package manager.

Even then, one pro of encouraging the separate definition of module map 
packages is so that they can be used by other people. It is cumbersome until we 
have a the ecosystem of those packages (and easy ways for people to find them), 
but it would be worse if they never ever ended up being shared.

 - Daniel

> 
> Thanks
> Tom
> 
> P.S. - I tried to make this easy to check out and compile
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Using Swift for interpreted shell scripts?

2015-12-16 Thread Daniel Dunbar via swift-users

> On Dec 16, 2015, at 7:21 AM, @lbutlr via swift-users  
> wrote:
> 
> On 15 Dec 2015, at 14:12, John Regner  wrote:
>> Check out this talk from Ayaka on just this topic! 
>> https://realm.io/news/swift-scripting/
> 
> Thank you, that looks very promising.
> 
> I didn’t realize the list was set to “reply off list” so a message I thought 
> I posted didn’t go through. Rather than repost it…
> 
> On Dec 15, 2015, at 12:59 PM, David Turnbull  wrote:
>> There's this shebang for OS X:
>> #!/usr/bin/env xcrun swift
> 
> Interesting. I was just messing around with
> 
> #!/usr/bin/swift
> 
> And making some (albeit slow) progress.
> 
> ===
> 
> Is there a reason to use xcrun instead of calling swift directly?

Probably not. You can just call `swift` and it will shim through to the same 
thing as `xcrun swift`.

IIRC, 10.9 didn't have the `swift` shim, but every OS X release since then has.

 - Daniel

> 
> -- 
> 'But you ain't part of it, are you?' said Granny conversationally. 'You
> try, but you always find yourself watchin' yourself watchin' people, eh?
> Never quite believin' anything? Thinkin' the wrong thoughts?'
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] memory requirements for building swift on linux?

2015-12-14 Thread Daniel Dunbar via swift-users
For those hitting this issue, you might try building without debug info to see 
if that helps (build-script -R).

 - Daniel

> On Dec 14, 2015, at 6:55 AM, Kevin Lundberg via swift-users 
>  wrote:
> 
> I was able to build it on my 8GB macbook successfully, but there may be 
> platform differences there that caused that.
> 
> It seems that 4GB isn't enough either, fails when linking clang-3.8. I'll 
> have to figure something else out for linux for me. Thanks!
> 
> On 12/14/2015 9:30 AM, Tobias Scholze wrote:
>> Hi,
>> to build Swift from the sources I used a 16 GB bare metal machine and it was 
>> not enough.
>> So I think, you need a lot of memory ( > 16 GB) to have fun while building 
>> it.
>> 
>> - Toby
>> 
>> Kevin Lundberg via swift-users < 
>> swift-users@swift.org 
>> > schrieb am Mo., 14. Dez. 2015 um 15:03 Uhr:
>> Hi All,
>> 
>> I've set up a linux VM (ubuntu 15.10) in virtualbox on my windows PC to
>> build and test swift on linux, but I've been unable to successfully
>> build it to completion. I have all the repos including the corelibs
>> cloned locally, and have followed all the steps as far as I know for
>> installing dependencies. Every time I build, it fails somewhere during
>> linking, the last time failing when  linking "CXX shared library
>> lib/libLTO.so".
>> 
>> I don't have the full error, but I'm curious if there's some RAM
>> requirement for building swift. My VM had 2GB, and I just bumped it up
>> to 4GB to try again. Has anyone else run into this, and is there a
>> recommended minimum needed to successfully build swift with? Could
>> something else be the cause here instead of RAM if 2GB is in fact enough?
>> 
>> Thanks!
>> 
>> -Kevin
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Instantiate Swift class from string

2015-12-10 Thread Daniel Dunbar via swift-users

> On Dec 10, 2015, at 1:01 PM, Matthew Davies via swift-users 
>  wrote:
> 
> Yes I have the protoco​l​, but the problem is that I would want to be able to 
> call a method on the class that isn't necessarily defined in the protocol. 

You should only call methods that are defined in the protocol, and you should 
extend the protocol as necessary. You can always have instances conform to 
additional protocols and use conditional casts, if necessary.

The value of this approach is that it is statically type safe, and users of 
your framework can easily tell what methods they need to implement to work with 
it.

 - Daniel

> 
> I.e., I would like to be able to do something like this​:​
> 
> 
> ​---​
> 
> protocol Controller {
>   init()
> }
> 
> class MainController : Controller {
> 
>   required init() {}
> 
>   func index() -> String {
> return "This is the index"
>   }
> }
> 
> class Router {
>   func get(url: String, ctrl: Controller.Type, method: String) {
> let inst = ctrl.init()
> // Run the method that is passed in here
>   }
> }
> 
> let router = Router()
> router.get("/", ctrl: MainController.self, method: "index")
> ​---​
> 
> Does that make sense as to what I'm trying to accomplish? As I said, I'm open 
> to suggestions. I'm relatively new to Swift's design patterns, so I may be 
> thinking about this in completely the wrong way…
> 
> 
> On Thu, Dec 10, 2015 at 12:48 David Owens II  > wrote:
> You have the protocol conformance, why can’t you simply call the method 
> directly?
> 
>> On Dec 10, 2015, at 12:22 PM, Matthew Davies via swift-users 
>> > wrote:
>> 
>> I'm building a URL router in which I'd like to pass a controller and a 
>> method. I don't want to instantiate all the controllers up front and pass 
>> the methods in as closures, nor do I want old controller instances still 
>> kept around. If there's a better way, I'm definitely open to any 
>> suggestions. I'm still learning the "Swift" way to do things.
>> 
>> 
>> Matthew Davies
>> Junior Developer, GeoStrategies 
>> Director of Photography, OffBlock Films 
>> 209-225-3246  | 209-202-3284  | 
>> daviesg...@gmail.com  | daviesgeek.com 
>> 
>>      
>>      
>> 
>> 
>> On Thu, Dec 10, 2015 at 10:47 AM, Dan Stenmark > > wrote:
>> NSSelectorFromString() is still available in Swift, and you should be able 
>> to use the result of that in performSelector, though I’m hesitant to support 
>> this approach as it flies in the face of the safety Swift tries to enforce.  
>> I’m curious about your use case here; are you trying to create some kind of 
>> dynamic proxy for a remote object ala NSXPCConnection?
>> 
>> Dan
>> 
>>> On Dec 10, 2015, at 10:33 AM, Matthew Davies via swift-users 
>>> > wrote:
>>> 
>>> Ooh okay. I think that should work for my purposes. Thanks.
>>> 
>>> Somewhat related to this, how would I then call a method dynamically on an 
>>> instance of the class, after instantiating it?
>>> 
>>> ---
>>> class Graph {
>>>   func call(method: String) {
>>> // Something goes here
>>>   }
>>> 
>>>   func redraw() -> String {
>>> return "Redraws"
>>>   }
>>> }
>>> 
>>> let inst = Graph()
>>> inst.call("redraw")
>>> ---
>>> 
>>> 
>>> Matthew Davies
>>> Junior Developer, GeoStrategies 
>>> Director of Photography, OffBlock Films 
>>> 209-225-3246  | 209-202-3284  | 
>>> daviesg...@gmail.com  | daviesgeek.com 
>>> 
>>>      
>>>      
>>> 
>>> 
>>> On Thu, Dec 10, 2015 at 10:18 AM, Daniel Dunbar >> > wrote:
>>> Note that you can define a protocol which will allow your framework to 
>>> instantiate the type, and to call methods on instances of that type. If you 
>>> can structure your code in this fashion, it can be very elegant in that it 
>>> doesn't require factory functions and it is  type safe.
>>> 
>>> For example:
>>> --
>>> struct GraphableDescription { }
>>> 
>>> protocol Graphable {
>>> /// Construct a graphable item from a description.
>>> init(description: GraphableDescription)
>>> 
>>> func graph()
>>> }
>>> 
>>> // Example framework method.
>>> func graphItem(description: GraphableDescription, graphable: 
>>> Graphable.Type) {
>>> // Instantiate the graphable.
>>>

Re: [swift-users] Segfault importing sqlite3.h from a system module

2015-12-05 Thread Daniel Dunbar via swift-users

> On Dec 5, 2015, at 4:29 AM, Michael Buhot  wrote:
> 
> Hello,
> 
> I’m getting a segfault when importing sqlite using a swift system module and 
> the package manager.
> I have the following directory structure with a trivial system module and 
> application:
> 
> CSqlite3/
>  Package.swift
>  module.modulemap
>  .git/
> 
> app/
>  Package.swift
>  main.swift
>  .git/
> 
> CSqlite3 is a system module I created with an empty Package.swift file, and 
> module.modulemap: 
> 
> module CSqlite3 [system] {
>header "/usr/include/sqlite3.h"
>link "sqlite3"
>export *
> }
> 
> app/Package.swift contains:
> import PackageDescription
> 
> let package = Package(
>dependencies: [
>.Package(url: "../CSqlite3", majorVersion: 1)
>]
> )
> 
> And main.swift contains:
> import CSqlite3
> print("hello world”)
> 
> The error I’m getting is:
> $ swift build
> Compiling Swift Module 'app' (1 sources)
> 0  swift0x0001026ea47b 
> llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
> 1  swift0x0001026e9916 llvm::sys::RunSignalHandlers() 
> + 70
> 2  swift0x0001026eaaa3 SignalHandler(int) + 243
> 3  libsystem_platform.dylib 0x7fff8d25852a _sigtramp + 26
> 4  libsystem_platform.dylib 0x3c00 _sigtramp + 1926936304
> 5  swift0x000100f0502d 
> clang::Preprocessor::MacroState::getModuleInfo(clang::Preprocessor&, 
> clang::IdentifierInfo const*) const + 189
> 6  swift0x000100f04a76 
> clang::Preprocessor::getMacroDefinition(clang::IdentifierInfo const*) + 326
> 7  swift0x000101872e50 
> clang::Preprocessor::HandleIdentifier(clang::Token&) + 320
> 8  swift0x00010181c4f4 
> clang::Lexer::LexIdentifier(clang::Token&, char const*) + 932
> 9  swift0x000101822312 
> clang::Lexer::LexTokenInternal(clang::Token&, bool) + 8562
> 10 swift0x0001018734c4 
> clang::Preprocessor::Lex(clang::Token&) + 68
> 11 swift0x0001018442b7 
> clang::Preprocessor::ReadMacroName(clang::Token&, clang::MacroUse, bool*) + 55
> 12 swift0x000101847630 
> clang::Preprocessor::HandleIfdefDirective(clang::Token&, bool, bool) + 48
> 13 swift0x0001018464f4 
> clang::Preprocessor::HandleDirective(clang::Token&) + 1124
> 14 swift0x000101822966 
> clang::Lexer::LexTokenInternal(clang::Token&, bool) + 10182
> 15 swift0x0001018734c4 
> clang::Preprocessor::Lex(clang::Token&) + 68
> 16 swift0x0001011598bf 
> clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&) + 287
> 17 swift0x0001010db875 clang::ParseAST(clang::Sema&, 
> bool, bool) + 501
> 18 swift0x000100f2eb72 
> clang::FrontendAction::Execute() + 66
> 19 swift0x000100efaf43 
> clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 979
> 20 swift0x00010268e98d 
> llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) + 269
> 21 swift0x00010268ead0 
> RunSafelyOnThread_Dispatch(void*) + 48
> 22 swift0x0001026ebaed 
> ExecuteOnThread_Dispatch(void*) + 13
> 23 libsystem_pthread.dylib  0x7fff8ea2a9b1 _pthread_body + 131
> 24 libsystem_pthread.dylib  0x7fff8ea2a92e _pthread_body + 0
> 25 libsystem_pthread.dylib  0x7fff8ea28385 thread_start + 13
> Stack dump:
> 0./usr/include/sqlite3.h:76:2: current parser token 'ifndef'
> :0: error: unable to execute command: Segmentation fault: 11
> :0: error: compile command failed due to signal (use -v to see 
> invocation)
> :0: error: build had 1 command failures
> swift-build: exit(1): 
> ["/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2015-12-01-a.xctoolchain/usr/bin/swift-build-tool",
>  "-f", "/Users/mbuhot/source/app/.build/debug/app.o/llbuild.yaml”]
> 
> Is this a bug or have I messed something up?

Any time you see a crash it is a bug, please file on https://bugs.swift.org and 
a tarball of those files (also, might be good to include the OS version and 
version of sqlite you have installed).

 - Daniel

> Help much appreciated!
> 
> 
> Mike Buhot
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] "swift build" throws :0: error: no such file or directory: 'build'

2015-12-05 Thread Daniel Dunbar via swift-users
Sounds like you don't have the Swift package's usr/bin in your path, and are 
using an old `swift` without this support. See full instructions at:
  https://swift.org/download/#apple-platforms

 - Daniel

> On Dec 5, 2015, at 2:06 PM, Joy Mailer via swift-users 
>  wrote:
> 
> Followed the instructions on this page to set up a Package:
> https://swift.org/getting-started/#using-the-build-system 
> 
> 
> When I run "swift build", I get the error:
> :0: error: no such file or directory: 'build'
> 
> I'm able to build stand alone files with "swiftc myprogram.swift"
> 
> JJ
>  ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users