Help with build project

It's quite non-trivial to build a project for the first time in Xcode, please tell me if I'm doing something wrong https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#using-ninja-with-xcode?

(I made successfully all steps in https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#the-actual-build)

  1. The first command "utils/build-script --swift-darwin-supported-archs "$(uname -m)" --xcode --clean" was executed successfully

  2. Then I create a worksapce

%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202023-08-05%20%D0%B2%2013.11.20

  1. In the created workspace I drag "build/Xcode-/swift-macosx-/Swift.xcodeproj" and I choose “Automatically Create Schemes”

%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA%20%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0%202023-08-05%20%D0%B2%2013.14.45

Some schemes

  1. I drag the project with the External Build system template into the created workspace

  1. I fill in info in the target settings (I'm not sure if I understand correctly what Arguments are and what should actually be there)

  1. And here's the most problematic part: “Add a scheme for the target. In the drop-down menu, be careful not to mistake your target for a similar one that belongs to a generated Xcode project.” Which scheme and for which target should I add ?

  2. And that after step 6 I have to build. How to make edits in the resulting project if there are only CMakeLists files

How to complete step 6 and whether I am doing everything right before that. And what to do after step 6 ? Where are the sources themselves?)

Why not use Project instead of Workspace?

Hi @Pogosito,

Are you trying "to build a project" that uses Swift, or are you trying to build the Swift compiler itself?

Hi @Pogosito, welcome to the Swift Forums!

The Arguments for your Target (Test) settings should be bin/swift-frontend if you're building the swift compiler. This is the executable at Ninja-*/swift-macosx- */bin/swift-frontend.

For your new scheme, your target should be the target that you created for the Test project. I think the instructions intend to warn you to not accidentally select one of the options that were generated during "Automatically Create Schemes" and the wording could definitely make that clearer.

Hi! :wave:

The second step in the guide

"Create a new Xcode workspace."

Hi! :wave:

I am trying to build Swift compiler to try to fix compiler bugs and help our community

1 Like

Ah, great! Moving this thread over to the “Development” category for clarity. There are also some past threads in that category which may be helpful, where people detail how they got things set up. As I recall, most don’t use the Xcode project.

1 Like

@xwu Thank you very much, I probably searched badly, if there is an opportunity, please share the links where people build the project not through xcode

@amritpan Hi, thank you very much for your response

I added new scheme "Test 1" for my "Test" target also I change the arguments field. But which target should I build ?

Sorry for delay response

P.s which environment do you use for contributing in swift ?

You should be able to build and run the Test 1 scheme created with your Test target. What happens when you attempt this?

I use the Ninja with Xcode setup.

It depends on what you want to work on. For example, if you're working on the compiler frontend, then you should add/choose "swiftFrontend" or "swift-frontend".

Most likely what you need to edit can be found under "Swift Libraries", after you scroll past lots of CMake files. For example:

Other source (and header) files can be found under "Swift Executables", "SwiftModule"-prefixed groups, "SourceKit"-prefixed groups, "XPC Services", "Tests", and maybe some other groups.

There are some gyb'd files not generated for the Xcode build, e.g. Attr.def. For those files, you can just drag them from the Ninja build into the Xcode project.

1 Like

cc @contributor-experience-workgroup

I can say from my personal experience that it was quite a puzzle to find the source files in Xcode when I first built the project 2(?) years ago. Is there a way to have CMake hide some targets in the generated project? Although, this looks like something that needs changes/improvements from CMake itself first (relavent CMake issue: Proposal: Target property to indicate IDEs shouldn't show it (#23566) · Issues · CMake / CMake · GitLab).

2 Likes

Thanks. Target Test with scheme Test 1 builded successfully.

Am I right that I need recompile target "swift-fronted" after making changes, and then testing this changes in Test project ?

Снимок экрана 2023-08-14 в 23.10.51

For example I added some code in Array.swift (imagine I fixed some bug)

When I testing my changes in Test project and after it I can make pull request ?
Снимок экрана 2023-08-14 в 23.15.26

Thanks!


My bad ( I founded .swift files just filtering in navigation panel

You can continue to build and run your custom scheme after you make changes to the codebase. You do not need recompile target "swift-frontend" in Xcode as building and running will do this for you.

It is recommended to use the ninja with Xcode setup to edit code and then run tests with ninja on the command line. To run individual tests, you should check out the Running Tests section. There is a script for running individual tests and for running the entire testsuite. After you make changes in Xcode, before running tests, you will need to rebuild the compiler.

1 Like

But what if I want to run my "Test" target with my "own" version of compiler

For achieve that
I've created example file where I want to make experiments
Important!: As you can see the checkbox with target selected
Снимок экрана 2023-08-19 в 13.14.32

But I don't now why this file can't be a membership of target, and i can't compile "SomeFile.swift".

My questions is:
Where is of staring point of Test target ? And how add files to this target (and make a simple print and see result of print) ?

P.s
I can't add files to current target via build Phases

Now every time Test target compile and run successfully even if I write just text

If I understood correctly, you're trying to figure out how to test valid Swift code using your Ninja on Xcode build? You can create a test.swift file anywhere on your computer and then add its path name to your target's run arguments.

Then you can run it with the appropriate flags to check your test code. For example, you could use -debug-constraints and/or -typecheck to check if there is a type checker error with your test code. If you want to continue using Xcode instead of the command line, you can add these to your target's run arguments as well.

Thank you a lot!

Sorry for the late response.

I figured out how to make the target runnable, I just didn't understand at first which panel I was talking about in documentation and where to set the settings.



Did I get it right ?

It seems that now everything starts and something appears in the logs. But I still don't understand why I don't see the print result and why compiler doesn't see my functions/properties ?


Снимок экрана 2023-10-28 в 08.37.48

With Respect
Pogos

1 Like

The console shows a compilation error. What do you mean by "the compiler does not see my functions"? Swift is a compiled language, not an interpreted language like Python; a compilation error interrupts the compilation process and thus prevents any execution.

If I understood correctly, I added the path of the "ForFun" file so that when you click on run in xcode, it compiles and runs

(Edit: If I remove true.pogos, then everything will be compiled without errors, but the print result will not be in the console)

Also for an experiment, I added a new property to Bool, but for some reason, when building the project, compiler does not see it