Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build on FreeBSD #38335

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix build on FreeBSD #38335

wants to merge 1 commit into from

Conversation

drexin
Copy link
Contributor

@drexin drexin commented Jul 9, 2021

These changes make Swift build on FreeBSD (tested on 13.0-RELEASE-p1). There are some tests that I had to XFAIL, but the majority works. SourceKit tests are very unstable and seem to fail when too many tests are executed in parallel. Running them in isolation with lit.py -v $SWIFT_BUILD_ROOT/tests-xxx --filter=SourceKit -j12 works, but using more threads causes random failures. The more threads are used, the more tests fail. I have not found the reason, yet.

@drexin
Copy link
Contributor Author

drexin commented Jul 9, 2021

@swift-ci test

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.

stdlib/public/Platform/CMakeLists.txt Show resolved Hide resolved
stdlib/public/Platform/libc-freebsd.modulemap.gyb Outdated Show resolved Hide resolved
test/lit.cfg Show resolved Hide resolved
test/stdlib/POSIX.swift Show resolved Hide resolved
unittests/runtime/CMakeLists.txt Outdated Show resolved Hide resolved
@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2021

Build failed
Swift Test Linux Platform
Git Sha - 17fc1037a285eef09d4f738a23e9142a876797ce

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2021

Build failed
Swift Test OS X Platform
Git Sha - 17fc1037a285eef09d4f738a23e9142a876797ce

@drexin
Copy link
Contributor Author

drexin commented Jul 9, 2021

@swift-ci test

@@ -24,7 +24,7 @@

// Clang has been defining __INTxx_TYPE__ macros for a long time.
// __UINTxx_TYPE__ are defined only since Clang 3.5.
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__)
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(FreeBSD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want defined(__FreeBSD__) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@drexin drexin force-pushed the wip-freebsd branch 2 times, most recently from cefc502 to a8b345b Compare July 9, 2021 22:55
@drexin
Copy link
Contributor Author

drexin commented Jul 9, 2021

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a8b345b2c6abfa6dc1913ff5f5a25fcc6a7bfe37

@drexin
Copy link
Contributor Author

drexin commented Jul 10, 2021

@swift-ci test linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a8b345b2c6abfa6dc1913ff5f5a25fcc6a7bfe37

@drexin
Copy link
Contributor Author

drexin commented Jul 10, 2021

@swift-ci clean test linux

@@ -658,7 +658,7 @@ importer::getNormalInvocationArguments(
}
}

