Skip to content

Commit

Permalink
add spm executable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jomy10 committed Jan 17, 2024
1 parent 286049f commit dfa5cc1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
uses: swift-actions/setup-swift@v1
with:
swift-version: '5.9'
- run: find / -iname "libswift*"
- name: Build
run: bash build.sh build install
- name: Run tests
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
with:
ruby-version: '3.1'
bundler-cache: false
- name: check for native extension errors
run: cat /Users/runner/hostedtoolcache/Ruby/*/x64/lib/ruby/gems/*/extensions/*/*/msgpack-*/mkmf.log
- name: setup minitest
run: gem install minitest
- name: Build
Expand Down
59 changes: 59 additions & 0 deletions lib/swift/target/spm_executable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Swift
class SPMExecutable < SPMProduct
def executable?
true
end

def buildable?
true
end

def executable_path
File.join(self.out_dir, self.name)
end

def artifact_path(artifact_type)
case artifact_type
when Beaver::ArtifactType::EXECUTABLE
return self.executable_path
else
Beaver::Log::err("Invalid artifact #{artifact_type} for Swift::SPMExecutable")
end

def build
@built_this_run = true
call self.build_cmd
end

def run

end

private
def _custom_after_init
super()

@artifacts = [Beaver::ArtifactType::EXECUTABLE]

Beaver::cmd self.build_cmd do
sh %(swift build #{self._flags})
end

Beaver::cmd self.run_cmd do
sh %(swift run #{self._flags})
end
end

def _flags
"#{self.flags.join(" ")} --product #{self.name} -c #{self.proect.config_name}"
end

def build_cmd
"__build_#{self.project}/#{self.name}"
end

def run_cmd
"__run_#{self.project}/#{self.name}"
end
end

6 changes: 6 additions & 0 deletions lib/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def print_artifacts
puts " - #{ArtifactType::name(artifact)}: #{self.artifact_path(artifact)}"
end
end

def build_if_not_built_yet
unless @built_this_run
self.build
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion tests/swift-project/make.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ldflags: [
case $beaver.host_os
when :macos
"-L/#{`xcode-select -p`.gsub("\n","")}/Toolchains/swift-latest.xctoolchain/usr/lib/swift/macosx"
"-L/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib/swift/macosx"
when :linux
"-L/usr/lib/swift"
end
Expand Down

0 comments on commit dfa5cc1

Please sign in to comment.