Skip to content

Commit

Permalink
Updates for Swift 6 (#1394)
Browse files Browse the repository at this point in the history
Updates for building docs with Swift 6 / Xcode 16
  • Loading branch information
johnfairh authored Sep 20, 2024
1 parent fd0b539 commit bbd31c9
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 19 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 15.3
xcode-version: '16.0'
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
- name: Cache cocoapods
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cocoapods
with:
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

##### Enhancements

* None.
* Support Swift 6.0 / Xcode 16.0
[John Fairhurst](https://github.com/johnfairh)

##### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ git push
You'll need push access to the integration specs repo to do this. You can
request access from one of the maintainers when filing your PR.

You must have Xcode 15.3 installed to build the integration specs.
You must have Xcode 16.0 installed to build the integration specs.

## Making changes to SourceKitten

Expand Down
2 changes: 1 addition & 1 deletion lib/jazzy/podspec_documenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def self.github_file_prefix(podspec)
private_class_method :github_file_prefix

# Latest valid value for SWIFT_VERSION.
LATEST_SWIFT_VERSION = '5'
LATEST_SWIFT_VERSION = '6'

# All valid values for SWIFT_VERSION that are longer
# than a major version number. Ordered ascending.
Expand Down
9 changes: 9 additions & 0 deletions lib/jazzy/sourcekitten.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,19 @@ def self.make_swift_declaration(doc, declaration)
# @available attrs only in compiler 'interface' style
extract_availability(doc['key.doc.declaration'] || '')
.concat(extract_documented_attributes(annotated_decl_attrs))
.concat(fabricate_spi_attributes(doc, annotated_decl_attrs))
.push(decl)
.join("\n")
end

# Swift 6 workaround: @_spi attribute & SPI group missing
def self.fabricate_spi_attributes(doc, attrs)
return [] unless spi_attribute?(doc)
return [] if attrs =~ /@_spi/

['@_spi(<<unknown>>)']
end

# Exclude non-async routines that accept async closures
def self.swift_async?(fully_annotated_decl)
document = REXML::Document.new(fully_annotated_decl)
Expand Down
18 changes: 11 additions & 7 deletions lib/jazzy/symbol_graph/ext_node.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'set'

module Jazzy
module SymbolGraph
# For extensions we need to track constraints of the extended type
Expand All @@ -26,7 +28,7 @@ class ExtNode < BaseNode
attr_accessor :real_usr
attr_accessor :name
attr_accessor :all_constraints # ExtConstraints
attr_accessor :conformances # array, can be empty
attr_accessor :conformances # set, can be empty

# Deduce an extension from a member of an unknown type or
# of known type with additional constraints
Expand Down Expand Up @@ -54,7 +56,7 @@ def initialize(usr, name, constraints)
self.usr = usr
self.name = name
self.all_constraints = constraints
self.conformances = []
self.conformances = Set.new
super()
end

Expand All @@ -65,13 +67,13 @@ def constraints
end

def add_conformance(protocol)
conformances.append(protocol).sort!
conformances.add(protocol)
end

def full_declaration
decl = "extension #{name}"
unless conformances.empty?
decl += " : #{conformances.join(', ')}"
decl += " : #{conformances.sort.join(', ')}"
end
decl + all_constraints.ext.to_where_clause
end
Expand All @@ -90,7 +92,7 @@ def to_sourcekit(module_name, ext_module_name)
}

unless conformances.empty?
hash['key.inheritedtypes'] = conformances.map do |conformance|
hash['key.inheritedtypes'] = conformances.sort.map do |conformance|
{ 'key.name' => conformance }
end
end
Expand All @@ -100,11 +102,13 @@ def to_sourcekit(module_name, ext_module_name)
hash
end

# Sort order - by type name then constraint
# Sort order - by type name then constraint then conformances
# Conformance check needed for stable order with Swift 5.9
# extension symbols that can't merge as well as previously.
include Comparable

def sort_key
name + constraints.map(&:to_swift).join
name + constraints.map(&:to_swift).join + conformances.sort.join
end

def <=>(other)
Expand Down
2 changes: 1 addition & 1 deletion lib/jazzy/symbol_graph/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def extension_to?
# Protocol conformances added by compiler to actor decls that
# users aren't interested in.
def actor_protocol?
%w[Actor Sendable].include?(target_fallback)
%w[Actor AnyActor Sendable].include?(target_fallback)
end

def initialize(hash)
Expand Down
24 changes: 19 additions & 5 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ def configure_cocoapods
</script>
HTML

realm_jazzy_yaml = <<-YAML
build_tool_arguments:
- "-scheme"
- "RealmSwift"
- "SWIFT_VERSION=4.2"
- "-destination"
- "platform=OS X,arch=x86_64"
YAML

spec_subset = ENV.fetch('JAZZY_SPEC_SUBSET', nil)

# rubocop:disable Style/MultilineIfModifier
Expand Down Expand Up @@ -208,9 +217,15 @@ def configure_cocoapods

describe 'Creates Realm Swift docs' do
realm_version = ''
Dir.chdir(ROOT + 'spec/integration_specs/document_realm_swift/before') do
realm_path = ROOT + 'spec/integration_specs/document_realm_swift/before'
realm_jazzy_path = realm_path + '.jazzy.yaml'

Dir.chdir(realm_path) do
realm_version = `./build.sh get-version`.chomp
end
# Xcode 16 workaround
File.write(realm_jazzy_path, realm_jazzy_yaml)

behaves_like cli_spec 'document_realm_swift',
'--author Realm ' \
'--author_url "https://realm.io" ' \
Expand All @@ -222,10 +237,8 @@ def configure_cocoapods
"--module-version #{realm_version} " \
'--root-url https://realm.io/docs/swift/' \
"#{realm_version}/api/ " \
'--xcodebuild-arguments ' \
'-scheme,RealmSwift,SWIFT_VERSION=4.2,' \
"-destination,'platform=OS X' " \
"--head #{realm_head.shellescape}"
FileUtils.rm_rf realm_jazzy_path
end

describe 'Creates Siesta docs' do
Expand All @@ -249,7 +262,8 @@ def configure_cocoapods
behaves_like cli_spec 'misc_jazzy_symgraph_features',
'--swift-build-tool symbolgraph ' \
'--build-tool-arguments ' \
"-emit-extension-block-symbols,-I,#{module_path}"
'-emit-extension-block-symbols,-I,' \
"#{module_path.chomp}/Modules"
end

describe 'Creates docs for a multiple-module project' do
Expand Down
2 changes: 1 addition & 1 deletion spec/integration_specs
Submodule integration_specs updated 229 files

0 comments on commit bbd31c9

Please sign in to comment.