if (searchPathOpts.SDKPath.empty()) {
if (searchPathOpts.SDKPath.empty() && !triple.isOSFreeBSD()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why special case this for FreeBSD, not working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it excludes all system headers, causing e.g. the Glibc module to not work. I am unsure why this works on Linux, but not FreeBSD.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could try adding the ClangImporter flags -Xfrontend -dump-clang-diagnostics -Xcc -v after removing this special case to dump what it's seeing and compare with linux, as I did with SR-14796.

threads.append(t!)
#else
threads.append(t)
#endif
}

print("================ 34 2THRAEDS: \(threads)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your debugging info that can be taken out?

@@ -30,7 +30,7 @@ using namespace fine_grained_dependencies;

// This introduces a redefinition where ever std::is_same_t<size_t, uint64_t>
// holds
#if !(defined(__linux__) || defined(_WIN64))
#if (!(defined(__linux__) || defined(_WIN64) || defined(__FreeBSD__)))
Copy link
Contributor

@finagolfin finagolfin Jul 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unnecessary first parenthesis.

Copy link
Contributor

@finagolfin finagolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see this. I don't know about the std::pair changes but otherwise checks out.

FLAGS "-DCMAKE_SDK=${sdk}")
list(APPEND glibc_modulemap_target_list ${glibc_header_target})
# FreeBSD uses a different module map that does not use this header,
# so we don't generate it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried using this "Glibc" header instead on FreeBSD? I have it almost working for Android, #35707, so I think it should work for the BSDs too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but ran into a lot of missing functions. I did not have time to figure out what the problem is, yet, but I will take a look. Thanks for the link. I would like to land this first, though.

@drexin
Copy link
Contributor Author

drexin commented Jul 12, 2021

@swift-ci smoke test

Copy link

@fossdd fossdd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swift on FreeBSD is awesome! Thanks!

@drexin
Copy link
Contributor Author

drexin commented Jul 13, 2021

@swift-ci test macos

@drexin
Copy link
Contributor Author

drexin commented Jul 13, 2021

@swift-ci test windows

@drexin
Copy link
Contributor Author

drexin commented Jul 14, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Jul 14, 2021

@swift-ci test windows

1 similar comment
@drexin
Copy link
Contributor Author

drexin commented Jul 14, 2021

@swift-ci test windows

@drexin
Copy link
Contributor Author

drexin commented Jul 15, 2021

@swift-ci test windows

2 similar comments
@drexin
Copy link
Contributor Author

drexin commented Jul 15, 2021

@swift-ci test windows

@drexin
Copy link
Contributor Author

drexin commented Jul 19, 2021

@swift-ci test windows

@intini
Copy link

intini commented Sep 30, 2021

Hi. I would like to register that I really would like very much to have Swift ported and maintained on FreeBSD.

@majortom64
Copy link

Curious what is preventing this from happening? It would be great to be able to deploy Server Side Swift on FreeBSD. Is there anything that can be done to support this effort (financially or other wise)?

Super excited and want to thank everyone who has pushed this along.

@erde74
Copy link

erde74 commented Jan 30, 2022

@drexin hi, i updated the PR, the patch is based on swift release/5.6 branch. i have test this on FreeBSD 13

FreeBSD lenovo.local 13.0-RELEASE-p6 FreeBSD 13.0-RELEASE-p6 #0: Mon Jan 10 06:28:50 UTC 2022 root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64

Testing Time: 5295.68s
Unsupported : 1861
Passed : 6102
Expectedly Failed : 32
Failed : 45
Unexpectedly Passed: 1

freebsd.patch.txt
test-fail.txt

@tobiastom
Copy link

I would like to second @majortom64 question. @drexin: is there anything we can help to get this merged? Swift on FreeBSD would indeed be awesome.

@drexin
Copy link
Contributor Author

drexin commented Apr 21, 2022

Hey, sorry for the silence here. I was pretty busy with other stuff and this was just a side project. I don't think I will be able to spend any time on this in the near future, but if anyone wants to pick this up, please feel free to.

@tobiastom
Copy link

@drexin Thank you for the update. I completely understand.

Unfortunately this is beyond by abilities, but hopefully someone else might do it.

@finagolfin finagolfin mentioned this pull request Jun 20, 2022
@b-ncMN
Copy link

b-ncMN commented Jun 20, 2022

Hey everyone, coming from #59579
I would be interesting into continuing the work on this

@erde74
Copy link

erde74 commented Jun 21, 2022 via email

@b-ncMN
Copy link

b-ncMN commented Jun 24, 2022

Hi,
I'm coming back here with a little bit of advancement;
I have made a fork of this official repository, cloned it, made a wip-freebsd branch on top of main and cherry-picked / rebased the wip-freebsd branch from @drexin on my own branch, it is available here
I was wondering whether or not to create a new PR for that new branch?
and I was also wondering about this line specifically,
I have changed it to freebsd-uknown, seeing as how linux is linux-gnu, but I'm not entirely sure and ask for a confirmation

Thanks a lot for the answers in advance ! 😄

std::pair<ApplyInst *, SILDifferentiabilityWitness *>
indirectDifferentiation;
///
/// Note: This used to be a std::pair, but on FreeBSD std::pair can't be
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe, this is not FreeBSD specifics, but a libc++ one. Change the comment accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FreeBSD specifically disables the copy constructor by setting _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR to preserve ABI. It is not a general limitation of libc++.

@finagolfin
Copy link
Contributor

I was wondering whether or not to create a new PR for that new branch?

No, first follow the build instructions for linux here, translating to FreeBSD as much as possible, and see if you can bootstrap the compiler and run the validation suite, as has been done for OpenBSD. Only once you're able to build the compiler and run the tests on FreeBSD should you consider submitting a pull.

I was also wondering about this line specifically, I have changed it to freebsd-uknown, seeing as how linux is linux-gnu, but I'm not entirely sure and ask for a confirmation

Yes, that is better, the tests are moving that way, as in #58975.

@b-ncMN
Copy link

b-ncMN commented Jun 24, 2022

I was wondering whether or not to create a new PR for that new branch?

No, first follow the build instructions for linux here, translating to FreeBSD as much as possible, and see if you can bootstrap the compiler and run the validation suite, as has been done for OpenBSD. Only once you're able to build the compiler and run the tests on FreeBSD should you consider submitting a pull.

I was also wondering about this line specifically, I have changed it to freebsd-uknown, seeing as how linux is linux-gnu, but I'm not entirely sure and ask for a confirmation

Yes, that is better, the tests are moving that way, as in #58975.

Is there a process to follow for fixing LLVM build issues?
Can I provide the changes to https://github.com/apple/llvm-project ? or is it better to propose them upstream directly?

@finagolfin
Copy link
Contributor

Is there a process to follow for fixing LLVM build issues?

Yes, you submit it to their Phabricator.

Can I provide the changes to https://github.com/apple/llvm-project ? or is it better to propose them upstream directly?

No, you're supposed to submit changes upstream, not to the Apple fork for Swift.

3405691582 added a commit to 3405691582/swift that referenced this pull request Jul 9, 2022
Bring drexin's FreeBSD support patch up to date with main. Resolved
conflicts in prior merge commit and made some minor buildfixes. Still
requires some other more general fixes outside this pr to have this build
properly at HEAD but have verified this builds OK with those fixes TK on
FreeBSD 12.3.

Note: I don't intend to support this platform as a priority.
3405691582 added a commit to 3405691582/swift that referenced this pull request Jul 9, 2022
Bring drexin's FreeBSD support patch up to date with main. Resolved
conflicts in prior merge commit and made some minor buildfixes. Still
requires some other more general fixes outside this pr to have this build
properly at HEAD but have verified only this builds OK with those fixes
possibly TK including swiftlang#59987 on FreeBSD 12.3.

Note: I don't intend to support this platform as a priority.
3405691582 added a commit to 3405691582/swift that referenced this pull request Jul 9, 2022
Bring drexin's FreeBSD support patch up to date with main. Resolved
conflicts in prior merge commit and made some minor buildfixes. Still
requires some other more general fixes outside this pr to have this build
properly at HEAD but have verified only this builds OK with those fixes
possibly TK including swiftlang#59987 and bootstrapping disabled on FreeBSD 12.3.

Note: I don't intend to support this platform as a priority.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.